7 #include <sys/socket.h>
10 #include <net/gen/in.h>
11 #include <net/gen/tcp.h>
12 #include <net/gen/tcp_io.h>
15 __weak_alias(shutdown
, _shutdown
)
20 static int _tcp_shutdown(int sock
, int how
);
21 static int _uds_shutdown(int sock
, int how
);
23 int shutdown(int sock
, int how
)
26 struct sockaddr_un uds_addr
;
27 nwio_tcpconf_t tcpconf
;
29 r
= ioctl(sock
, NWIOGTCPCONF
, &tcpconf
);
30 if (r
!= -1 || (errno
!= ENOTTY
&& errno
!= EBADIOCTL
))
34 /* Bad file descriptor */
37 return _tcp_shutdown(sock
, how
);
40 r
= ioctl(sock
, NWIOGUDSADDR
, &uds_addr
);
41 if (r
!= -1 || (errno
!= ENOTTY
&& errno
!= EBADIOCTL
))
45 /* Bad file descriptor */
48 return _uds_shutdown(sock
, how
);
52 fprintf(stderr
, "shutdown: not implemented for fd %d\n", sock
);
58 static int _tcp_shutdown(int sock
, int how
)
62 if (how
== SHUT_WR
|| how
== SHUT_RDWR
)
64 r
= ioctl(sock
, NWIOTCPSHUTDOWN
, NULL
);
71 /* We can't shutdown the read side of the socket. */
76 static int _uds_shutdown(int sock
, int how
)
78 return ioctl(sock
, NWIOSUDSSHUT
, &how
);