diff options
author | Rob Landley <rob@landley.net> | 2019-02-20 07:46:40 -0600 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2019-02-20 07:46:40 -0600 |
commit | ca673822484c3ad4a2f309873e649868a8e0fcff (patch) | |
tree | 85ad73d8bd22973601caae722600843ef1e42d6d /toys | |
parent | c0afd2cb5a0f410ff8c2e4ba704accb3b32e5345 (diff) | |
download | toybox-ca673822484c3ad4a2f309873e649868a8e0fcff.tar.gz |
Simplify netcat a lot using the net.c upgrades from last commit.
Diffstat (limited to 'toys')
-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) { |