--- cci/sys/netinet/in_pcb.c 2019/07/28 12:24:19 1.1 +++ cci/sys/netinet/in_pcb.c 2019/07/28 12:29:36 1.1.1.2 @@ -15,6 +15,7 @@ #include "../h/protosw.h" struct in_addr zeroin_addr; +extern struct inpcb tcb; in_pcballoc(so, head) struct socket *so; @@ -104,6 +105,7 @@ in_pcbconnect(inp, nam) struct ifnet *ifp; struct sockaddr_in *ifaddr; register struct sockaddr_in *sin = mtod(nam, struct sockaddr_in *); + struct route ro; if (nam->m_len != sizeof (*sin)) return (EINVAL); @@ -111,15 +113,30 @@ in_pcbconnect(inp, nam) return (EAFNOSUPPORT); if (sin->sin_addr.s_addr == INADDR_ANY || sin->sin_port == 0) return (EADDRNOTAVAIL); + if (inp->inp_laddr.s_addr == INADDR_ANY) { - ifp = if_ifonnetof(in_netof(sin->sin_addr)); + if (inp->inp_head == &tcb) { + register short *sptr, *dptr; + + /* TCP protocol; bind local address + to that of route to be used. + */ + bzero((caddr_t)&ro,sizeof(ro)); + ro.ro_dst.sa_family = AF_INET; + ((struct sockaddr_in *)&ro.ro_dst)->sin_addr = sin->sin_addr; + rtalloc(&ro); + if (ro.ro_rt == 0 || + ((ifp = ro.ro_rt->rt_ifp) == 0)) { + goto nxttry; + } + rtfree(ro.ro_rt); + } + else { +nxttry: + ifp = if_ifonnetof(in_netof(sin->sin_addr)); + } + if (ifp == 0) { - /* - * We should select the interface based on - * the route to be used, but for udp this would - * result in two calls to rtalloc for each packet - * sent; hardly worthwhile... - */ ifp = if_ifwithaf(AF_INET); if (ifp == 0) return (EADDRNOTAVAIL);