look ok to me.. go for it
On Fri, Jul 29, 2016 at 6:00 PM, Alexander Hall <alexan...@beard.se> wrote: > Use the style from the man page examples for getaddrinfo, which makes a > bit more sense. > > No functional change intended, and prior to the do/while => for > transition, no .o files were harmed. > > OK? > > /Alexander > > > Index: netcat.c > =================================================================== > RCS file: /cvs/src/usr.bin/nc/netcat.c,v > retrieving revision 1.160 > diff -u -p -r1.160 netcat.c > --- netcat.c 13 Jul 2016 16:35:47 -0000 1.160 > +++ netcat.c 29 Jul 2016 23:47:52 -0000 > @@ -834,13 +834,12 @@ remote_connect(const char *host, const c > struct addrinfo *res, *res0; > int s, error, on = 1, save_errno; > > - if ((error = getaddrinfo(host, port, &hints, &res))) > + if ((error = getaddrinfo(host, port, &hints, &res0))) > errx(1, "getaddrinfo: %s", gai_strerror(error)); > > - res0 = res; > - do { > - if ((s = socket(res0->ai_family, res0->ai_socktype | > - SOCK_NONBLOCK, res0->ai_protocol)) < 0) > + for (res = res0; res; res = res->ai_next) { > + if ((s = socket(res->ai_family, res->ai_socktype | > + SOCK_NONBLOCK, res->ai_protocol)) < 0) > continue; > > /* Bind to a local port or source address if specified. */ > @@ -850,7 +849,7 @@ remote_connect(const char *host, const c > /* try SO_BINDANY, but don't insist */ > setsockopt(s, SOL_SOCKET, SO_BINDANY, &on, > sizeof(on)); > memset(&ahints, 0, sizeof(struct addrinfo)); > - ahints.ai_family = res0->ai_family; > + ahints.ai_family = res->ai_family; > ahints.ai_socktype = uflag ? SOCK_DGRAM : > SOCK_STREAM; > ahints.ai_protocol = uflag ? IPPROTO_UDP : > IPPROTO_TCP; > ahints.ai_flags = AI_PASSIVE; > @@ -863,9 +862,9 @@ remote_connect(const char *host, const c > freeaddrinfo(ares); > } > > - set_common_sockopts(s, res0->ai_family); > + set_common_sockopts(s, res->ai_family); > > - if (timeout_connect(s, res0->ai_addr, res0->ai_addrlen) == > 0) > + if (timeout_connect(s, res->ai_addr, res->ai_addrlen) == 0) > break; > if (vflag) > warn("connect to %s port %s (%s) failed", host, > port, > @@ -875,9 +874,9 @@ remote_connect(const char *host, const c > close(s); > errno = save_errno; > s = -1; > - } while ((res0 = res0->ai_next) != NULL); > + } > > - freeaddrinfo(res); > + freeaddrinfo(res0); > > return (s); > } > @@ -932,37 +931,36 @@ local_listen(char *host, char *port, str > if (host == NULL && hints.ai_family == AF_UNSPEC) > hints.ai_family = AF_INET; > > - if ((error = getaddrinfo(host, port, &hints, &res))) > + if ((error = getaddrinfo(host, port, &hints, &res0))) > errx(1, "getaddrinfo: %s", gai_strerror(error)); > > - res0 = res; > - do { > - if ((s = socket(res0->ai_family, res0->ai_socktype, > - res0->ai_protocol)) < 0) > + for (res = res0; res; res = res->ai_next) { > + if ((s = socket(res->ai_family, res->ai_socktype, > + res->ai_protocol)) < 0) > continue; > > ret = setsockopt(s, SOL_SOCKET, SO_REUSEPORT, &x, > sizeof(x)); > if (ret == -1) > err(1, NULL); > > - set_common_sockopts(s, res0->ai_family); > + set_common_sockopts(s, res->ai_family); > > - if (bind(s, (struct sockaddr *)res0->ai_addr, > - res0->ai_addrlen) == 0) > + if (bind(s, (struct sockaddr *)res->ai_addr, > + res->ai_addrlen) == 0) > break; > > save_errno = errno; > close(s); > errno = save_errno; > s = -1; > - } while ((res0 = res0->ai_next) != NULL); > + } > > if (!uflag && s != -1) { > if (listen(s, 1) < 0) > err(1, "listen"); > } > > - freeaddrinfo(res); > + freeaddrinfo(res0); > > return (s); > } > >