source: trunk/minix/lib/ip/accept.c@ 12

Last change on this file since 12 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 1.2 KB
Line 
1#include <errno.h>
2#include <fcntl.h>
3#include <stdio.h>
4#include <unistd.h>
5#include <string.h>
6#include <sys/ioctl.h>
7#include <sys/socket.h>
8#include <netinet/in.h>
9
10#include <net/netlib.h>
11#include <net/gen/in.h>
12#include <net/gen/tcp.h>
13#include <net/gen/tcp_io.h>
14#include <net/gen/udp.h>
15#include <net/gen/udp_io.h>
16
17#define DEBUG 0
18
19static int _tcp_accept(int socket, struct sockaddr *_RESTRICT address,
20 socklen_t *_RESTRICT address_len);
21
22int accept(int socket, struct sockaddr *_RESTRICT address,
23 socklen_t *_RESTRICT address_len)
24{
25 int r;
26
27 r= _tcp_accept(socket, address, address_len);
28 return r;
29
30#if DEBUG
31 fprintf(stderr, "accept: not implemented for fd %d\n", socket);
32#endif
33 errno= ENOSYS;
34 return -1;
35}
36
37static int _tcp_accept(int socket, struct sockaddr *_RESTRICT address,
38 socklen_t *_RESTRICT address_len)
39{
40 int r, s1, t_errno;
41 tcp_cookie_t cookie;
42
43 s1= open(TCP_DEVICE, O_RDWR);
44 if (s1 == -1)
45 return s1;
46 r= ioctl(s1, NWIOGTCPCOOKIE, &cookie);
47 if (r == -1)
48 {
49 t_errno= errno;
50 close(s1);
51 errno= t_errno;
52 return -1;
53 }
54 r= ioctl(socket, NWIOTCPACCEPTTO, &cookie);
55 if (r == -1)
56 {
57 t_errno= errno;
58 close(s1);
59 errno= t_errno;
60 return -1;
61 }
62 if (address != NULL)
63 getpeername(s1, address, address_len);
64 return s1;
65}
Note: See TracBrowser for help on using the repository browser.