mirror of
https://github.com/nmap/nmap.git
synced 2026-01-20 05:09:02 +00:00
Allow do_listen to return an error.
This commit is contained in:
@@ -271,6 +271,8 @@ static int ncat_listen_stream(int proto)
|
||||
for (i = 0; i < num_listenaddrs; i++) {
|
||||
/* setup the main listening socket */
|
||||
listen_socket[i] = do_listen(SOCK_STREAM, proto, &listenaddrs[i]);
|
||||
if (listen_socket[i] == -1)
|
||||
bye("do_listen: %s", socket_strerror(socket_errno()));
|
||||
|
||||
/* Make our listening socket non-blocking because there are timing issues
|
||||
* which could cause us to block on accept() even though select() says it's
|
||||
@@ -659,6 +661,8 @@ static int ncat_listen_dgram(int proto)
|
||||
for (i = 0; i < num_listenaddrs; i++) {
|
||||
/* create the UDP listen sockets */
|
||||
sockfd[i] = do_listen(SOCK_DGRAM, proto, &listenaddrs[i]);
|
||||
if (sockfd[i] == -1)
|
||||
bye("do_listen: %s", socket_strerror(socket_errno()));
|
||||
FD_SET(sockfd[i], &listen_fds);
|
||||
add_fd(&listen_fdlist, sockfd[i]);
|
||||
}
|
||||
@@ -676,6 +680,8 @@ static int ncat_listen_dgram(int proto)
|
||||
|
||||
/* Rebuild the udp socket which got burnt */
|
||||
sockfd[fdn] = do_listen(SOCK_DGRAM, proto, &listenaddrs[fdn]);
|
||||
if (sockfd[i] == -1)
|
||||
bye("do_listen: %s", socket_strerror(socket_errno()));
|
||||
FD_SET(sockfd[fdn], &listen_fds);
|
||||
add_fd(&listen_fdlist, sockfd[fdn]);
|
||||
|
||||
|
||||
@@ -218,6 +218,8 @@ int ncat_http_server(void)
|
||||
/* Listen on each address, set up lists for select */
|
||||
for (i = 0; i < num_listenaddrs; i++) {
|
||||
listen_socket[i] = do_listen(SOCK_STREAM, IPPROTO_TCP, &listenaddrs[i]);
|
||||
if (listen_socket[i] == -1)
|
||||
bye("do_listen: %s", socket_strerror(socket_errno()));
|
||||
|
||||
/* make us not block on accepts in wierd cases. See ncat_listen.c:209 */
|
||||
unblock_socket(listen_socket[i]);
|
||||
|
||||
@@ -387,6 +387,8 @@ unsigned short inet_port(const union sockaddr_u *su)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Return a listening socket after setting various characteristics on it.
|
||||
Returns -1 on error. */
|
||||
int do_listen(int type, int proto, const union sockaddr_u *srcaddr_u)
|
||||
{
|
||||
int sock = 0, option_on = 1;
|
||||
@@ -400,7 +402,7 @@ int do_listen(int type, int proto, const union sockaddr_u *srcaddr_u)
|
||||
nbase. */
|
||||
sock = inheritable_socket(srcaddr_u->storage.ss_family, type, proto);
|
||||
if (sock < 0)
|
||||
bye("socket: %s", socket_strerror(socket_errno()));
|
||||
return -1;
|
||||
|
||||
Setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &option_on, sizeof(int));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user