From ca673822484c3ad4a2f309873e649868a8e0fcff Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Wed, 20 Feb 2019 07:46:40 -0600 Subject: Simplify netcat a lot using the net.c upgrades from last commit. --- toys/net/netcat.c | 31 ++----------------------------- 1 file changed, 2 insertions(+), 29 deletions(-) (limited to 'toys/net') 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) { -- cgit v1.2.3