add some missing returns, correct args to ipcaccess, general cleanup
[unix-history] / usr / src / sys / kern / sys_socket.c
CommitLineData
da7c5cc6 1/*
ac79b8e6 2 * Copyright (c) 1982, 1986, 1990 Regents of the University of California.
e0813a30 3 * All rights reserved.
da7c5cc6 4 *
e0813a30 5 * Redistribution and use in source and binary forms are permitted
616d42db
KB
6 * provided that the above copyright notice and this paragraph are
7 * duplicated in all such forms and that any documentation,
8 * advertising materials, and other materials related to such
9 * distribution and use acknowledge that the software was developed
10 * by the University of California, Berkeley. The name of the
11 * University may not be used to endorse or promote products derived
12 * from this software without specific prior written permission.
13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
e0813a30 16 *
ac79b8e6 17 * @(#)sys_socket.c 7.6 (Berkeley) %G%
da7c5cc6 18 */
48aab316 19
94368568
JB
20#include "param.h"
21#include "systm.h"
94368568
JB
22#include "user.h"
23#include "file.h"
24#include "mbuf.h"
25#include "protosw.h"
26#include "socket.h"
27#include "socketvar.h"
28#include "ioctl.h"
29#include "uio.h"
30#include "stat.h"
48aab316
SL
31
32#include "../net/if.h"
33#include "../net/route.h"
34
c4ec2128 35int soo_read(), soo_write(), soo_ioctl(), soo_select(), soo_close();
48aab316 36struct fileops socketops =
c4ec2128 37 { soo_read, soo_write, soo_ioctl, soo_select, soo_close };
48aab316 38
c4ec2128
KM
39/* ARGSUSED */
40soo_read(fp, uio, cred)
48aab316 41 struct file *fp;
48aab316 42 struct uio *uio;
c4ec2128 43 struct ucred *cred;
48aab316 44{
48aab316 45
c4ec2128 46 return (soreceive((struct socket *)fp->f_data, (struct mbuf **)0,
ac79b8e6 47 uio, (struct mbuf **)0, (struct mbuf **)0, (int *)0));
c4ec2128
KM
48}
49
50/* ARGSUSED */
51soo_write(fp, uio, cred)
52 struct file *fp;
53 struct uio *uio;
54 struct ucred *cred;
55{
56
57 return (sosend((struct socket *)fp->f_data, (struct mbuf *)0,
ac79b8e6 58 uio, (struct mbuf *)0, (struct mbuf *)0, 0));
48aab316
SL
59}
60
61soo_ioctl(fp, cmd, data)
62 struct file *fp;
63 int cmd;
64 register caddr_t data;
65{
66 register struct socket *so = (struct socket *)fp->f_data;
67
68 switch (cmd) {
69
70 case FIONBIO:
71 if (*(int *)data)
72 so->so_state |= SS_NBIO;
73 else
74 so->so_state &= ~SS_NBIO;
1116b929 75 return (0);
48aab316
SL
76
77 case FIOASYNC:
78 if (*(int *)data)
79 so->so_state |= SS_ASYNC;
80 else
81 so->so_state &= ~SS_ASYNC;
1116b929 82 return (0);
48aab316 83
8b899dbe
SL
84 case FIONREAD:
85 *(int *)data = so->so_rcv.sb_cc;
1116b929 86 return (0);
8b899dbe 87
48aab316 88 case SIOCSPGRP:
a2aebb63 89 so->so_pgid = *(int *)data;
1116b929 90 return (0);
48aab316
SL
91
92 case SIOCGPGRP:
a2aebb63 93 *(int *)data = so->so_pgid;
1116b929 94 return (0);
48aab316
SL
95
96 case SIOCATMARK:
97 *(int *)data = (so->so_state&SS_RCVATMARK) != 0;
1116b929 98 return (0);
48aab316 99 }
1116b929
SL
100 /*
101 * Interface/routing/protocol specific ioctls:
102 * interface and routing ioctls should have a
103 * different entry since a socket's unnecessary
104 */
ac79b8e6 105 if (IOCGROUP(cmd) == 'i')
adcb6261 106 return (ifioctl(so, cmd, data));
ac79b8e6 107 if (IOCGROUP(cmd) == 'r')
1116b929
SL
108 return (rtioctl(cmd, data));
109 return ((*so->so_proto->pr_usrreq)(so, PRU_CONTROL,
110 (struct mbuf *)cmd, (struct mbuf *)data, (struct mbuf *)0));
48aab316
SL
111}
112
113soo_select(fp, which)
114 struct file *fp;
115 int which;
116{
117 register struct socket *so = (struct socket *)fp->f_data;
118 register int s = splnet();
119
120 switch (which) {
121
122 case FREAD:
123 if (soreadable(so)) {
124 splx(s);
125 return (1);
126 }
127 sbselqueue(&so->so_rcv);
128 break;
129
130 case FWRITE:
131 if (sowriteable(so)) {
132 splx(s);
133 return (1);
134 }
135 sbselqueue(&so->so_snd);
136 break;
de2c74a5
MK
137
138 case 0:
139 if (so->so_oobmark ||
140 (so->so_state & SS_RCVATMARK)) {
141 splx(s);
142 return (1);
143 }
144 sbselqueue(&so->so_rcv);
145 break;
48aab316
SL
146 }
147 splx(s);
148 return (0);
149}
150
502b634a 151/*ARGSUSED*/
92438dfc
SL
152soo_stat(so, ub)
153 register struct socket *so;
48aab316
SL
154 register struct stat *ub;
155{
48aab316
SL
156
157 bzero((caddr_t)ub, sizeof (*ub));
48aab316
SL
158 return ((*so->so_proto->pr_usrreq)(so, PRU_SENSE,
159 (struct mbuf *)ub, (struct mbuf *)0,
160 (struct mbuf *)0));
48aab316
SL
161}
162
163soo_close(fp)
164 struct file *fp;
165{
ec04fec2 166 int error = 0;
e0813a30 167
ec04fec2
SL
168 if (fp->f_data)
169 error = soclose((struct socket *)fp->f_data);
48aab316
SL
170 fp->f_data = 0;
171 return (error);
172}