7 #include <sys/socket.h>
8 #include <netinet/in.h>
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>
19 static int _tcp_accept(int socket
, struct sockaddr
*_RESTRICT address
,
20 socklen_t
*_RESTRICT address_len
);
22 int accept(int socket
, struct sockaddr
*_RESTRICT address
,
23 socklen_t
*_RESTRICT address_len
)
28 r
= _tcp_accept(socket
, address
, address_len
);
29 if (r
!= -1 || (errno
!= ENOTTY
&& errno
!= EBADIOCTL
))
32 /* Unfortunately, we have to return EOPNOTSUPP for a socket that
33 * does not support accept (such as a UDP socket) and ENOTSOCK for
34 * filedescriptors that do not refer to a socket.
36 r
= ioctl(socket
, NWIOGUDPOPT
, &udpopt
);
43 if ((errno
== ENOTTY
|| errno
== EBADIOCTL
))
52 static int _tcp_accept(int socket
, struct sockaddr
*_RESTRICT address
,
53 socklen_t
*_RESTRICT address_len
)
58 s1
= open(TCP_DEVICE
, O_RDWR
);
61 r
= ioctl(s1
, NWIOGTCPCOOKIE
, &cookie
);
69 r
= ioctl(socket
, NWIOTCPACCEPTTO
, &cookie
);
78 getpeername(s1
, address
, address_len
);