- /* The kind of socket is determined by the triplet {family, type, protocol} */
- family = so->so_proto->pr_domain->dom_family;
- type = so->so_proto->pr_type;
- protocol = so->so_proto->pr_protocol;
- switch (family) {
- case AF_INET:
- case AF_INET6: {
- struct in_sockinfo *insi = &si->soi_proto.pri_in;
- struct inpcb *inp = (struct inpcb *)so->so_pcb;
-
- si->soi_kind = SOCKINFO_IN;
-
- insi->insi_fport = inp->inp_fport;
- insi->insi_lport = inp->inp_lport;
- insi->insi_gencnt = inp->inp_gencnt;
- insi->insi_flags = inp->inp_flags;
- insi->insi_vflag = inp->inp_vflag;
- insi->insi_ip_ttl = inp->inp_ip_ttl;
- insi->insi_faddr.ina_6 = inp->inp_dependfaddr.inp6_foreign;
- insi->insi_laddr.ina_6 = inp->inp_dependladdr.inp6_local;
- insi->insi_v4.in4_tos = inp->inp_depend4.inp4_ip_tos;
- insi->insi_v6.in6_hlim = inp->inp_depend6.inp6_hlim;
- insi->insi_v6.in6_cksum = inp->inp_depend6.inp6_cksum;
- insi->insi_v6.in6_ifindex = inp->inp6_ifindex;
- insi->insi_v6.in6_hops = inp->inp_depend6.inp6_hops;
-
- if (type == SOCK_STREAM && (protocol == 0 || protocol == IPPROTO_TCP) && inp->inp_ppcb != 0) {
- struct tcp_sockinfo *tcpsi = &si->soi_proto.pri_tcp;
- struct tcpcb *tp= (struct tcpcb *)inp->inp_ppcb;
-
- si->soi_kind = SOCKINFO_TCP;
-
- tcpsi->tcpsi_state = tp->t_state;
- tcpsi->tcpsi_timer[TCPT_REXMT] = tp->t_timer[TCPT_REXMT];
- tcpsi->tcpsi_timer[TCPT_PERSIST] = tp->t_timer[TCPT_PERSIST];
- tcpsi->tcpsi_timer[TCPT_KEEP] = tp->t_timer[TCPT_KEEP];
- tcpsi->tcpsi_timer[TCPT_2MSL] = tp->t_timer[TCPT_2MSL];
- tcpsi->tcpsi_mss = tp->t_maxseg;
- tcpsi->tcpsi_flags = tp->t_flags;
- tcpsi->tcpsi_tp = (u_int64_t)((uintptr_t)tp);
- }
- break;
+ /*
+ * The kind of socket is determined by the triplet
+ * {domain, type, protocol}
+ */
+ domain = SOCK_DOM(so);
+ type = SOCK_TYPE(so);
+ protocol = SOCK_PROTO(so);
+ switch (domain) {
+ case PF_INET:
+ case PF_INET6: {
+ struct in_sockinfo *insi = &si->soi_proto.pri_in;
+ struct inpcb *inp = (struct inpcb *)so->so_pcb;
+
+ si->soi_kind = SOCKINFO_IN;
+
+ insi->insi_fport = inp->inp_fport;
+ insi->insi_lport = inp->inp_lport;
+ insi->insi_gencnt = inp->inp_gencnt;
+ insi->insi_flags = inp->inp_flags;
+ insi->insi_vflag = inp->inp_vflag;
+ insi->insi_ip_ttl = inp->inp_ip_ttl;
+ insi->insi_faddr.ina_6 = inp->inp_dependfaddr.inp6_foreign;
+ insi->insi_laddr.ina_6 = inp->inp_dependladdr.inp6_local;
+ insi->insi_v4.in4_tos = inp->inp_depend4.inp4_ip_tos;
+ insi->insi_v6.in6_hlim = 0;
+ insi->insi_v6.in6_cksum = inp->inp_depend6.inp6_cksum;
+ insi->insi_v6.in6_ifindex = 0;
+ insi->insi_v6.in6_hops = inp->inp_depend6.inp6_hops;
+
+ if (type == SOCK_STREAM && (protocol == 0 ||
+ protocol == IPPROTO_TCP) && inp->inp_ppcb != NULL) {
+ struct tcp_sockinfo *tcpsi = &si->soi_proto.pri_tcp;
+ struct tcpcb *tp = (struct tcpcb *)inp->inp_ppcb;
+
+ si->soi_kind = SOCKINFO_TCP;
+
+ tcpsi->tcpsi_state = tp->t_state;
+ tcpsi->tcpsi_timer[TCPT_REXMT] =
+ tp->t_timer[TCPT_REXMT];
+ tcpsi->tcpsi_timer[TCPT_PERSIST] =
+ tp->t_timer[TCPT_PERSIST];
+ tcpsi->tcpsi_timer[TCPT_KEEP] = tp->t_timer[TCPT_KEEP];
+ tcpsi->tcpsi_timer[TCPT_2MSL] = tp->t_timer[TCPT_2MSL];
+ tcpsi->tcpsi_mss = tp->t_maxseg;
+ tcpsi->tcpsi_flags = tp->t_flags;
+ tcpsi->tcpsi_tp =
+ (u_int64_t)VM_KERNEL_ADDRPERM(tp);
+ }
+ break;
+ }
+ case PF_UNIX: {
+ struct unpcb *unp = (struct unpcb *)so->so_pcb;
+ struct un_sockinfo *unsi = &si->soi_proto.pri_un;
+
+ si->soi_kind = SOCKINFO_UN;
+
+ unsi->unsi_conn_pcb =
+ (uint64_t)VM_KERNEL_ADDRPERM(unp->unp_conn);
+ if (unp->unp_conn)
+ unsi->unsi_conn_so = (uint64_t)
+ VM_KERNEL_ADDRPERM(unp->unp_conn->unp_socket);
+
+ if (unp->unp_addr) {
+ size_t addrlen = unp->unp_addr->sun_len;
+
+ if (addrlen > SOCK_MAXADDRLEN)
+ addrlen = SOCK_MAXADDRLEN;
+ bcopy(unp->unp_addr, &unsi->unsi_addr, addrlen);