diff options
-rw-r--r-- | toys/net/netcat.c | 31 |
1 files changed, 2 insertions, 29 deletions
diff --git a/toys/net/netcat.c b/toys/net/netcat.c index 1c765348..e98f12b2 100644 --- a/toys/net/netcat.c +++ b/toys/net/netcat.c @@ -110,35 +110,8 @@ void netcat_main(void) struct sockaddr* address = (void*)toybuf; socklen_t len = sizeof(struct sockaddr_storage); - if (TT.s) { - sprintf(toybuf, "%ld", TT.p); - sockfd = xbind(xgetaddrinfo(TT.s, toybuf, family, type, 0, 0)); - } else { - size_t bind_addrlen; - - // If we weren't given an address with which to resolve which family to - // use, we have to choose. - if (family == AF_UNSPEC) family = AF_INET; - - address->sa_family = family; - - if (family == AF_INET6) { - struct sockaddr_in6* addr_in6 = (void*)address; - bind_addrlen = sizeof(*addr_in6); - addr_in6->sin6_port = SWAP_BE16(TT.p); - addr_in6->sin6_addr = in6addr_any; - } else { - struct sockaddr_in* addr_in = (void*)address; - bind_addrlen = sizeof(*addr_in); - addr_in->sin_port = SWAP_BE16(TT.p); - addr_in->sin_addr.s_addr = INADDR_ANY; - } - - sockfd = xsocket(family, type, 0); - type = 1; - xsetsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &type, sizeof(type)); - if (bind(sockfd, address, bind_addrlen)) perror_exit("bind"); - } + sprintf(toybuf, "%ld", TT.p); + sockfd = xbind(xgetaddrinfo(TT.s, toybuf, family, type, 0, 0)); if (listen(sockfd, 5)) error_exit("listen"); if (!TT.p) { |