root / slirp / udp.c @ f9320410
History | View | Annotate | Download (17.3 kB)
1 | f0cbd3ec | bellard | /*
|
---|---|---|---|
2 | f0cbd3ec | bellard | * Copyright (c) 1982, 1986, 1988, 1990, 1993
|
3 | f0cbd3ec | bellard | * The Regents of the University of California. All rights reserved.
|
4 | f0cbd3ec | bellard | *
|
5 | f0cbd3ec | bellard | * Redistribution and use in source and binary forms, with or without
|
6 | f0cbd3ec | bellard | * modification, are permitted provided that the following conditions
|
7 | f0cbd3ec | bellard | * are met:
|
8 | f0cbd3ec | bellard | * 1. Redistributions of source code must retain the above copyright
|
9 | f0cbd3ec | bellard | * notice, this list of conditions and the following disclaimer.
|
10 | f0cbd3ec | bellard | * 2. Redistributions in binary form must reproduce the above copyright
|
11 | f0cbd3ec | bellard | * notice, this list of conditions and the following disclaimer in the
|
12 | f0cbd3ec | bellard | * documentation and/or other materials provided with the distribution.
|
13 | f0cbd3ec | bellard | * 3. All advertising materials mentioning features or use of this software
|
14 | f0cbd3ec | bellard | * must display the following acknowledgement:
|
15 | f0cbd3ec | bellard | * This product includes software developed by the University of
|
16 | f0cbd3ec | bellard | * California, Berkeley and its contributors.
|
17 | f0cbd3ec | bellard | * 4. Neither the name of the University nor the names of its contributors
|
18 | f0cbd3ec | bellard | * may be used to endorse or promote products derived from this software
|
19 | f0cbd3ec | bellard | * without specific prior written permission.
|
20 | f0cbd3ec | bellard | *
|
21 | f0cbd3ec | bellard | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
22 | f0cbd3ec | bellard | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
23 | f0cbd3ec | bellard | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
24 | f0cbd3ec | bellard | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
25 | f0cbd3ec | bellard | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
26 | f0cbd3ec | bellard | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
27 | f0cbd3ec | bellard | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
28 | f0cbd3ec | bellard | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
29 | f0cbd3ec | bellard | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
30 | f0cbd3ec | bellard | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
31 | f0cbd3ec | bellard | * SUCH DAMAGE.
|
32 | f0cbd3ec | bellard | *
|
33 | f0cbd3ec | bellard | * @(#)udp_usrreq.c 8.4 (Berkeley) 1/21/94
|
34 | f0cbd3ec | bellard | * udp_usrreq.c,v 1.4 1994/10/02 17:48:45 phk Exp
|
35 | f0cbd3ec | bellard | */
|
36 | f0cbd3ec | bellard | |
37 | f0cbd3ec | bellard | /*
|
38 | f0cbd3ec | bellard | * Changes and additions relating to SLiRP
|
39 | f0cbd3ec | bellard | * Copyright (c) 1995 Danny Gasparovski.
|
40 | 5fafdf24 | ths | *
|
41 | 5fafdf24 | ths | * Please read the file COPYRIGHT for the
|
42 | f0cbd3ec | bellard | * terms and conditions of the copyright.
|
43 | f0cbd3ec | bellard | */
|
44 | f0cbd3ec | bellard | |
45 | f0cbd3ec | bellard | #include <slirp.h> |
46 | f0cbd3ec | bellard | #include "ip_icmp.h" |
47 | f0cbd3ec | bellard | |
48 | 31a60e22 | blueswir1 | #ifdef LOG_ENABLED
|
49 | f0cbd3ec | bellard | struct udpstat udpstat;
|
50 | 31a60e22 | blueswir1 | #endif
|
51 | f0cbd3ec | bellard | |
52 | f0cbd3ec | bellard | struct socket udb;
|
53 | f0cbd3ec | bellard | |
54 | 9634d903 | blueswir1 | static u_int8_t udp_tos(struct socket *so); |
55 | 9634d903 | blueswir1 | static void udp_emu(struct socket *so, struct mbuf *m); |
56 | 9634d903 | blueswir1 | |
57 | f0cbd3ec | bellard | /*
|
58 | f0cbd3ec | bellard | * UDP protocol implementation.
|
59 | f0cbd3ec | bellard | * Per RFC 768, August, 1980.
|
60 | f0cbd3ec | bellard | */
|
61 | f0cbd3ec | bellard | #ifndef COMPAT_42
|
62 | 9634d903 | blueswir1 | #define UDPCKSUM 1 |
63 | f0cbd3ec | bellard | #else
|
64 | 9634d903 | blueswir1 | #define UDPCKSUM 0 /* XXX */ |
65 | f0cbd3ec | bellard | #endif
|
66 | f0cbd3ec | bellard | |
67 | f0cbd3ec | bellard | struct socket *udp_last_so = &udb;
|
68 | f0cbd3ec | bellard | |
69 | f0cbd3ec | bellard | void
|
70 | f0cbd3ec | bellard | udp_init() |
71 | f0cbd3ec | bellard | { |
72 | f0cbd3ec | bellard | udb.so_next = udb.so_prev = &udb; |
73 | f0cbd3ec | bellard | } |
74 | 5fafdf24 | ths | /* m->m_data points at ip packet header
|
75 | 5fafdf24 | ths | * m->m_len length ip packet
|
76 | f0cbd3ec | bellard | * ip->ip_len length data (IPDU)
|
77 | f0cbd3ec | bellard | */
|
78 | f0cbd3ec | bellard | void
|
79 | f0cbd3ec | bellard | udp_input(m, iphlen) |
80 | f0cbd3ec | bellard | register struct mbuf *m; |
81 | f0cbd3ec | bellard | int iphlen;
|
82 | f0cbd3ec | bellard | { |
83 | f0cbd3ec | bellard | register struct ip *ip; |
84 | f0cbd3ec | bellard | register struct udphdr *uh; |
85 | f0cbd3ec | bellard | /* struct mbuf *opts = 0;*/
|
86 | f0cbd3ec | bellard | int len;
|
87 | 5fafdf24 | ths | struct ip save_ip;
|
88 | f0cbd3ec | bellard | struct socket *so;
|
89 | 5fafdf24 | ths | |
90 | f0cbd3ec | bellard | DEBUG_CALL("udp_input");
|
91 | f0cbd3ec | bellard | DEBUG_ARG("m = %lx", (long)m); |
92 | f0cbd3ec | bellard | DEBUG_ARG("iphlen = %d", iphlen);
|
93 | 5fafdf24 | ths | |
94 | 31a60e22 | blueswir1 | STAT(udpstat.udps_ipackets++); |
95 | f0cbd3ec | bellard | |
96 | f0cbd3ec | bellard | /*
|
97 | f0cbd3ec | bellard | * Strip IP options, if any; should skip this,
|
98 | f0cbd3ec | bellard | * make available to user, and use on returned packets,
|
99 | f0cbd3ec | bellard | * but we don't yet have a way to check the checksum
|
100 | f0cbd3ec | bellard | * with options still present.
|
101 | f0cbd3ec | bellard | */
|
102 | f0cbd3ec | bellard | if(iphlen > sizeof(struct ip)) { |
103 | f0cbd3ec | bellard | ip_stripoptions(m, (struct mbuf *)0); |
104 | f0cbd3ec | bellard | iphlen = sizeof(struct ip); |
105 | f0cbd3ec | bellard | } |
106 | f0cbd3ec | bellard | |
107 | f0cbd3ec | bellard | /*
|
108 | f0cbd3ec | bellard | * Get IP and UDP header together in first mbuf.
|
109 | f0cbd3ec | bellard | */
|
110 | f0cbd3ec | bellard | ip = mtod(m, struct ip *);
|
111 | f0cbd3ec | bellard | uh = (struct udphdr *)((caddr_t)ip + iphlen);
|
112 | f0cbd3ec | bellard | |
113 | f0cbd3ec | bellard | /*
|
114 | f0cbd3ec | bellard | * Make mbuf data length reflect UDP length.
|
115 | f0cbd3ec | bellard | * If not enough data to reflect UDP length, drop.
|
116 | f0cbd3ec | bellard | */
|
117 | f0cbd3ec | bellard | len = ntohs((u_int16_t)uh->uh_ulen); |
118 | f0cbd3ec | bellard | |
119 | f0cbd3ec | bellard | if (ip->ip_len != len) {
|
120 | f0cbd3ec | bellard | if (len > ip->ip_len) {
|
121 | 31a60e22 | blueswir1 | STAT(udpstat.udps_badlen++); |
122 | f0cbd3ec | bellard | goto bad;
|
123 | f0cbd3ec | bellard | } |
124 | f0cbd3ec | bellard | m_adj(m, len - ip->ip_len); |
125 | f0cbd3ec | bellard | ip->ip_len = len; |
126 | f0cbd3ec | bellard | } |
127 | 5fafdf24 | ths | |
128 | f0cbd3ec | bellard | /*
|
129 | f0cbd3ec | bellard | * Save a copy of the IP header in case we want restore it
|
130 | f0cbd3ec | bellard | * for sending an ICMP error message in response.
|
131 | f0cbd3ec | bellard | */
|
132 | 5fafdf24 | ths | save_ip = *ip; |
133 | f0cbd3ec | bellard | save_ip.ip_len+= iphlen; /* tcp_input subtracts this */
|
134 | f0cbd3ec | bellard | |
135 | f0cbd3ec | bellard | /*
|
136 | f0cbd3ec | bellard | * Checksum extended UDP header and data.
|
137 | f0cbd3ec | bellard | */
|
138 | 9634d903 | blueswir1 | if (UDPCKSUM && uh->uh_sum) {
|
139 | f0cbd3ec | bellard | ((struct ipovly *)ip)->ih_next = 0; |
140 | f0cbd3ec | bellard | ((struct ipovly *)ip)->ih_prev = 0; |
141 | f0cbd3ec | bellard | ((struct ipovly *)ip)->ih_x1 = 0; |
142 | f0cbd3ec | bellard | ((struct ipovly *)ip)->ih_len = uh->uh_ulen;
|
143 | f0cbd3ec | bellard | /* keep uh_sum for ICMP reply
|
144 | 5fafdf24 | ths | * uh->uh_sum = cksum(m, len + sizeof (struct ip));
|
145 | 5fafdf24 | ths | * if (uh->uh_sum) {
|
146 | f0cbd3ec | bellard | */
|
147 | f0cbd3ec | bellard | if(cksum(m, len + sizeof(struct ip))) { |
148 | 31a60e22 | blueswir1 | STAT(udpstat.udps_badsum++); |
149 | f0cbd3ec | bellard | goto bad;
|
150 | f0cbd3ec | bellard | } |
151 | f0cbd3ec | bellard | } |
152 | f0cbd3ec | bellard | |
153 | f0cbd3ec | bellard | /*
|
154 | f0cbd3ec | bellard | * handle DHCP/BOOTP
|
155 | f0cbd3ec | bellard | */
|
156 | f0cbd3ec | bellard | if (ntohs(uh->uh_dport) == BOOTP_SERVER) {
|
157 | f0cbd3ec | bellard | bootp_input(m); |
158 | f0cbd3ec | bellard | goto bad;
|
159 | f0cbd3ec | bellard | } |
160 | f0cbd3ec | bellard | |
161 | c7f74643 | bellard | /*
|
162 | c7f74643 | bellard | * handle TFTP
|
163 | c7f74643 | bellard | */
|
164 | c7f74643 | bellard | if (ntohs(uh->uh_dport) == TFTP_SERVER) {
|
165 | c7f74643 | bellard | tftp_input(m); |
166 | c7f74643 | bellard | goto bad;
|
167 | c7f74643 | bellard | } |
168 | c7f74643 | bellard | |
169 | f0cbd3ec | bellard | /*
|
170 | f0cbd3ec | bellard | * Locate pcb for datagram.
|
171 | f0cbd3ec | bellard | */
|
172 | f0cbd3ec | bellard | so = udp_last_so; |
173 | f0cbd3ec | bellard | if (so->so_lport != uh->uh_sport ||
|
174 | f0cbd3ec | bellard | so->so_laddr.s_addr != ip->ip_src.s_addr) { |
175 | f0cbd3ec | bellard | struct socket *tmp;
|
176 | 3b46e624 | ths | |
177 | f0cbd3ec | bellard | for (tmp = udb.so_next; tmp != &udb; tmp = tmp->so_next) {
|
178 | f0cbd3ec | bellard | if (tmp->so_lport == uh->uh_sport &&
|
179 | f0cbd3ec | bellard | tmp->so_laddr.s_addr == ip->ip_src.s_addr) { |
180 | f0cbd3ec | bellard | tmp->so_faddr.s_addr = ip->ip_dst.s_addr; |
181 | f0cbd3ec | bellard | tmp->so_fport = uh->uh_dport; |
182 | f0cbd3ec | bellard | so = tmp; |
183 | f0cbd3ec | bellard | break;
|
184 | f0cbd3ec | bellard | } |
185 | f0cbd3ec | bellard | } |
186 | f0cbd3ec | bellard | if (tmp == &udb) {
|
187 | f0cbd3ec | bellard | so = NULL;
|
188 | f0cbd3ec | bellard | } else {
|
189 | 31a60e22 | blueswir1 | STAT(udpstat.udpps_pcbcachemiss++); |
190 | f0cbd3ec | bellard | udp_last_so = so; |
191 | f0cbd3ec | bellard | } |
192 | f0cbd3ec | bellard | } |
193 | 5fafdf24 | ths | |
194 | f0cbd3ec | bellard | if (so == NULL) { |
195 | f0cbd3ec | bellard | /*
|
196 | f0cbd3ec | bellard | * If there's no socket for this packet,
|
197 | f0cbd3ec | bellard | * create one
|
198 | f0cbd3ec | bellard | */
|
199 | f0cbd3ec | bellard | if ((so = socreate()) == NULL) goto bad; |
200 | f0cbd3ec | bellard | if(udp_attach(so) == -1) { |
201 | 5fafdf24 | ths | DEBUG_MISC((dfd," udp_attach errno = %d-%s\n",
|
202 | f0cbd3ec | bellard | errno,strerror(errno))); |
203 | f0cbd3ec | bellard | sofree(so); |
204 | f0cbd3ec | bellard | goto bad;
|
205 | f0cbd3ec | bellard | } |
206 | 3b46e624 | ths | |
207 | f0cbd3ec | bellard | /*
|
208 | f0cbd3ec | bellard | * Setup fields
|
209 | f0cbd3ec | bellard | */
|
210 | f0cbd3ec | bellard | /* udp_last_so = so; */
|
211 | f0cbd3ec | bellard | so->so_laddr = ip->ip_src; |
212 | f0cbd3ec | bellard | so->so_lport = uh->uh_sport; |
213 | 3b46e624 | ths | |
214 | f0cbd3ec | bellard | if ((so->so_iptos = udp_tos(so)) == 0) |
215 | f0cbd3ec | bellard | so->so_iptos = ip->ip_tos; |
216 | 3b46e624 | ths | |
217 | f0cbd3ec | bellard | /*
|
218 | f0cbd3ec | bellard | * XXXXX Here, check if it's in udpexec_list,
|
219 | f0cbd3ec | bellard | * and if it is, do the fork_exec() etc.
|
220 | f0cbd3ec | bellard | */
|
221 | f0cbd3ec | bellard | } |
222 | f0cbd3ec | bellard | |
223 | 54fd9cdf | ths | so->so_faddr = ip->ip_dst; /* XXX */
|
224 | 54fd9cdf | ths | so->so_fport = uh->uh_dport; /* XXX */
|
225 | 54fd9cdf | ths | |
226 | f0cbd3ec | bellard | iphlen += sizeof(struct udphdr); |
227 | f0cbd3ec | bellard | m->m_len -= iphlen; |
228 | f0cbd3ec | bellard | m->m_data += iphlen; |
229 | f0cbd3ec | bellard | |
230 | f0cbd3ec | bellard | /*
|
231 | f0cbd3ec | bellard | * Now we sendto() the packet.
|
232 | f0cbd3ec | bellard | */
|
233 | f0cbd3ec | bellard | if (so->so_emu)
|
234 | f0cbd3ec | bellard | udp_emu(so, m); |
235 | f0cbd3ec | bellard | |
236 | f0cbd3ec | bellard | if(sosendto(so,m) == -1) { |
237 | f0cbd3ec | bellard | m->m_len += iphlen; |
238 | f0cbd3ec | bellard | m->m_data -= iphlen; |
239 | f0cbd3ec | bellard | *ip=save_ip; |
240 | f0cbd3ec | bellard | DEBUG_MISC((dfd,"udp tx errno = %d-%s\n",errno,strerror(errno)));
|
241 | 3b46e624 | ths | icmp_error(m, ICMP_UNREACH,ICMP_UNREACH_NET, 0,strerror(errno));
|
242 | f0cbd3ec | bellard | } |
243 | f0cbd3ec | bellard | |
244 | f0cbd3ec | bellard | m_free(so->so_m); /* used for ICMP if error on sorecvfrom */
|
245 | f0cbd3ec | bellard | |
246 | f0cbd3ec | bellard | /* restore the orig mbuf packet */
|
247 | f0cbd3ec | bellard | m->m_len += iphlen; |
248 | f0cbd3ec | bellard | m->m_data -= iphlen; |
249 | f0cbd3ec | bellard | *ip=save_ip; |
250 | f0cbd3ec | bellard | so->so_m=m; /* ICMP backup */
|
251 | f0cbd3ec | bellard | |
252 | f0cbd3ec | bellard | return;
|
253 | f0cbd3ec | bellard | bad:
|
254 | f0cbd3ec | bellard | m_freem(m); |
255 | f0cbd3ec | bellard | /* if (opts) m_freem(opts); */
|
256 | f0cbd3ec | bellard | return;
|
257 | f0cbd3ec | bellard | } |
258 | f0cbd3ec | bellard | |
259 | 5fafdf24 | ths | int udp_output2(struct socket *so, struct mbuf *m, |
260 | f0cbd3ec | bellard | struct sockaddr_in *saddr, struct sockaddr_in *daddr, |
261 | f0cbd3ec | bellard | int iptos)
|
262 | f0cbd3ec | bellard | { |
263 | f0cbd3ec | bellard | register struct udpiphdr *ui; |
264 | f0cbd3ec | bellard | int error = 0; |
265 | f0cbd3ec | bellard | |
266 | f0cbd3ec | bellard | DEBUG_CALL("udp_output");
|
267 | f0cbd3ec | bellard | DEBUG_ARG("so = %lx", (long)so); |
268 | f0cbd3ec | bellard | DEBUG_ARG("m = %lx", (long)m); |
269 | f0cbd3ec | bellard | DEBUG_ARG("saddr = %lx", (long)saddr->sin_addr.s_addr); |
270 | f0cbd3ec | bellard | DEBUG_ARG("daddr = %lx", (long)daddr->sin_addr.s_addr); |
271 | f0cbd3ec | bellard | |
272 | f0cbd3ec | bellard | /*
|
273 | f0cbd3ec | bellard | * Adjust for header
|
274 | f0cbd3ec | bellard | */
|
275 | f0cbd3ec | bellard | m->m_data -= sizeof(struct udpiphdr); |
276 | f0cbd3ec | bellard | m->m_len += sizeof(struct udpiphdr); |
277 | 5fafdf24 | ths | |
278 | f0cbd3ec | bellard | /*
|
279 | f0cbd3ec | bellard | * Fill in mbuf with extended UDP header
|
280 | f0cbd3ec | bellard | * and addresses and length put into network format.
|
281 | f0cbd3ec | bellard | */
|
282 | f0cbd3ec | bellard | ui = mtod(m, struct udpiphdr *);
|
283 | f0cbd3ec | bellard | ui->ui_next = ui->ui_prev = 0;
|
284 | f0cbd3ec | bellard | ui->ui_x1 = 0;
|
285 | f0cbd3ec | bellard | ui->ui_pr = IPPROTO_UDP; |
286 | f0cbd3ec | bellard | ui->ui_len = htons(m->m_len - sizeof(struct ip)); /* + sizeof (struct udphdr)); */ |
287 | f0cbd3ec | bellard | /* XXXXX Check for from-one-location sockets, or from-any-location sockets */
|
288 | f0cbd3ec | bellard | ui->ui_src = saddr->sin_addr; |
289 | f0cbd3ec | bellard | ui->ui_dst = daddr->sin_addr; |
290 | f0cbd3ec | bellard | ui->ui_sport = saddr->sin_port; |
291 | f0cbd3ec | bellard | ui->ui_dport = daddr->sin_port; |
292 | f0cbd3ec | bellard | ui->ui_ulen = ui->ui_len; |
293 | f0cbd3ec | bellard | |
294 | f0cbd3ec | bellard | /*
|
295 | f0cbd3ec | bellard | * Stuff checksum and output datagram.
|
296 | f0cbd3ec | bellard | */
|
297 | f0cbd3ec | bellard | ui->ui_sum = 0;
|
298 | 9634d903 | blueswir1 | if (UDPCKSUM) {
|
299 | f0cbd3ec | bellard | if ((ui->ui_sum = cksum(m, /* sizeof (struct udpiphdr) + */ m->m_len)) == 0) |
300 | f0cbd3ec | bellard | ui->ui_sum = 0xffff;
|
301 | f0cbd3ec | bellard | } |
302 | f0cbd3ec | bellard | ((struct ip *)ui)->ip_len = m->m_len;
|
303 | f0cbd3ec | bellard | |
304 | 9634d903 | blueswir1 | ((struct ip *)ui)->ip_ttl = IPDEFTTL;
|
305 | f0cbd3ec | bellard | ((struct ip *)ui)->ip_tos = iptos;
|
306 | 5fafdf24 | ths | |
307 | 31a60e22 | blueswir1 | STAT(udpstat.udps_opackets++); |
308 | 5fafdf24 | ths | |
309 | f0cbd3ec | bellard | error = ip_output(so, m); |
310 | 5fafdf24 | ths | |
311 | f0cbd3ec | bellard | return (error);
|
312 | f0cbd3ec | bellard | } |
313 | f0cbd3ec | bellard | |
314 | 5fafdf24 | ths | int udp_output(struct socket *so, struct mbuf *m, |
315 | f0cbd3ec | bellard | struct sockaddr_in *addr)
|
316 | f0cbd3ec | bellard | |
317 | f0cbd3ec | bellard | { |
318 | f0cbd3ec | bellard | struct sockaddr_in saddr, daddr;
|
319 | f0cbd3ec | bellard | |
320 | f0cbd3ec | bellard | saddr = *addr; |
321 | f3ae0704 | balrog | if ((so->so_faddr.s_addr & htonl(0xffffff00)) == special_addr.s_addr) { |
322 | c904d61f | bellard | if ((so->so_faddr.s_addr & htonl(0x000000ff)) == htonl(0xff)) |
323 | c904d61f | bellard | saddr.sin_addr.s_addr = alias_addr.s_addr; |
324 | f3ae0704 | balrog | else if (addr->sin_addr.s_addr == loopback_addr.s_addr || |
325 | f3ae0704 | balrog | ((so->so_faddr.s_addr & htonl(CTL_DNS)) == htonl(CTL_DNS))) |
326 | f3ae0704 | balrog | saddr.sin_addr.s_addr = so->so_faddr.s_addr; |
327 | c904d61f | bellard | } |
328 | f0cbd3ec | bellard | daddr.sin_addr = so->so_laddr; |
329 | f0cbd3ec | bellard | daddr.sin_port = so->so_lport; |
330 | 3b46e624 | ths | |
331 | f0cbd3ec | bellard | return udp_output2(so, m, &saddr, &daddr, so->so_iptos);
|
332 | f0cbd3ec | bellard | } |
333 | f0cbd3ec | bellard | |
334 | f0cbd3ec | bellard | int
|
335 | f0cbd3ec | bellard | udp_attach(so) |
336 | f0cbd3ec | bellard | struct socket *so;
|
337 | f0cbd3ec | bellard | { |
338 | f0cbd3ec | bellard | struct sockaddr_in addr;
|
339 | 5fafdf24 | ths | |
340 | f0cbd3ec | bellard | if((so->s = socket(AF_INET,SOCK_DGRAM,0)) != -1) { |
341 | f0cbd3ec | bellard | /*
|
342 | f0cbd3ec | bellard | * Here, we bind() the socket. Although not really needed
|
343 | f0cbd3ec | bellard | * (sendto() on an unbound socket will bind it), it's done
|
344 | f0cbd3ec | bellard | * here so that emulation of ytalk etc. don't have to do it
|
345 | f0cbd3ec | bellard | */
|
346 | f0cbd3ec | bellard | addr.sin_family = AF_INET; |
347 | f0cbd3ec | bellard | addr.sin_port = 0;
|
348 | f0cbd3ec | bellard | addr.sin_addr.s_addr = INADDR_ANY; |
349 | f0cbd3ec | bellard | if(bind(so->s, (struct sockaddr *)&addr, sizeof(addr))<0) { |
350 | f0cbd3ec | bellard | int lasterrno=errno;
|
351 | 379ff53d | bellard | closesocket(so->s); |
352 | f0cbd3ec | bellard | so->s=-1;
|
353 | 02d2c54c | bellard | #ifdef _WIN32
|
354 | 02d2c54c | bellard | WSASetLastError(lasterrno); |
355 | 02d2c54c | bellard | #else
|
356 | f0cbd3ec | bellard | errno=lasterrno; |
357 | 02d2c54c | bellard | #endif
|
358 | f0cbd3ec | bellard | } else {
|
359 | f0cbd3ec | bellard | /* success, insert in queue */
|
360 | f0cbd3ec | bellard | so->so_expire = curtime + SO_EXPIRE; |
361 | f0cbd3ec | bellard | insque(so,&udb); |
362 | f0cbd3ec | bellard | } |
363 | f0cbd3ec | bellard | } |
364 | f0cbd3ec | bellard | return(so->s);
|
365 | f0cbd3ec | bellard | } |
366 | f0cbd3ec | bellard | |
367 | f0cbd3ec | bellard | void
|
368 | f0cbd3ec | bellard | udp_detach(so) |
369 | f0cbd3ec | bellard | struct socket *so;
|
370 | f0cbd3ec | bellard | { |
371 | 379ff53d | bellard | closesocket(so->s); |
372 | f0cbd3ec | bellard | /* if (so->so_m) m_free(so->so_m); done by sofree */
|
373 | f0cbd3ec | bellard | |
374 | f0cbd3ec | bellard | sofree(so); |
375 | f0cbd3ec | bellard | } |
376 | f0cbd3ec | bellard | |
377 | 9634d903 | blueswir1 | static const struct tos_t udptos[] = { |
378 | f0cbd3ec | bellard | {0, 53, IPTOS_LOWDELAY, 0}, /* DNS */ |
379 | f0cbd3ec | bellard | {517, 517, IPTOS_LOWDELAY, EMU_TALK}, /* talk */ |
380 | f0cbd3ec | bellard | {518, 518, IPTOS_LOWDELAY, EMU_NTALK}, /* ntalk */ |
381 | f0cbd3ec | bellard | {0, 7648, IPTOS_LOWDELAY, EMU_CUSEEME}, /* Cu-Seeme */ |
382 | f0cbd3ec | bellard | {0, 0, 0, 0} |
383 | f0cbd3ec | bellard | }; |
384 | f0cbd3ec | bellard | |
385 | 9634d903 | blueswir1 | static u_int8_t
|
386 | 9634d903 | blueswir1 | udp_tos(struct socket *so)
|
387 | f0cbd3ec | bellard | { |
388 | f0cbd3ec | bellard | int i = 0; |
389 | 5fafdf24 | ths | |
390 | f0cbd3ec | bellard | while(udptos[i].tos) {
|
391 | f0cbd3ec | bellard | if ((udptos[i].fport && ntohs(so->so_fport) == udptos[i].fport) ||
|
392 | f0cbd3ec | bellard | (udptos[i].lport && ntohs(so->so_lport) == udptos[i].lport)) { |
393 | f0cbd3ec | bellard | so->so_emu = udptos[i].emu; |
394 | f0cbd3ec | bellard | return udptos[i].tos;
|
395 | f0cbd3ec | bellard | } |
396 | f0cbd3ec | bellard | i++; |
397 | f0cbd3ec | bellard | } |
398 | 5fafdf24 | ths | |
399 | f0cbd3ec | bellard | return 0; |
400 | f0cbd3ec | bellard | } |
401 | f0cbd3ec | bellard | |
402 | f0cbd3ec | bellard | #ifdef EMULATE_TALK
|
403 | f0cbd3ec | bellard | #include "talkd.h" |
404 | f0cbd3ec | bellard | #endif
|
405 | f0cbd3ec | bellard | |
406 | f0cbd3ec | bellard | /*
|
407 | f0cbd3ec | bellard | * Here, talk/ytalk/ntalk requests must be emulated
|
408 | f0cbd3ec | bellard | */
|
409 | 9634d903 | blueswir1 | static void |
410 | 9634d903 | blueswir1 | udp_emu(struct socket *so, struct mbuf *m) |
411 | f0cbd3ec | bellard | { |
412 | f0cbd3ec | bellard | struct sockaddr_in addr;
|
413 | f0cbd3ec | bellard | int addrlen = sizeof(addr); |
414 | f0cbd3ec | bellard | #ifdef EMULATE_TALK
|
415 | f0cbd3ec | bellard | CTL_MSG_OLD *omsg; |
416 | f0cbd3ec | bellard | CTL_MSG *nmsg; |
417 | f0cbd3ec | bellard | char buff[sizeof(CTL_MSG)]; |
418 | f0cbd3ec | bellard | u_char type; |
419 | 5fafdf24 | ths | |
420 | f0cbd3ec | bellard | struct talk_request {
|
421 | f0cbd3ec | bellard | struct talk_request *next;
|
422 | f0cbd3ec | bellard | struct socket *udp_so;
|
423 | f0cbd3ec | bellard | struct socket *tcp_so;
|
424 | f0cbd3ec | bellard | } *req; |
425 | 5fafdf24 | ths | |
426 | 5fafdf24 | ths | static struct talk_request *req_tbl = 0; |
427 | 5fafdf24 | ths | |
428 | f0cbd3ec | bellard | #endif
|
429 | 5fafdf24 | ths | |
430 | f0cbd3ec | bellard | struct cu_header {
|
431 | 101c5935 | bellard | uint16_t d_family; // destination family
|
432 | 101c5935 | bellard | uint16_t d_port; // destination port
|
433 | 101c5935 | bellard | uint32_t d_addr; // destination address
|
434 | 101c5935 | bellard | uint16_t s_family; // source family
|
435 | 101c5935 | bellard | uint16_t s_port; // source port
|
436 | 51a36cb2 | bellard | uint32_t so_addr; // source address
|
437 | 101c5935 | bellard | uint32_t seqn; // sequence number
|
438 | 101c5935 | bellard | uint16_t message; // message
|
439 | 101c5935 | bellard | uint16_t data_type; // data type
|
440 | 101c5935 | bellard | uint16_t pkt_len; // packet length
|
441 | f0cbd3ec | bellard | } *cu_head; |
442 | f0cbd3ec | bellard | |
443 | f0cbd3ec | bellard | switch(so->so_emu) {
|
444 | f0cbd3ec | bellard | |
445 | f0cbd3ec | bellard | #ifdef EMULATE_TALK
|
446 | f0cbd3ec | bellard | case EMU_TALK:
|
447 | f0cbd3ec | bellard | case EMU_NTALK:
|
448 | f0cbd3ec | bellard | /*
|
449 | f0cbd3ec | bellard | * Talk emulation. We always change the ctl_addr to get
|
450 | f0cbd3ec | bellard | * some answers from the daemon. When an ANNOUNCE comes,
|
451 | f0cbd3ec | bellard | * we send LEAVE_INVITE to the local daemons. Also when a
|
452 | f0cbd3ec | bellard | * DELETE comes, we send copies to the local daemons.
|
453 | f0cbd3ec | bellard | */
|
454 | f0cbd3ec | bellard | if (getsockname(so->s, (struct sockaddr *)&addr, &addrlen) < 0) |
455 | f0cbd3ec | bellard | return;
|
456 | 3b46e624 | ths | |
457 | f0cbd3ec | bellard | #define IS_OLD (so->so_emu == EMU_TALK)
|
458 | f0cbd3ec | bellard | |
459 | f0cbd3ec | bellard | #define COPY_MSG(dest, src) { dest->type = src->type; \
|
460 | f0cbd3ec | bellard | dest->id_num = src->id_num; \ |
461 | f0cbd3ec | bellard | dest->pid = src->pid; \ |
462 | f0cbd3ec | bellard | dest->addr = src->addr; \ |
463 | f0cbd3ec | bellard | dest->ctl_addr = src->ctl_addr; \ |
464 | f0cbd3ec | bellard | memcpy(&dest->l_name, &src->l_name, NAME_SIZE_OLD); \ |
465 | f0cbd3ec | bellard | memcpy(&dest->r_name, &src->r_name, NAME_SIZE_OLD); \ |
466 | f0cbd3ec | bellard | memcpy(&dest->r_tty, &src->r_tty, TTY_SIZE); } |
467 | f0cbd3ec | bellard | |
468 | f0cbd3ec | bellard | #define OTOSIN(ptr, field) ((struct sockaddr_in *)&ptr->field) |
469 | f0cbd3ec | bellard | /* old_sockaddr to sockaddr_in */
|
470 | f0cbd3ec | bellard | |
471 | f0cbd3ec | bellard | |
472 | f0cbd3ec | bellard | if (IS_OLD) { /* old talk */ |
473 | f0cbd3ec | bellard | omsg = mtod(m, CTL_MSG_OLD*); |
474 | f0cbd3ec | bellard | nmsg = (CTL_MSG *) buff; |
475 | f0cbd3ec | bellard | type = omsg->type; |
476 | f0cbd3ec | bellard | OTOSIN(omsg, ctl_addr)->sin_port = addr.sin_port; |
477 | f0cbd3ec | bellard | OTOSIN(omsg, ctl_addr)->sin_addr = our_addr; |
478 | f0cbd3ec | bellard | strncpy(omsg->l_name, getlogin(), NAME_SIZE_OLD); |
479 | 5fafdf24 | ths | } else { /* new talk */ |
480 | f0cbd3ec | bellard | omsg = (CTL_MSG_OLD *) buff; |
481 | f0cbd3ec | bellard | nmsg = mtod(m, CTL_MSG *); |
482 | f0cbd3ec | bellard | type = nmsg->type; |
483 | f0cbd3ec | bellard | OTOSIN(nmsg, ctl_addr)->sin_port = addr.sin_port; |
484 | f0cbd3ec | bellard | OTOSIN(nmsg, ctl_addr)->sin_addr = our_addr; |
485 | f0cbd3ec | bellard | strncpy(nmsg->l_name, getlogin(), NAME_SIZE_OLD); |
486 | f0cbd3ec | bellard | } |
487 | 3b46e624 | ths | |
488 | 5fafdf24 | ths | if (type == LOOK_UP)
|
489 | f0cbd3ec | bellard | return; /* for LOOK_UP this is enough */ |
490 | 3b46e624 | ths | |
491 | f0cbd3ec | bellard | if (IS_OLD) { /* make a copy of the message */ |
492 | f0cbd3ec | bellard | COPY_MSG(nmsg, omsg); |
493 | f0cbd3ec | bellard | nmsg->vers = 1;
|
494 | f0cbd3ec | bellard | nmsg->answer = 0;
|
495 | f0cbd3ec | bellard | } else
|
496 | f0cbd3ec | bellard | COPY_MSG(omsg, nmsg); |
497 | f0cbd3ec | bellard | |
498 | f0cbd3ec | bellard | /*
|
499 | f0cbd3ec | bellard | * If if is an ANNOUNCE message, we go through the
|
500 | f0cbd3ec | bellard | * request table to see if a tcp port has already
|
501 | f0cbd3ec | bellard | * been redirected for this socket. If not, we solisten()
|
502 | f0cbd3ec | bellard | * a new socket and add this entry to the table.
|
503 | f0cbd3ec | bellard | * The port number of the tcp socket and our IP
|
504 | f0cbd3ec | bellard | * are put to the addr field of the message structures.
|
505 | f0cbd3ec | bellard | * Then a LEAVE_INVITE is sent to both local daemon
|
506 | f0cbd3ec | bellard | * ports, 517 and 518. This is why we have two copies
|
507 | f0cbd3ec | bellard | * of the message, one in old talk and one in new talk
|
508 | f0cbd3ec | bellard | * format.
|
509 | 5fafdf24 | ths | */
|
510 | f0cbd3ec | bellard | |
511 | f0cbd3ec | bellard | if (type == ANNOUNCE) {
|
512 | f0cbd3ec | bellard | int s;
|
513 | f0cbd3ec | bellard | u_short temp_port; |
514 | 3b46e624 | ths | |
515 | f0cbd3ec | bellard | for(req = req_tbl; req; req = req->next)
|
516 | f0cbd3ec | bellard | if (so == req->udp_so)
|
517 | f0cbd3ec | bellard | break; /* found it */ |
518 | 3b46e624 | ths | |
519 | f0cbd3ec | bellard | if (!req) { /* no entry for so, create new */ |
520 | f0cbd3ec | bellard | req = (struct talk_request *)
|
521 | f0cbd3ec | bellard | malloc(sizeof(struct talk_request)); |
522 | f0cbd3ec | bellard | req->udp_so = so; |
523 | 3b46e624 | ths | req->tcp_so = solisten(0,
|
524 | 5fafdf24 | ths | OTOSIN(omsg, addr)->sin_addr.s_addr, |
525 | f0cbd3ec | bellard | OTOSIN(omsg, addr)->sin_port, |
526 | f0cbd3ec | bellard | SS_FACCEPTONCE); |
527 | f0cbd3ec | bellard | req->next = req_tbl; |
528 | f0cbd3ec | bellard | req_tbl = req; |
529 | 3b46e624 | ths | } |
530 | 3b46e624 | ths | |
531 | f0cbd3ec | bellard | /* replace port number in addr field */
|
532 | f0cbd3ec | bellard | addrlen = sizeof(addr);
|
533 | 5fafdf24 | ths | getsockname(req->tcp_so->s, |
534 | f0cbd3ec | bellard | (struct sockaddr *) &addr,
|
535 | 3b46e624 | ths | &addrlen); |
536 | f0cbd3ec | bellard | OTOSIN(omsg, addr)->sin_port = addr.sin_port; |
537 | f0cbd3ec | bellard | OTOSIN(omsg, addr)->sin_addr = our_addr; |
538 | f0cbd3ec | bellard | OTOSIN(nmsg, addr)->sin_port = addr.sin_port; |
539 | 3b46e624 | ths | OTOSIN(nmsg, addr)->sin_addr = our_addr; |
540 | 3b46e624 | ths | |
541 | f0cbd3ec | bellard | /* send LEAVE_INVITEs */
|
542 | f0cbd3ec | bellard | temp_port = OTOSIN(omsg, ctl_addr)->sin_port; |
543 | f0cbd3ec | bellard | OTOSIN(omsg, ctl_addr)->sin_port = 0;
|
544 | f0cbd3ec | bellard | OTOSIN(nmsg, ctl_addr)->sin_port = 0;
|
545 | 3b46e624 | ths | omsg->type = nmsg->type = LEAVE_INVITE; |
546 | 3b46e624 | ths | |
547 | f0cbd3ec | bellard | s = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP); |
548 | f0cbd3ec | bellard | addr.sin_addr = our_addr; |
549 | f0cbd3ec | bellard | addr.sin_family = AF_INET; |
550 | f0cbd3ec | bellard | addr.sin_port = htons(517);
|
551 | 5fafdf24 | ths | sendto(s, (char *)omsg, sizeof(*omsg), 0, |
552 | f0cbd3ec | bellard | (struct sockaddr *)&addr, sizeof(addr)); |
553 | f0cbd3ec | bellard | addr.sin_port = htons(518);
|
554 | f0cbd3ec | bellard | sendto(s, (char *)nmsg, sizeof(*nmsg), 0, |
555 | f0cbd3ec | bellard | (struct sockaddr *) &addr, sizeof(addr)); |
556 | 379ff53d | bellard | closesocket(s) ; |
557 | f0cbd3ec | bellard | |
558 | 5fafdf24 | ths | omsg->type = nmsg->type = ANNOUNCE; |
559 | f0cbd3ec | bellard | OTOSIN(omsg, ctl_addr)->sin_port = temp_port; |
560 | f0cbd3ec | bellard | OTOSIN(nmsg, ctl_addr)->sin_port = temp_port; |
561 | f0cbd3ec | bellard | } |
562 | 3b46e624 | ths | |
563 | 5fafdf24 | ths | /*
|
564 | f0cbd3ec | bellard | * If it is a DELETE message, we send a copy to the
|
565 | f0cbd3ec | bellard | * local daemons. Then we delete the entry corresponding
|
566 | f0cbd3ec | bellard | * to our socket from the request table.
|
567 | f0cbd3ec | bellard | */
|
568 | 3b46e624 | ths | |
569 | f0cbd3ec | bellard | if (type == DELETE) {
|
570 | f0cbd3ec | bellard | struct talk_request *temp_req, *req_next;
|
571 | f0cbd3ec | bellard | int s;
|
572 | f0cbd3ec | bellard | u_short temp_port; |
573 | 3b46e624 | ths | |
574 | f0cbd3ec | bellard | temp_port = OTOSIN(omsg, ctl_addr)->sin_port; |
575 | f0cbd3ec | bellard | OTOSIN(omsg, ctl_addr)->sin_port = 0;
|
576 | f0cbd3ec | bellard | OTOSIN(nmsg, ctl_addr)->sin_port = 0;
|
577 | 3b46e624 | ths | |
578 | f0cbd3ec | bellard | s = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP); |
579 | f0cbd3ec | bellard | addr.sin_addr = our_addr; |
580 | f0cbd3ec | bellard | addr.sin_family = AF_INET; |
581 | f0cbd3ec | bellard | addr.sin_port = htons(517);
|
582 | f0cbd3ec | bellard | sendto(s, (char *)omsg, sizeof(*omsg), 0, |
583 | f0cbd3ec | bellard | (struct sockaddr *)&addr, sizeof(addr)); |
584 | f0cbd3ec | bellard | addr.sin_port = htons(518);
|
585 | f0cbd3ec | bellard | sendto(s, (char *)nmsg, sizeof(*nmsg), 0, |
586 | f0cbd3ec | bellard | (struct sockaddr *)&addr, sizeof(addr)); |
587 | 379ff53d | bellard | closesocket(s); |
588 | 3b46e624 | ths | |
589 | f0cbd3ec | bellard | OTOSIN(omsg, ctl_addr)->sin_port = temp_port; |
590 | f0cbd3ec | bellard | OTOSIN(nmsg, ctl_addr)->sin_port = temp_port; |
591 | f0cbd3ec | bellard | |
592 | f0cbd3ec | bellard | /* delete table entry */
|
593 | f0cbd3ec | bellard | if (so == req_tbl->udp_so) {
|
594 | f0cbd3ec | bellard | temp_req = req_tbl; |
595 | f0cbd3ec | bellard | req_tbl = req_tbl->next; |
596 | f0cbd3ec | bellard | free(temp_req); |
597 | f0cbd3ec | bellard | } else {
|
598 | f0cbd3ec | bellard | temp_req = req_tbl; |
599 | f0cbd3ec | bellard | for(req = req_tbl->next; req; req = req_next) {
|
600 | f0cbd3ec | bellard | req_next = req->next; |
601 | f0cbd3ec | bellard | if (so == req->udp_so) {
|
602 | f0cbd3ec | bellard | temp_req->next = req_next; |
603 | f0cbd3ec | bellard | free(req); |
604 | f0cbd3ec | bellard | break;
|
605 | f0cbd3ec | bellard | } else {
|
606 | f0cbd3ec | bellard | temp_req = req; |
607 | f0cbd3ec | bellard | } |
608 | f0cbd3ec | bellard | } |
609 | f0cbd3ec | bellard | } |
610 | f0cbd3ec | bellard | } |
611 | 3b46e624 | ths | |
612 | 3b46e624 | ths | return;
|
613 | f0cbd3ec | bellard | #endif
|
614 | 3b46e624 | ths | |
615 | 5fafdf24 | ths | case EMU_CUSEEME:
|
616 | 5fafdf24 | ths | |
617 | f0cbd3ec | bellard | /*
|
618 | f0cbd3ec | bellard | * Cu-SeeMe emulation.
|
619 | f0cbd3ec | bellard | * Hopefully the packet is more that 16 bytes long. We don't
|
620 | f0cbd3ec | bellard | * do any other tests, just replace the address and port
|
621 | f0cbd3ec | bellard | * fields.
|
622 | 5fafdf24 | ths | */
|
623 | f0cbd3ec | bellard | if (m->m_len >= sizeof (*cu_head)) { |
624 | f0cbd3ec | bellard | if (getsockname(so->s, (struct sockaddr *)&addr, &addrlen) < 0) |
625 | f0cbd3ec | bellard | return;
|
626 | f0cbd3ec | bellard | cu_head = mtod(m, struct cu_header *);
|
627 | 101c5935 | bellard | cu_head->s_port = addr.sin_port; |
628 | 51a36cb2 | bellard | cu_head->so_addr = our_addr.s_addr; |
629 | f0cbd3ec | bellard | } |
630 | 3b46e624 | ths | |
631 | f0cbd3ec | bellard | return;
|
632 | f0cbd3ec | bellard | } |
633 | f0cbd3ec | bellard | } |
634 | f0cbd3ec | bellard | |
635 | f0cbd3ec | bellard | struct socket *
|
636 | f0cbd3ec | bellard | udp_listen(port, laddr, lport, flags) |
637 | f0cbd3ec | bellard | u_int port; |
638 | f0cbd3ec | bellard | u_int32_t laddr; |
639 | f0cbd3ec | bellard | u_int lport; |
640 | f0cbd3ec | bellard | int flags;
|
641 | f0cbd3ec | bellard | { |
642 | f0cbd3ec | bellard | struct sockaddr_in addr;
|
643 | f0cbd3ec | bellard | struct socket *so;
|
644 | f0cbd3ec | bellard | int addrlen = sizeof(struct sockaddr_in), opt = 1; |
645 | 5fafdf24 | ths | |
646 | f0cbd3ec | bellard | if ((so = socreate()) == NULL) { |
647 | f0cbd3ec | bellard | free(so); |
648 | f0cbd3ec | bellard | return NULL; |
649 | f0cbd3ec | bellard | } |
650 | f0cbd3ec | bellard | so->s = socket(AF_INET,SOCK_DGRAM,0);
|
651 | f0cbd3ec | bellard | so->so_expire = curtime + SO_EXPIRE; |
652 | f0cbd3ec | bellard | insque(so,&udb); |
653 | f0cbd3ec | bellard | |
654 | f0cbd3ec | bellard | addr.sin_family = AF_INET; |
655 | f0cbd3ec | bellard | addr.sin_addr.s_addr = INADDR_ANY; |
656 | f0cbd3ec | bellard | addr.sin_port = port; |
657 | f0cbd3ec | bellard | |
658 | f0cbd3ec | bellard | if (bind(so->s,(struct sockaddr *)&addr, addrlen) < 0) { |
659 | f0cbd3ec | bellard | udp_detach(so); |
660 | f0cbd3ec | bellard | return NULL; |
661 | f0cbd3ec | bellard | } |
662 | f0cbd3ec | bellard | setsockopt(so->s,SOL_SOCKET,SO_REUSEADDR,(char *)&opt,sizeof(int)); |
663 | f0cbd3ec | bellard | /* setsockopt(so->s,SOL_SOCKET,SO_OOBINLINE,(char *)&opt,sizeof(int)); */
|
664 | 5fafdf24 | ths | |
665 | f0cbd3ec | bellard | getsockname(so->s,(struct sockaddr *)&addr,&addrlen);
|
666 | f0cbd3ec | bellard | so->so_fport = addr.sin_port; |
667 | f0cbd3ec | bellard | if (addr.sin_addr.s_addr == 0 || addr.sin_addr.s_addr == loopback_addr.s_addr) |
668 | 8dbca8dd | bellard | so->so_faddr = alias_addr; |
669 | f0cbd3ec | bellard | else
|
670 | f0cbd3ec | bellard | so->so_faddr = addr.sin_addr; |
671 | 5fafdf24 | ths | |
672 | f0cbd3ec | bellard | so->so_lport = lport; |
673 | f0cbd3ec | bellard | so->so_laddr.s_addr = laddr; |
674 | f0cbd3ec | bellard | if (flags != SS_FACCEPTONCE)
|
675 | f0cbd3ec | bellard | so->so_expire = 0;
|
676 | 5fafdf24 | ths | |
677 | f0cbd3ec | bellard | so->so_state = SS_ISFCONNECTED; |
678 | 5fafdf24 | ths | |
679 | f0cbd3ec | bellard | return so;
|
680 | f0cbd3ec | bellard | } |