diff options
author | Josh Gao <jmgao@google.com> | 2018-12-10 16:57:46 -0800 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2018-12-10 20:09:34 -0600 |
commit | 0e431542e98f70aeb26291c0ada7bff84851dc77 (patch) | |
tree | 455a28237307d72aa6f34000a85ba204d8762c5f /lib/net.c | |
parent | 3c2a6d3622707d53b254b71df5b73e8a465d03b5 (diff) | |
download | toybox-0e431542e98f70aeb26291c0ada7bff84851dc77.tar.gz |
nc: add IPv6 support.
Diffstat (limited to 'lib/net.c')
-rw-r--r-- | lib/net.c | 18 |
1 files changed, 18 insertions, 0 deletions
@@ -53,6 +53,24 @@ int xconnect(struct addrinfo *ai_arg) return fd; } +int xbind(struct addrinfo *ai_arg) +{ + struct addrinfo *ai; + int fd = -1; + + // Try all the returned addresses. Report errors if last entry can't connect. + for (ai = ai_arg; ai; ai = ai->ai_next) { + fd = (ai->ai_next ? socket : xsocket)(ai->ai_family, ai->ai_socktype, + ai->ai_protocol); + if (!bind(fd, ai->ai_addr, ai->ai_addrlen)) break; + else if (!ai->ai_next) perror_exit("connect"); + close(fd); + } + freeaddrinfo(ai_arg); + + return fd; +} + int xpoll(struct pollfd *fds, int nfds, int timeout) { int i; |