[BACK]Return to uipc_socket.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / sys / kern

Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.

Diff for /src/sys/kern/uipc_socket.c between version 1.27 and 1.48.2.2

version 1.27, 1997/06/11 10:04:09 version 1.48.2.2, 2000/12/13 15:50:23
Line 32 
Line 32 
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF   * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.   * SUCH DAMAGE.
  *   *
  *      @(#)uipc_socket.c       8.3 (Berkeley) 4/15/94   *      @(#)uipc_socket.c       8.6 (Berkeley) 5/2/95
  */   */
   
   #include "opt_compat_sunos.h"
   
 #include <sys/param.h>  #include <sys/param.h>
 #include <sys/systm.h>  #include <sys/systm.h>
 #include <sys/proc.h>  #include <sys/proc.h>
Line 48 
Line 50 
 #include <sys/socketvar.h>  #include <sys/socketvar.h>
 #include <sys/signalvar.h>  #include <sys/signalvar.h>
 #include <sys/resourcevar.h>  #include <sys/resourcevar.h>
   #include <sys/pool.h>
   
   struct pool socket_pool;
   
   extern int somaxconn;                   /* patchable (XXX sysctl) */
   int somaxconn = SOMAXCONN;
   
   void
   soinit()
   {
   
           pool_init(&socket_pool, sizeof(struct socket), 0, 0, 0,
               "sockpl", 0, NULL, NULL, M_SOCKET);
   }
   
 /*  /*
  * Socket operation routines.   * Socket operation routines.
Line 61  int
Line 77  int
 socreate(dom, aso, type, proto)  socreate(dom, aso, type, proto)
         int dom;          int dom;
         struct socket **aso;          struct socket **aso;
         register int type;          int type;
         int proto;          int proto;
 {  {
         struct proc *p = curproc;               /* XXX */          struct proc *p = curproc;               /* XXX */
         register struct protosw *prp;          struct protosw *prp;
         register struct socket *so;          struct socket *so;
         register int error;          int error;
           int s;
   
         if (proto)          if (proto)
                 prp = pffindproto(dom, proto, type);                  prp = pffindproto(dom, proto, type);
Line 77  socreate(dom, aso, type, proto)
Line 94  socreate(dom, aso, type, proto)
                 return (EPROTONOSUPPORT);                  return (EPROTONOSUPPORT);
         if (prp->pr_type != type)          if (prp->pr_type != type)
                 return (EPROTOTYPE);                  return (EPROTOTYPE);
         MALLOC(so, struct socket *, sizeof(*so), M_SOCKET, M_WAIT);          s = splsoftnet();
         bzero((caddr_t)so, sizeof(*so));          so = pool_get(&socket_pool, PR_WAITOK);
           memset((caddr_t)so, 0, sizeof(*so));
           TAILQ_INIT(&so->so_q0);
           TAILQ_INIT(&so->so_q);
         so->so_type = type;          so->so_type = type;
         so->so_proto = prp;          so->so_proto = prp;
           so->so_send = sosend;
           so->so_receive = soreceive;
           if (p != 0)
                   so->so_uid = p->p_ucred->cr_uid;
         error = (*prp->pr_usrreq)(so, PRU_ATTACH, (struct mbuf *)0,          error = (*prp->pr_usrreq)(so, PRU_ATTACH, (struct mbuf *)0,
             (struct mbuf *)(long)proto, (struct mbuf *)0, p);              (struct mbuf *)(long)proto, (struct mbuf *)0, p);
         if (error) {          if (error) {
                 so->so_state |= SS_NOFDREF;                  so->so_state |= SS_NOFDREF;
                 sofree(so);                  sofree(so);
                   splx(s);
                 return (error);                  return (error);
         }          }
 #ifdef COMPAT_SUNOS  #ifdef COMPAT_SUNOS
Line 95  socreate(dom, aso, type, proto)
Line 120  socreate(dom, aso, type, proto)
                         so->so_options |= SO_BROADCAST;                          so->so_options |= SO_BROADCAST;
         }          }
 #endif  #endif
           splx(s);
         *aso = so;          *aso = so;
         return (0);          return (0);
 }  }
   
 int  int
 sobind(so, nam)  sobind(so, nam, p)
         struct socket *so;          struct socket *so;
         struct mbuf *nam;          struct mbuf *nam;
           struct proc *p;
 {  {
         struct proc *p = curproc;               /* XXX */  
         int s = splsoftnet();          int s = splsoftnet();
         int error;          int error;
   
Line 116  sobind(so, nam)
Line 142  sobind(so, nam)
   
 int  int
 solisten(so, backlog)  solisten(so, backlog)
         register struct socket *so;          struct socket *so;
         int backlog;          int backlog;
 {  {
         int s = splsoftnet(), error;          int s = splsoftnet(), error;
Line 127  solisten(so, backlog)
Line 153  solisten(so, backlog)
                 splx(s);                  splx(s);
                 return (error);                  return (error);
         }          }
         if (so->so_q == 0)          if (so->so_q.tqh_first == NULL)
                 so->so_options |= SO_ACCEPTCONN;                  so->so_options |= SO_ACCEPTCONN;
         if (backlog < 0)          if (backlog < 0)
                 backlog = 0;                  backlog = 0;
         so->so_qlimit = min(backlog, SOMAXCONN);          so->so_qlimit = min(backlog, somaxconn);
         splx(s);          splx(s);
         return (0);          return (0);
 }  }
   
 void  void
 sofree(so)  sofree(so)
         register struct socket *so;          struct socket *so;
 {  {
   
         if (so->so_pcb || (so->so_state & SS_NOFDREF) == 0)          if (so->so_pcb || (so->so_state & SS_NOFDREF) == 0)
                 return;                  return;
         if (so->so_head) {          if (so->so_head) {
                 if (!soqremque(so, 0) && !soqremque(so, 1))                  /*
                         panic("sofree dq");                   * We must not decommission a socket that's on the accept(2)
                 so->so_head = 0;                   * queue.  If we do, then accept(2) may hang after select(2)
                    * indicated that the listening socket was ready.
                    */
                   if (!soqremque(so, 0))
                           return;
         }          }
         sbrelease(&so->so_snd);          sbrelease(&so->so_snd);
         sorflush(so);          sorflush(so);
         FREE(so, M_SOCKET);          pool_put(&socket_pool, so);
 }  }
   
 /*  /*
Line 160  sofree(so)
Line 190  sofree(so)
  */   */
 int  int
 soclose(so)  soclose(so)
         register struct socket *so;          struct socket *so;
 {  {
           struct socket *so2;
         int s = splsoftnet();           /* conservative */          int s = splsoftnet();           /* conservative */
         int error = 0;          int error = 0;
   
         if (so->so_options & SO_ACCEPTCONN) {          if (so->so_options & SO_ACCEPTCONN) {
                 while (so->so_q0)                  while ((so2 = so->so_q0.tqh_first) != 0) {
                         (void) soabort(so->so_q0);                          (void) soqremque(so2, 0);
                 while (so->so_q)                          (void) soabort(so2);
                         (void) soabort(so->so_q);                  }
                   while ((so2 = so->so_q.tqh_first) != 0) {
                           (void) soqremque(so2, 1);
                           (void) soabort(so2);
                   }
         }          }
         if (so->so_pcb == 0)          if (so->so_pcb == 0)
                 goto discard;                  goto discard;
Line 186  soclose(so)
Line 221  soclose(so)
                         while (so->so_state & SS_ISCONNECTED) {                          while (so->so_state & SS_ISCONNECTED) {
                                 error = tsleep((caddr_t)&so->so_timeo,                                  error = tsleep((caddr_t)&so->so_timeo,
                                                PSOCK | PCATCH, netcls,                                                 PSOCK | PCATCH, netcls,
                                                so->so_linger);                                                 so->so_linger * hz);
                                 if (error)                                  if (error)
                                         break;                                          break;
                         }                          }
Line 223  soabort(so)
Line 258  soabort(so)
   
 int  int
 soaccept(so, nam)  soaccept(so, nam)
         register struct socket *so;          struct socket *so;
         struct mbuf *nam;          struct mbuf *nam;
 {  {
         int s = splsoftnet();          int s = splsoftnet();
Line 232  soaccept(so, nam)
Line 267  soaccept(so, nam)
         if ((so->so_state & SS_NOFDREF) == 0)          if ((so->so_state & SS_NOFDREF) == 0)
                 panic("soaccept: !NOFDREF");                  panic("soaccept: !NOFDREF");
         so->so_state &= ~SS_NOFDREF;          so->so_state &= ~SS_NOFDREF;
         error = (*so->so_proto->pr_usrreq)(so, PRU_ACCEPT, (struct mbuf *)0,          if ((so->so_state & SS_ISDISCONNECTED) == 0)
             nam, (struct mbuf *)0, (struct proc *)0);                  error = (*so->so_proto->pr_usrreq)(so, PRU_ACCEPT,
                       (struct mbuf *)0, nam, (struct mbuf *)0, (struct proc *)0);
           else
                   error = 0;
         splx(s);          splx(s);
         return (error);          return (error);
 }  }
   
 int  int
 soconnect(so, nam)  soconnect(so, nam)
         register struct socket *so;          struct socket *so;
         struct mbuf *nam;          struct mbuf *nam;
 {  {
         struct proc *p = curproc;               /* XXX */          struct proc *p = curproc;               /* XXX */
Line 269  soconnect(so, nam)
Line 307  soconnect(so, nam)
   
 int  int
 soconnect2(so1, so2)  soconnect2(so1, so2)
         register struct socket *so1;          struct socket *so1;
         struct socket *so2;          struct socket *so2;
 {  {
         int s = splsoftnet();          int s = splsoftnet();
Line 284  soconnect2(so1, so2)
Line 322  soconnect2(so1, so2)
   
 int  int
 sodisconnect(so)  sodisconnect(so)
         register struct socket *so;          struct socket *so;
 {  {
         int s = splsoftnet();          int s = splsoftnet();
         int error;          int error;
Line 325  bad:
Line 363  bad:
  */   */
 int  int
 sosend(so, addr, uio, top, control, flags)  sosend(so, addr, uio, top, control, flags)
         register struct socket *so;          struct socket *so;
         struct mbuf *addr;          struct mbuf *addr;
         struct uio *uio;          struct uio *uio;
         struct mbuf *top;          struct mbuf *top;
Line 334  sosend(so, addr, uio, top, control, flag
Line 372  sosend(so, addr, uio, top, control, flag
 {  {
         struct proc *p = curproc;               /* XXX */          struct proc *p = curproc;               /* XXX */
         struct mbuf **mp;          struct mbuf **mp;
         register struct mbuf *m;          struct mbuf *m;
         register long space, len, resid;          long space, len, resid;
         int clen = 0, error, s, dontroute, mlen;          int clen = 0, error, s, dontroute, mlen;
         int atomic = sosendallatonce(so) || top;          int atomic = sosendallatonce(so) || top;
   
Line 350  sosend(so, addr, uio, top, control, flag
Line 388  sosend(so, addr, uio, top, control, flag
          * of space and resid.  On the other hand, a negative resid           * of space and resid.  On the other hand, a negative resid
          * causes us to loop sending 0-length segments to the protocol.           * causes us to loop sending 0-length segments to the protocol.
          */           */
         if (resid < 0)          if (resid < 0) {
                 return (EINVAL);                  error = EINVAL;
                   goto out;
           }
         dontroute =          dontroute =
             (flags & MSG_DONTROUTE) && (so->so_options & SO_DONTROUTE) == 0 &&              (flags & MSG_DONTROUTE) && (so->so_options & SO_DONTROUTE) == 0 &&
             (so->so_proto->pr_flags & PR_ATOMIC);              (so->so_proto->pr_flags & PR_ATOMIC);
Line 367  restart:
Line 407  restart:
                 s = splsoftnet();                  s = splsoftnet();
                 if (so->so_state & SS_CANTSENDMORE)                  if (so->so_state & SS_CANTSENDMORE)
                         snderr(EPIPE);                          snderr(EPIPE);
                 if (so->so_error)                  if (so->so_error) {
                         snderr(so->so_error);                          error = so->so_error;
                           so->so_error = 0;
                           splx(s);
                           goto release;
                   }
                 if ((so->so_state & SS_ISCONNECTED) == 0) {                  if ((so->so_state & SS_ISCONNECTED) == 0) {
                         if (so->so_proto->pr_flags & PR_CONNREQUIRED) {                          if (so->so_proto->pr_flags & PR_CONNREQUIRED) {
                                 if ((so->so_state & SS_ISCONFIRMING) == 0 &&                                  if ((so->so_state & SS_ISCONFIRMING) == 0 &&
Line 398  restart:
Line 442  restart:
                 mp = &top;                  mp = &top;
                 space -= clen;                  space -= clen;
                 do {                  do {
                     if (uio == NULL) {                          if (uio == NULL) {
                         /*                                  /*
                          * Data is prepackaged in "top".                                   * Data is prepackaged in "top".
                          */                                   */
                         resid = 0;                                  resid = 0;
                         if (flags & MSG_EOR)                                  if (flags & MSG_EOR)
                                 top->m_flags |= M_EOR;                                          top->m_flags |= M_EOR;
                     } else do {                          } else do {
                         if (top == 0) {                                  if (top == 0) {
                                 MGETHDR(m, M_WAIT, MT_DATA);                                          MGETHDR(m, M_WAIT, MT_DATA);
                                 mlen = MHLEN;                                          mlen = MHLEN;
                                 m->m_pkthdr.len = 0;                                          m->m_pkthdr.len = 0;
                                 m->m_pkthdr.rcvif = (struct ifnet *)0;                                          m->m_pkthdr.rcvif = (struct ifnet *)0;
                         } else {                                  } else {
                                 MGET(m, M_WAIT, MT_DATA);                                          MGET(m, M_WAIT, MT_DATA);
                                 mlen = MLEN;                                          mlen = MLEN;
                         }                                  }
                         if (resid >= MINCLSIZE && space >= MCLBYTES) {                                  if (resid >= MINCLSIZE && space >= MCLBYTES) {
                                 MCLGET(m, M_WAIT);                                          MCLGET(m, M_WAIT);
                                 if ((m->m_flags & M_EXT) == 0)                                          if ((m->m_flags & M_EXT) == 0)
                                         goto nopages;                                                  goto nopages;
                                 mlen = MCLBYTES;                                          mlen = MCLBYTES;
 #ifdef  MAPPED_MBUFS  #ifdef  MAPPED_MBUFS
                                 len = min(MCLBYTES, resid);  
 #else  
                                 if (atomic && top == 0) {  
                                         len = min(MCLBYTES - max_hdr, resid);  
                                         m->m_data += max_hdr;  
                                 } else  
                                         len = min(MCLBYTES, resid);                                          len = min(MCLBYTES, resid);
   #else
                                           if (atomic && top == 0) {
                                                   len = min(MCLBYTES - max_hdr, resid);
                                                   m->m_data += max_hdr;
                                           } else
                                                   len = min(MCLBYTES, resid);
 #endif  #endif
                                 space -= len;                                          space -= len;
                         } else {                                  } else {
 nopages:  nopages:
                                 len = min(min(mlen, resid), space);                                          len = min(min(mlen, resid), space);
                                 space -= len;                                          space -= len;
                                 /*                                          /*
                                  * For datagram protocols, leave room                                           * For datagram protocols, leave room
                                  * for protocol headers in first mbuf.                                           * for protocol headers in first mbuf.
                                  */                                           */
                                 if (atomic && top == 0 && len < mlen)                                          if (atomic && top == 0 && len < mlen)
                                         MH_ALIGN(m, len);                                                  MH_ALIGN(m, len);
                         }                                  }
                         error = uiomove(mtod(m, caddr_t), (int)len, uio);                                  error = uiomove(mtod(m, caddr_t), (int)len, uio);
                         resid = uio->uio_resid;                                  resid = uio->uio_resid;
                         m->m_len = len;                                  m->m_len = len;
                         *mp = m;                                  *mp = m;
                         top->m_pkthdr.len += len;                                  top->m_pkthdr.len += len;
                                   if (error)
                                           goto release;
                                   mp = &m->m_next;
                                   if (resid <= 0) {
                                           if (flags & MSG_EOR)
                                                   top->m_flags |= M_EOR;
                                           break;
                                   }
                           } while (space > 0 && atomic);
   
                           s = splsoftnet();
   
                           if (so->so_state & SS_CANTSENDMORE)
                                   snderr(EPIPE);
   
                           if (dontroute)
                                   so->so_options |= SO_DONTROUTE;
                           if (resid > 0)
                                   so->so_state |= SS_MORETOCOME;
                           error = (*so->so_proto->pr_usrreq)(so,
                               (flags & MSG_OOB) ? PRU_SENDOOB : PRU_SEND,
                               top, addr, control, p);
                           if (dontroute)
                                   so->so_options &= ~SO_DONTROUTE;
                           if (resid > 0)
                                   so->so_state &= ~SS_MORETOCOME;
                           splx(s);
   
                           clen = 0;
                           control = 0;
                           top = 0;
                           mp = &top;
                         if (error)                          if (error)
                                 goto release;                                  goto release;
                         mp = &m->m_next;  
                         if (resid <= 0) {  
                                 if (flags & MSG_EOR)  
                                         top->m_flags |= M_EOR;  
                                 break;  
                         }  
                     } while (space > 0 && atomic);  
                     if (dontroute)  
                             so->so_options |= SO_DONTROUTE;  
                     s = splsoftnet();                           /* XXX */  
                     error = (*so->so_proto->pr_usrreq)(so,  
                         (flags & MSG_OOB) ? PRU_SENDOOB : PRU_SEND,  
                         top, addr, control, p);  
                     splx(s);  
                     if (dontroute)  
                             so->so_options &= ~SO_DONTROUTE;  
                     clen = 0;  
                     control = 0;  
                     top = 0;  
                     mp = &top;  
                     if (error)  
                         goto release;  
                 } while (resid && space > 0);                  } while (resid && space > 0);
         } while (resid);          } while (resid);
   
Line 501  out:
Line 555  out:
  */   */
 int  int
 soreceive(so, paddr, uio, mp0, controlp, flagsp)  soreceive(so, paddr, uio, mp0, controlp, flagsp)
         register struct socket *so;          struct socket *so;
         struct mbuf **paddr;          struct mbuf **paddr;
         struct uio *uio;          struct uio *uio;
         struct mbuf **mp0;          struct mbuf **mp0;
         struct mbuf **controlp;          struct mbuf **controlp;
         int *flagsp;          int *flagsp;
 {  {
         register struct mbuf *m, **mp;          struct mbuf *m, **mp;
         register int flags, len, error, s, offset;          int flags, len, error, s, offset;
         struct protosw *pr = so->so_proto;          struct protosw *pr = so->so_proto;
         struct mbuf *nextrecord;          struct mbuf *nextrecord;
         int moff, type = 0;          int moff, type = 0;
Line 650  dontblock:
Line 704  dontblock:
                                 if (pr->pr_domain->dom_externalize &&                                  if (pr->pr_domain->dom_externalize &&
                                     mtod(m, struct cmsghdr *)->cmsg_type ==                                      mtod(m, struct cmsghdr *)->cmsg_type ==
                                     SCM_RIGHTS)                                      SCM_RIGHTS)
                                    error = (*pr->pr_domain->dom_externalize)(m);                                          error = (*pr->pr_domain->dom_externalize)(m);
                                 *controlp = m;                                  *controlp = m;
                                 so->so_rcv.sb_mb = m->m_next;                                  so->so_rcv.sb_mb = m->m_next;
                                 m->m_next = 0;                                  m->m_next = 0;
Line 803  release:
Line 857  release:
   
 int  int
 soshutdown(so, how)  soshutdown(so, how)
         register struct socket *so;          struct socket *so;
         register int how;          int how;
 {  {
         register struct protosw *pr = so->so_proto;          struct protosw *pr = so->so_proto;
   
         how++;          if (!(how == SHUT_RD || how == SHUT_WR || how == SHUT_RDWR))
         if (how & FREAD)                  return (EINVAL);
   
           if (how == SHUT_RD || how == SHUT_RDWR)
                 sorflush(so);                  sorflush(so);
         if (how & FWRITE)          if (how == SHUT_WR || how == SHUT_RDWR)
                 return (*pr->pr_usrreq)(so, PRU_SHUTDOWN, (struct mbuf *)0,                  return (*pr->pr_usrreq)(so, PRU_SHUTDOWN, (struct mbuf *)0,
                     (struct mbuf *)0, (struct mbuf *)0, (struct proc *)0);                      (struct mbuf *)0, (struct mbuf *)0, (struct proc *)0);
         return (0);          return (0);
Line 819  soshutdown(so, how)
Line 875  soshutdown(so, how)
   
 void  void
 sorflush(so)  sorflush(so)
         register struct socket *so;          struct socket *so;
 {  {
         register struct sockbuf *sb = &so->so_rcv;          struct sockbuf *sb = &so->so_rcv;
         register struct protosw *pr = so->so_proto;          struct protosw *pr = so->so_proto;
         register int s;          int s;
         struct sockbuf asb;          struct sockbuf asb;
   
         sb->sb_flags |= SB_NOINTR;          sb->sb_flags |= SB_NOINTR;
Line 832  sorflush(so)
Line 888  sorflush(so)
         socantrcvmore(so);          socantrcvmore(so);
         sbunlock(sb);          sbunlock(sb);
         asb = *sb;          asb = *sb;
         bzero((caddr_t)sb, sizeof (*sb));          memset((caddr_t)sb, 0, sizeof(*sb));
         splx(s);          splx(s);
         if (pr->pr_flags & PR_RIGHTS && pr->pr_domain->dom_dispose)          if (pr->pr_flags & PR_RIGHTS && pr->pr_domain->dom_dispose)
                 (*pr->pr_domain->dom_dispose)(asb.sb_mb);                  (*pr->pr_domain->dom_dispose)(asb.sb_mb);
Line 841  sorflush(so)
Line 897  sorflush(so)
   
 int  int
 sosetopt(so, level, optname, m0)  sosetopt(so, level, optname, m0)
         register struct socket *so;          struct socket *so;
         int level, optname;          int level, optname;
         struct mbuf *m0;          struct mbuf *m0;
 {  {
         int error = 0;          int error = 0;
         register struct mbuf *m = m0;          struct mbuf *m = m0;
   
         if (level != SOL_SOCKET) {          if (level != SOL_SOCKET) {
                 if (so->so_proto && so->so_proto->pr_ctloutput)                  if (so->so_proto && so->so_proto->pr_ctloutput)
Line 857  sosetopt(so, level, optname, m0)
Line 913  sosetopt(so, level, optname, m0)
                 switch (optname) {                  switch (optname) {
   
                 case SO_LINGER:                  case SO_LINGER:
                         if (m == NULL || m->m_len != sizeof (struct linger)) {                          if (m == NULL || m->m_len != sizeof(struct linger)) {
                                 error = EINVAL;                                  error = EINVAL;
                                 goto bad;                                  goto bad;
                         }                          }
Line 873  sosetopt(so, level, optname, m0)
Line 929  sosetopt(so, level, optname, m0)
                 case SO_REUSEPORT:                  case SO_REUSEPORT:
                 case SO_OOBINLINE:                  case SO_OOBINLINE:
                 case SO_TIMESTAMP:                  case SO_TIMESTAMP:
                         if (m == NULL || m->m_len < sizeof (int)) {                          if (m == NULL || m->m_len < sizeof(int)) {
                                 error = EINVAL;                                  error = EINVAL;
                                 goto bad;                                  goto bad;
                         }                          }
Line 887  sosetopt(so, level, optname, m0)
Line 943  sosetopt(so, level, optname, m0)
                 case SO_RCVBUF:                  case SO_RCVBUF:
                 case SO_SNDLOWAT:                  case SO_SNDLOWAT:
                 case SO_RCVLOWAT:                  case SO_RCVLOWAT:
                         if (m == NULL || m->m_len < sizeof (int)) {                      {
                           int optval;
   
                           if (m == NULL || m->m_len < sizeof(int)) {
                                 error = EINVAL;                                  error = EINVAL;
                                 goto bad;                                  goto bad;
                         }                          }
   
                           /*
                            * Values < 1 make no sense for any of these
                            * options, so disallow them.
                            */
                           optval = *mtod(m, int *);
                           if (optval < 1) {
                                   error = EINVAL;
                                   goto bad;
                           }
   
                         switch (optname) {                          switch (optname) {
   
                         case SO_SNDBUF:                          case SO_SNDBUF:
                         case SO_RCVBUF:                          case SO_RCVBUF:
                                 if (sbreserve(optname == SO_SNDBUF ?                                  if (sbreserve(optname == SO_SNDBUF ?
                                     &so->so_snd : &so->so_rcv,                                      &so->so_snd : &so->so_rcv,
                                     (u_long) *mtod(m, int *)) == 0) {                                      (u_long) optval) == 0) {
                                         error = ENOBUFS;                                          error = ENOBUFS;
                                         goto bad;                                          goto bad;
                                 }                                  }
                                 break;                                  break;
   
                           /*
                            * Make sure the low-water is never greater than
                            * the high-water.
                            */
                         case SO_SNDLOWAT:                          case SO_SNDLOWAT:
                                 so->so_snd.sb_lowat = *mtod(m, int *);                                  so->so_snd.sb_lowat =
                                       (optval > so->so_snd.sb_hiwat) ?
                                       so->so_snd.sb_hiwat : optval;
                                 break;                                  break;
                         case SO_RCVLOWAT:                          case SO_RCVLOWAT:
                                 so->so_rcv.sb_lowat = *mtod(m, int *);                                  so->so_rcv.sb_lowat =
                                       (optval > so->so_rcv.sb_hiwat) ?
                                       so->so_rcv.sb_hiwat : optval;
                                 break;                                  break;
                         }                          }
                         break;                          break;
                       }
   
                 case SO_SNDTIMEO:                  case SO_SNDTIMEO:
                 case SO_RCVTIMEO:                  case SO_RCVTIMEO:
Line 918  sosetopt(so, level, optname, m0)
Line 997  sosetopt(so, level, optname, m0)
                         struct timeval *tv;                          struct timeval *tv;
                         short val;                          short val;
   
                         if (m == NULL || m->m_len < sizeof (*tv)) {                          if (m == NULL || m->m_len < sizeof(*tv)) {
                                 error = EINVAL;                                  error = EINVAL;
                                 goto bad;                                  goto bad;
                         }                          }
Line 959  bad:
Line 1038  bad:
   
 int  int
 sogetopt(so, level, optname, mp)  sogetopt(so, level, optname, mp)
         register struct socket *so;          struct socket *so;
         int level, optname;          int level, optname;
         struct mbuf **mp;          struct mbuf **mp;
 {  {
         register struct mbuf *m;          struct mbuf *m;
   
         if (level != SOL_SOCKET) {          if (level != SOL_SOCKET) {
                 if (so->so_proto && so->so_proto->pr_ctloutput) {                  if (so->so_proto && so->so_proto->pr_ctloutput) {
Line 973  sogetopt(so, level, optname, mp)
Line 1052  sogetopt(so, level, optname, mp)
                         return (ENOPROTOOPT);                          return (ENOPROTOOPT);
         } else {          } else {
                 m = m_get(M_WAIT, MT_SOOPTS);                  m = m_get(M_WAIT, MT_SOOPTS);
                 m->m_len = sizeof (int);                  m->m_len = sizeof(int);
   
                 switch (optname) {                  switch (optname) {
   
                 case SO_LINGER:                  case SO_LINGER:
                         m->m_len = sizeof (struct linger);                          m->m_len = sizeof(struct linger);
                         mtod(m, struct linger *)->l_onoff =                          mtod(m, struct linger *)->l_onoff =
                                 so->so_options & SO_LINGER;                                  so->so_options & SO_LINGER;
                         mtod(m, struct linger *)->l_linger = so->so_linger;                          mtod(m, struct linger *)->l_linger = so->so_linger;
Line 1045  sogetopt(so, level, optname, mp)
Line 1124  sogetopt(so, level, optname, mp)
   
 void  void
 sohasoutofband(so)  sohasoutofband(so)
         register struct socket *so;          struct socket *so;
 {  {
         struct proc *p;          struct proc *p;
   

Legend:
Removed from v.1.27  
changed lines
  Added in v.1.48.2.2

CVSweb <webmaster@jp.NetBSD.org>