diff options
author | Rob Landley <rob@landley.net> | 2015-08-05 21:20:27 -0500 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2015-08-05 21:20:27 -0500 |
commit | 31ff1f23dedbfe6e2dccf9d3c7c294a1cd761266 (patch) | |
tree | a50c230a6fe9b8c99bdacce741887f01d0ee2005 /toys/other | |
parent | 35dafc7b17ce23da62dcce2195bed9b370680e65 (diff) | |
download | toybox-31ff1f23dedbfe6e2dccf9d3c7c294a1cd761266.tar.gz |
Switch nbd_client to xconnect() and make xconnect() try all returned addresses
before failing.
Diffstat (limited to 'toys/other')
-rw-r--r-- | toys/other/nbd_client.c | 16 |
1 files changed, 1 insertions, 15 deletions
diff --git a/toys/other/nbd_client.c b/toys/other/nbd_client.c index c16585a2..a82ff7c8 100644 --- a/toys/other/nbd_client.c +++ b/toys/other/nbd_client.c @@ -40,7 +40,6 @@ void nbd_client_main(void) { int sock = -1, nbd, flags; unsigned long timeout = 0; - struct addrinfo *addr, *p; char *host=toys.optargs[0], *port=toys.optargs[1], *device=toys.optargs[2]; uint64_t devsize; @@ -49,23 +48,10 @@ void nbd_client_main(void) nbd = xopen(device, O_RDWR); for (;;) { int temp; - struct addrinfo hints; // Find and connect to server - memset(&hints, 0, sizeof(hints)); - hints.ai_family = PF_UNSPEC; - hints.ai_socktype = SOCK_STREAM; - if (getaddrinfo(host, port, &hints, &addr)) addr = 0; - for (p = addr; p; p = p->ai_next) { - sock = socket(p->ai_family, p->ai_socktype, p->ai_protocol); - if (-1 != connect(sock, p->ai_addr, p->ai_addrlen)) break; - close(sock); - } - freeaddrinfo(addr); - - if (!p) perror_exit("%s:%s", host, port); - + sock = xconnect(host, port, AF_UNSPEC, SOCK_STREAM, 0, 0); temp = 1; setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, &temp, sizeof(int)); |