7 #include <sys/socket.h>
9 #include <net/netlib.h>
10 #include <net/gen/in.h>
11 #include <net/gen/tcp.h>
12 #include <net/gen/tcp_io.h>
13 #include <net/gen/udp.h>
14 #include <net/gen/udp_io.h>
18 static int _tcp_accept(int socket
, struct sockaddr
*_RESTRICT address
,
19 socklen_t
*_RESTRICT address_len
);
21 int accept(int socket
, struct sockaddr
*_RESTRICT address
,
22 socklen_t
*_RESTRICT address_len
)
27 r
= _tcp_accept(socket
, address
, address_len
);
28 if (r
!= -1 || (errno
!= ENOTTY
&& errno
!= EBADIOCTL
))
31 /* Unfortunately, we have to return EOPNOTSUPP for a socket that
32 * does not support accept (such as a UDP socket) and ENOTSOCK for
33 * filedescriptors that do not refer to a socket.
35 r
= ioctl(socket
, NWIOGUDPOPT
, &udpopt
);
42 if ((errno
== ENOTTY
|| errno
== EBADIOCTL
))
51 static int _tcp_accept(int socket
, struct sockaddr
*_RESTRICT address
,
52 socklen_t
*_RESTRICT address_len
)
57 s1
= open(TCP_DEVICE
, O_RDWR
);
60 r
= ioctl(s1
, NWIOGTCPCOOKIE
, &cookie
);
68 r
= ioctl(socket
, NWIOTCPACCEPTTO
, &cookie
);
77 getpeername(s1
, address
, address_len
);