1: /*
   2:  * Copyright (c) 1982, 1986 Regents of the University of California.
   3:  * All rights reserved.
   4:  *
   5:  * Redistribution and use in source and binary forms are permitted
   6:  * provided that this notice is preserved and that due credit is given
   7:  * to the University of California at Berkeley. The name of the University
   8:  * may not be used to endorse or promote products derived from this
   9:  * software without specific prior written permission. This software
  10:  * is provided ``as is'' without express or implied warranty.
  11:  *
  12:  *	@(#)sys_socket.c	7.2 (Berkeley) 3/31/88
  13:  */
  14: 
  15: #include "param.h"
  16: #ifdef INET
  17: #include "systm.h"
  18: #include "user.h"
  19: #include "file.h"
  20: #include "mbuf.h"
  21: #include "protosw.h"
  22: #include "socket.h"
  23: #include "socketvar.h"
  24: #include "ioctl.h"
  25: #include "stat.h"
  26: 
  27: #include "../net/if.h"
  28: #include "../net/route.h"
  29: 
  30: /*ARGSUSED*/
  31: soo_ioctl(so, cmd, data)
  32:     struct socket *so;  /* remember to have the kentry routine pass */
  33:                 /* a socket NOT a file pointer */
  34:     int cmd;
  35:     register caddr_t data;
  36: {
  37: 
  38:     switch (cmd) {
  39: 
  40:     case FIONBIO:
  41:         if (*(int *)data)
  42:             so->so_state |= SS_NBIO;
  43:         else
  44:             so->so_state &= ~SS_NBIO;
  45:         return (0);
  46: 
  47:     case FIOASYNC:
  48:         if (*(int *)data)
  49:             so->so_state |= SS_ASYNC;
  50:         else
  51:             so->so_state &= ~SS_ASYNC;
  52:         return (0);
  53: 
  54:     case FIONREAD:
  55:         *(long *)data = so->so_rcv.sb_cc;
  56:         return (0);
  57: 
  58:     case SIOCSPGRP:
  59:         so->so_pgrp = *(int *)data;
  60:         return (0);
  61: 
  62:     case SIOCGPGRP:
  63:         *(int *)data = so->so_pgrp;
  64:         return (0);
  65: 
  66:     case SIOCATMARK:
  67:         *(int *)data = (so->so_state&SS_RCVATMARK) != 0;
  68:         return (0);
  69:     }
  70:     /*
  71: 	 * Interface/routing/protocol specific ioctls:
  72: 	 * interface and routing ioctls should have a
  73: 	 * different entry since a socket's unnecessary
  74: 	 */
  75: #define cmdbyte(x)  (((x) >> 8) & 0xff)
  76:     if (cmdbyte(cmd) == 'i')
  77:         return(u.u_error = ifioctl(so, cmd, data));
  78:     if (cmdbyte(cmd) == 'r')
  79:         return(u.u_error = rtioctl(cmd, data));
  80:     return(u.u_error = (*so->so_proto->pr_usrreq)(so, PRU_CONTROL,
  81:         (struct mbuf *)cmd, (struct mbuf *)data, (struct mbuf *)0));
  82: }
  83: 
  84: soo_select(so, which)
  85:     register struct socket *so;  /* kentry() must pass socket not file */
  86:     int which;
  87: {
  88:     register int s = splnet();
  89: 
  90:     switch (which) {
  91: 
  92:     case FREAD:
  93:         if (soreadable(so)) {
  94:             splx(s);
  95:             return (1);
  96:         }
  97:         sbselqueue(&so->so_rcv);
  98:         break;
  99: 
 100:     case FWRITE:
 101:         if (sowriteable(so)) {
 102:             splx(s);
 103:             return (1);
 104:         }
 105:         sbselqueue(&so->so_snd);
 106:         break;
 107: 
 108:     case 0:
 109:         if (so->so_oobmark ||
 110:             (so->so_state & SS_RCVATMARK)) {
 111:             splx(s);
 112:             return (1);
 113:         }
 114:         sbselqueue(&so->so_rcv);
 115:         break;
 116:     }
 117:     splx(s);
 118:     return (0);
 119: }
 120: 
 121: /*ARGSUSED*/
 122: soo_stat(so, ub)
 123:     register struct socket *so;
 124:     register struct stat *ub;
 125: {
 126: 
 127:     bzero((caddr_t)ub, sizeof (*ub));
 128:     return ((*so->so_proto->pr_usrreq)(so, PRU_SENSE,
 129:         (struct mbuf *)ub, (struct mbuf *)0,
 130:         (struct mbuf *)0));
 131: }
 132: #endif

Defined functions

soo_ioctl defined in line 31; used 2 times
soo_select defined in line 84; used 2 times
soo_stat defined in line 122; used 2 times

Defined macros

cmdbyte defined in line 75; used 2 times
Last modified: 1992-12-25
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2804
Valid CSS Valid XHTML 1.0 Strict