|
|
1.1 root 1: /*
2: * Copyright (c) 1982, 1986, 1990 Regents of the University of California.
3: * All rights reserved.
4: *
5: * Redistribution is only permitted until one year after the first shipment
6: * of 4.4BSD by the Regents. Otherwise, redistribution and use in source and
7: * binary forms are permitted provided that: (1) source distributions retain
8: * this entire copyright notice and comment, and (2) distributions including
9: * binaries display the following acknowledgement: This product includes
10: * software developed by the University of California, Berkeley and its
11: * contributors'' in the documentation or other materials provided with the
12: * distribution and in all advertising materials mentioning features or use
13: * of this software. Neither the name of the University nor the names of
14: * its contributors may be used to endorse or promote products derived from
15: * this software without specific prior written permission.
16: * THIS SOFTWARE IS PROVIDED AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
17: * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
18: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19: *
20: * @(#)sys_socket.c 7.8 (Berkeley) 6/28/90
21: */
22:
23: #include "param.h"
24: #include "systm.h"
25: #include "user.h"
26: #include "file.h"
27: #include "mbuf.h"
28: #include "protosw.h"
29: #include "socket.h"
30: #include "socketvar.h"
31: #include "ioctl.h"
32: #include "uio.h"
33: #include "stat.h"
34:
35: #include "../net/if.h"
36: #include "../net/route.h"
37:
38: int soo_read(), soo_write(), soo_ioctl(), soo_select(), soo_close();
39: struct fileops socketops =
40: { soo_read, soo_write, soo_ioctl, soo_select, soo_close };
41:
42: /* ARGSUSED */
43: soo_read(fp, uio, cred)
44: struct file *fp;
45: struct uio *uio;
46: struct ucred *cred;
47: {
48:
49: return (soreceive((struct socket *)fp->f_data, (struct mbuf **)0,
50: uio, (struct mbuf **)0, (struct mbuf **)0, (int *)0));
51: }
52:
53: /* ARGSUSED */
54: soo_write(fp, uio, cred)
55: struct file *fp;
56: struct uio *uio;
57: struct ucred *cred;
58: {
59:
60: return (sosend((struct socket *)fp->f_data, (struct mbuf *)0,
61: uio, (struct mbuf *)0, (struct mbuf *)0, 0));
62: }
63:
64: soo_ioctl(fp, cmd, data)
65: struct file *fp;
66: int cmd;
67: register caddr_t data;
68: {
69: register struct socket *so = (struct socket *)fp->f_data;
70:
71: switch (cmd) {
72:
73: case FIONBIO:
74: if (*(int *)data)
75: so->so_state |= SS_NBIO;
76: else
77: so->so_state &= ~SS_NBIO;
78: return (0);
79:
80: case FIOASYNC:
81: if (*(int *)data) {
82: so->so_state |= SS_ASYNC;
83: so->so_rcv.sb_flags |= SB_ASYNC;
84: so->so_snd.sb_flags |= SB_ASYNC;
85: } else {
86: so->so_state &= ~SS_ASYNC;
87: so->so_rcv.sb_flags &= ~SB_ASYNC;
88: so->so_snd.sb_flags &= ~SB_ASYNC;
89: }
90: return (0);
91:
92: case FIONREAD:
93: *(int *)data = so->so_rcv.sb_cc;
94: return (0);
95:
96: case SIOCSPGRP:
97: so->so_pgid = *(int *)data;
98: return (0);
99:
100: case SIOCGPGRP:
101: *(int *)data = so->so_pgid;
102: return (0);
103:
104: case SIOCATMARK:
105: *(int *)data = (so->so_state&SS_RCVATMARK) != 0;
106: return (0);
107: }
108: /*
109: * Interface/routing/protocol specific ioctls:
110: * interface and routing ioctls should have a
111: * different entry since a socket's unnecessary
112: */
113: if (IOCGROUP(cmd) == 'i')
114: return (ifioctl(so, cmd, data));
115: if (IOCGROUP(cmd) == 'r')
116: return (rtioctl(cmd, data));
117: return ((*so->so_proto->pr_usrreq)(so, PRU_CONTROL,
118: (struct mbuf *)cmd, (struct mbuf *)data, (struct mbuf *)0));
119: }
120:
121: soo_select(fp, which)
122: struct file *fp;
123: int which;
124: {
125: register struct socket *so = (struct socket *)fp->f_data;
126: register int s = splnet();
127:
128: switch (which) {
129:
130: case FREAD:
131: if (soreadable(so)) {
132: splx(s);
133: return (1);
134: }
135: sbselqueue(&so->so_rcv);
136: break;
137:
138: case FWRITE:
139: if (sowriteable(so)) {
140: splx(s);
141: return (1);
142: }
143: sbselqueue(&so->so_snd);
144: break;
145:
146: case 0:
147: if (so->so_oobmark ||
148: (so->so_state & SS_RCVATMARK)) {
149: splx(s);
150: return (1);
151: }
152: sbselqueue(&so->so_rcv);
153: break;
154: }
155: splx(s);
156: return (0);
157: }
158:
159: /*ARGSUSED*/
160: soo_stat(so, ub)
161: register struct socket *so;
162: register struct stat *ub;
163: {
164:
165: bzero((caddr_t)ub, sizeof (*ub));
166: return ((*so->so_proto->pr_usrreq)(so, PRU_SENSE,
167: (struct mbuf *)ub, (struct mbuf *)0,
168: (struct mbuf *)0));
169: }
170:
171: soo_close(fp)
172: struct file *fp;
173: {
174: int error = 0;
175:
176: if (fp->f_data)
177: error = soclose((struct socket *)fp->f_data);
178: fp->f_data = 0;
179: return (error);
180: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.