-/* $OpenBSD: netcat.c,v 1.153 2016/06/02 04:26:32 beck Exp $ */
+/* $OpenBSD: netcat.c,v 1.154 2016/06/27 23:58:08 deraadt Exp $ */
/*
* Copyright (c) 2001 Eric Jackson <ericj@monkey.org>
* Copyright (c) 2015 Bob Beck. All rights reserved.
int
main(int argc, char *argv[])
{
- int ch, s, ret, socksv;
+ int ch, s = -1, ret, socksv;
char *host, *uport;
struct addrinfo hints;
struct servent *sv;
struct tls *tls_ctx = NULL;
ret = 1;
- s = 0;
socksv = 5;
host = NULL;
uport = NULL;
build_ports(uport);
/* Cycle through portlist, connecting to each port. */
- for (i = 0; portlist[i] != NULL; i++) {
- if (s)
+ for (s = -1, i = 0; portlist[i] != NULL; i++) {
+ if (s != -1)
close(s);
if (usetls) {
else
s = remote_connect(host, portlist[i], hints);
- if (s < 0)
+ if (s == -1)
continue;
ret = 0;
}
}
- if (s)
+ if (s != -1)
close(s);
tls_config_free(tls_cfg);