Repository navigation
Expand file tree
/
Copy pathaccept.c
More file actions
65 lines (57 loc) · 1.23 KB
/
Copy pathaccept.c
File metadata and controls
65 lines (57 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<
7DC2
div data-line-number="20" class="react-line-number react-code-text" style="padding-right:16px">2021
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <net/netlib.h>
#include <net/gen/in.h>
#include <net/gen/tcp.h>
#include <net/gen/tcp_io.h>
#include <net/gen/udp.h>
#include <net/gen/udp_io.h>
#define DEBUG 0
static int _tcp_accept(int socket, struct sockaddr *_RESTRICT address,
socklen_t *_RESTRICT address_len);
int accept(int socket, struct sockaddr *_RESTRICT address,
socklen_t *_RESTRICT address_len)
{
int r;
r= _tcp_accept(socket, address, address_len);
return r;
#if DEBUG
fprintf(stderr, "accept: not implemented for fd %d\n", socket);
#endif
errno= ENOSYS;
return -1;
}
static int _tcp_accept(int socket, struct sockaddr *_RESTRICT address,
socklen_t *_RESTRICT address_len)
{
int r, s1, t_errno;
tcp_cookie_t cookie;
s1= open(TCP_DEVICE, O_RDWR);
if (s1 == -1)
return s1;
r= ioctl(s1, NWIOGTCPCOOKIE, &cookie);
if (r == -1)
{
t_errno= errno;
close(s1);
errno= t_errno;
return -1;
}
r= ioctl(socket, NWIOTCPACCEPTTO, &cookie);
if (r == -1)
{
t_errno= errno;
close(s1);
errno= t_errno;
return -1;
}
if (address != NULL)
getpeername(s1, address, address_len);
return s1;
}