7 #include <sys/socket.h>
10 #include <net/gen/in.h>
11 #include <net/gen/tcp.h>
12 #include <net/gen/tcp_io.h>
16 static int _tcp_shutdown(int sock
, int how
);
17 static int _uds_shutdown(int sock
, int how
);
19 int shutdown(int sock
, int how
)
22 struct sockaddr_un uds_addr
;
23 nwio_tcpconf_t tcpconf
;
25 r
= ioctl(sock
, NWIOGTCPCONF
, &tcpconf
);
26 if (r
!= -1 || errno
!= ENOTTY
)
30 /* Bad file descriptor */
33 return _tcp_shutdown(sock
, how
);
36 r
= ioctl(sock
, NWIOGUDSADDR
, &uds_addr
);
37 if (r
!= -1 || errno
!= ENOTTY
)
41 /* Bad file descriptor */
44 return _uds_shutdown(sock
, how
);
48 fprintf(stderr
, "shutdown: not implemented for fd %d\n", sock
);
54 static int _tcp_shutdown(int sock
, int how
)
58 if (how
== SHUT_WR
|| how
== SHUT_RDWR
)
60 r
= ioctl(sock
, NWIOTCPSHUTDOWN
, NULL
);
67 /* We can't shutdown the read side of the socket. */
72 static int _uds_shutdown(int sock
, int how
)
74 return ioctl(sock
, NWIOSUDSSHUT
, &how
);