minor bug fixes
authorBill Joy <wnj@ucbvax.Berkeley.EDU>
Fri, 12 Mar 1982 15:09:52 +0000 (07:09 -0800)
committerBill Joy <wnj@ucbvax.Berkeley.EDU>
Fri, 12 Mar 1982 15:09:52 +0000 (07:09 -0800)
SCCS-vsn: sys/netinet/in_pcb.c 4.19
SCCS-vsn: sys/netinet/tcp_input.c 1.59
SCCS-vsn: sys/netinet/tcp_subr.c 4.16
SCCS-vsn: sys/netinet/tcp_usrreq.c 1.53

usr/src/sys/netinet/in_pcb.c
usr/src/sys/netinet/tcp_input.c
usr/src/sys/netinet/tcp_subr.c
usr/src/sys/netinet/tcp_usrreq.c

index 1646308..a2ea154 100644 (file)
@@ -1,4 +1,4 @@
-/*     in_pcb.c        4.18    82/03/03        */
+/*     in_pcb.c        4.19    82/03/11        */
 
 #include "../h/param.h"
 #include "../h/systm.h"
 
 #include "../h/param.h"
 #include "../h/systm.h"
@@ -11,6 +11,7 @@
 #include "../net/in_systm.h"
 #include "../net/if.h"
 #include "../net/in_pcb.h"
 #include "../net/in_systm.h"
 #include "../net/if.h"
 #include "../net/in_pcb.h"
+#include "../h/protosw.h"
 
 /*
  * Routines to manage internet protocol control blocks.
 
 /*
  * Routines to manage internet protocol control blocks.
@@ -73,14 +74,18 @@ COUNT(IN_PCBATTACH);
                lport = sin->sin_port;
                if (lport) {
                        u_short aport = lport;
                lport = sin->sin_port;
                if (lport) {
                        u_short aport = lport;
+                       int wild = 0;
 #if vax
                        aport = htons(aport);
 #endif
                        /* GROSS */
                        if (aport < IPPORT_RESERVED && u.u_uid != 0)
                                return (EPERM);
 #if vax
                        aport = htons(aport);
 #endif
                        /* GROSS */
                        if (aport < IPPORT_RESERVED && u.u_uid != 0)
                                return (EPERM);
+                       if ((so->so_proto->pr_flags & PR_CONNREQUIRED) == 0 ||
+                           (so->so_options & SO_ACCEPTCONN) == 0)
+                               wild = INPLOOKUP_WILDCARD;
                        if (in_pcblookup(head,
                        if (in_pcblookup(head,
-                           zeroin_addr, 0, sin->sin_addr, lport, 0))
+                           zeroin_addr, 0, sin->sin_addr, lport, wild))
                                return (EADDRINUSE);
                }
        }
                                return (EADDRINUSE);
                }
        }
@@ -115,6 +120,12 @@ bad:
        return (ENOBUFS);
 }
 
        return (ENOBUFS);
 }
 
+/*
+ * Connect from a socket to a specified address.
+ * Both address and port must be specified in argument sin.
+ * If don't have a local address for this socket yet,
+ * then pick one.
+ */
 in_pcbconnect(inp, sin)
        struct inpcb *inp;
        struct sockaddr_in *sin;
 in_pcbconnect(inp, sin)
        struct inpcb *inp;
        struct sockaddr_in *sin;
@@ -132,7 +143,11 @@ COUNT(IN_PCBCONNECT);
                        ifp = ifnet;
        }
        if (in_pcblookup(inp->inp_head,
                        ifp = ifnet;
        }
        if (in_pcblookup(inp->inp_head,
-           sin->sin_addr, sin->sin_port, inp->inp_laddr, inp->inp_lport, 0))
+           sin->sin_addr,
+           sin->sin_port,
+           inp->inp_laddr.s_addr ? inp->inp_laddr : ifp->if_addr,
+           inp->inp_lport,
+           0))
                return (EADDRINUSE);
        if (inp->inp_laddr.s_addr == 0)
                inp->inp_laddr = ifp->if_addr;
                return (EADDRINUSE);
        if (inp->inp_laddr.s_addr == 0)
                inp->inp_laddr = ifp->if_addr;
@@ -175,7 +190,8 @@ in_pcbdetach(inp)
 }
 
 /*
 }
 
 /*
- * Look for a control block to accept a segment.
+ * Look for a control block to accept a segment, or to make
+ * sure 
  * First choice is an exact address match.
  * Second choice is a match with either the foreign or the local
  * address specified.
  * First choice is an exact address match.
  * Second choice is a match with either the foreign or the local
  * address specified.
@@ -197,14 +213,18 @@ in_pcblookup(head, faddr, fport, laddr, lport, flags)
                        continue;
                wildcard = 0;
                if (inp->inp_laddr.s_addr != 0) {
                        continue;
                wildcard = 0;
                if (inp->inp_laddr.s_addr != 0) {
-                       if (inp->inp_laddr.s_addr != laddr.s_addr)
+                       if (laddr.s_addr == 0)
+                               wildcard++;
+                       else if (inp->inp_laddr.s_addr != laddr.s_addr)
                                continue;
                } else {
                        if (laddr.s_addr != 0)
                                wildcard++;
                }
                if (inp->inp_faddr.s_addr != 0) {
                                continue;
                } else {
                        if (laddr.s_addr != 0)
                                wildcard++;
                }
                if (inp->inp_faddr.s_addr != 0) {
-                       if (inp->inp_faddr.s_addr != faddr.s_addr ||
+                       if (faddr.s_addr == 0)
+                               wildcard++;
+                       else if (inp->inp_faddr.s_addr != faddr.s_addr ||
                            inp->inp_fport != fport)
                                continue;
                } else {
                            inp->inp_fport != fport)
                                continue;
                } else {
index 67a7cfe..807e0ca 100644 (file)
@@ -1,4 +1,4 @@
-/*     tcp_input.c     1.58    82/03/10        */
+/*     tcp_input.c     1.59    82/03/11        */
 
 #include "../h/param.h"
 #include "../h/systm.h"
 
 #include "../h/param.h"
 #include "../h/systm.h"
@@ -810,7 +810,7 @@ tcp_pulloutofband(so, ti)
        struct tcpiphdr *ti;
 {
        register struct mbuf *m;
        struct tcpiphdr *ti;
 {
        register struct mbuf *m;
-       int cnt = sizeof (struct tcpiphdr) + ti->ti_urp - 1;
+       int cnt = ti->ti_urp - 1;
        
        m = dtom(ti);
        while (cnt >= 0) {
        
        m = dtom(ti);
        while (cnt >= 0) {
index da5b334..926b5d3 100644 (file)
@@ -1,4 +1,4 @@
-/*     tcp_subr.c      4.15    82/02/15        */
+/*     tcp_subr.c      4.16    82/03/11        */
 
 #include "../h/param.h"
 #include "../h/systm.h"
 
 #include "../h/param.h"
 #include "../h/systm.h"
@@ -111,6 +111,7 @@ COUNT(TCP_RESPOND);
                m = dtom(ti);
                m_freem(m->m_next);
                m->m_next = 0;
                m = dtom(ti);
                m_freem(m->m_next);
                m->m_next = 0;
+               m->m_off = (int)ti - (int)m;
                m->m_len = sizeof (struct tcpiphdr);
 #define xchg(a,b,type) { type t; t=a; a=b; b=t; }
                xchg(ti->ti_dst.s_addr, ti->ti_src.s_addr, u_long);
                m->m_len = sizeof (struct tcpiphdr);
 #define xchg(a,b,type) { type t; t=a; a=b; b=t; }
                xchg(ti->ti_dst.s_addr, ti->ti_src.s_addr, u_long);
index 092bbb4..9250b1f 100644 (file)
@@ -1,4 +1,4 @@
-/* tcp_usrreq.c 1.52 82/02/27 */
+/* tcp_usrreq.c 1.53 82/03/11 */
 
 #include "../h/param.h"
 #include "../h/systm.h"
 
 #include "../h/param.h"
 #include "../h/systm.h"
@@ -153,7 +153,16 @@ COUNT(TCP_USRREQ);
         * done at higher levels; just return the address
         * of the peer, storing through addr.
         */
         * done at higher levels; just return the address
         * of the peer, storing through addr.
         */
-       case PRU_ACCEPT:
+       case PRU_ACCEPT: {
+               struct sockaddr_in *sin = (struct sockaddr_in *)addr;
+
+               if (sin) {
+                       bzero((caddr_t)sin, sizeof (*sin));
+                       sin->sin_family = AF_INET;
+                       sin->sin_port = inp->inp_fport;
+                       sin->sin_addr = inp->inp_faddr;
+               }
+               }
                break;
 
        /*
                break;
 
        /*