This source file includes following definitions.
- svr4_netattach
- svr4_netopen
- svr4_soo_close
- svr4_stream_get
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 #include <sys/param.h>
36 #include <sys/kernel.h>
37 #include <sys/systm.h>
38 #include <sys/buf.h>
39 #include <sys/malloc.h>
40 #include <sys/ioctl.h>
41 #include <sys/tty.h>
42 #include <sys/file.h>
43 #include <sys/filedesc.h>
44 #include <sys/selinfo.h>
45 #include <sys/socket.h>
46 #include <sys/socketvar.h>
47 #include <sys/protosw.h>
48 #include <sys/domain.h>
49 #include <net/if.h>
50 #include <netinet/in.h>
51 #include <sys/proc.h>
52 #include <sys/vnode.h>
53 #include <sys/device.h>
54 #include <sys/conf.h>
55
56
57 #include <compat/svr4/svr4_types.h>
58 #include <compat/svr4/svr4_util.h>
59 #include <compat/svr4/svr4_signal.h>
60 #include <compat/svr4/svr4_syscallargs.h>
61 #include <compat/svr4/svr4_ioctl.h>
62 #include <compat/svr4/svr4_stropts.h>
63 #include <compat/svr4/svr4_socket.h>
64
65
66
67
68 enum {
69 dev_arp = 26,
70 dev_icmp = 27,
71 dev_ip = 28,
72 dev_tcp = 35,
73 dev_udp = 36,
74 dev_rawip = 37,
75 dev_unix_dgram = 38,
76 dev_unix_stream = 39,
77 dev_unix_ord_stream = 40
78 };
79
80 int svr4_netattach(int);
81
82 static int svr4_soo_close(struct file *fp, struct proc *p);
83
84 static struct fileops svr4_netops = {
85 soo_read, soo_write, soo_ioctl, soo_poll, soo_kqfilter,
86 soo_stat, svr4_soo_close
87 };
88
89
90
91
92
93 int
94 svr4_netattach(n)
95 int n;
96 {
97 return 0;
98 }
99
100
101 int
102 svr4_netopen(dev, flag, mode, p)
103 dev_t dev;
104 int flag;
105 int mode;
106 struct proc *p;
107 {
108 int type, protocol;
109 int fd;
110 struct file *fp;
111 struct socket *so;
112 int error;
113 int family;
114
115 DPRINTF(("netopen("));
116
117 if (p->p_dupfd >= 0)
118 return ENODEV;
119
120 switch (minor(dev)) {
121 case dev_udp:
122 family = AF_INET;
123 type = SOCK_DGRAM;
124 protocol = IPPROTO_UDP;
125 DPRINTF(("udp, "));
126 break;
127
128 case dev_tcp:
129 family = AF_INET;
130 type = SOCK_STREAM;
131 protocol = IPPROTO_TCP;
132 DPRINTF(("tcp, "));
133 break;
134
135 case dev_ip:
136 case dev_rawip:
137 family = AF_INET;
138 type = SOCK_RAW;
139 protocol = IPPROTO_IP;
140 DPRINTF(("ip, "));
141 break;
142
143 case dev_icmp:
144 family = AF_INET;
145 type = SOCK_RAW;
146 protocol = IPPROTO_ICMP;
147 DPRINTF(("icmp, "));
148 break;
149
150 case dev_unix_dgram:
151 family = AF_UNIX;
152 type = SOCK_DGRAM;
153 protocol = 0;
154 DPRINTF(("unix-dgram, "));
155 break;
156
157 case dev_unix_stream:
158 case dev_unix_ord_stream:
159 family = AF_UNIX;
160 type = SOCK_STREAM;
161 protocol = 0;
162 DPRINTF(("unix-stream, "));
163 break;
164
165 default:
166 DPRINTF(("%d);\n", minor(dev)));
167 return EOPNOTSUPP;
168 }
169
170 if ((error = falloc(p, &fp, &fd)) != 0)
171 return (error);
172
173 if ((error = socreate(family, &so, type, protocol)) != 0) {
174 DPRINTF(("socreate error %d\n", error));
175 fdremove(p->p_fd, fd);
176 closef(fp, p);
177 return error;
178 }
179
180 fp->f_flag = FREAD|FWRITE;
181 fp->f_type = DTYPE_SOCKET;
182 fp->f_ops = &svr4_netops;
183
184 fp->f_data = (caddr_t)so;
185 (void) svr4_stream_get(fp);
186
187 DPRINTF(("ok);\n"));
188
189 p->p_dupfd = fd;
190 FILE_SET_MATURE(fp);
191 return ENXIO;
192 }
193
194 static int
195 svr4_soo_close(fp, p)
196 struct file *fp;
197 struct proc *p;
198 {
199 struct socket *so = (struct socket *) fp->f_data;
200 svr4_delete_socket(p, fp);
201 free(so->so_internal, M_NETADDR);
202 return soo_close(fp, p);
203 }
204
205 struct svr4_strm *
206 svr4_stream_get(fp)
207 struct file *fp;
208 {
209 struct socket *so;
210 struct svr4_strm *st;
211
212 if (fp == NULL || fp->f_type != DTYPE_SOCKET)
213 return NULL;
214
215 so = (struct socket *) fp->f_data;
216
217 if (so->so_internal)
218 return so->so_internal;
219
220
221 fp->f_ops = &svr4_netops;
222 st = malloc(sizeof(struct svr4_strm), M_NETADDR, M_WAITOK);
223 st->s_family = so->so_proto->pr_domain->dom_family;
224 st->s_cmd = ~0;
225 st->s_afd = -1;
226 so->so_internal = st;
227
228 return st;
229 }