-/* $OpenBSD: netcat.c,v 1.219 2022/06/08 20:07:31 tb Exp $ */
+/* $OpenBSD: netcat.c,v 1.220 2022/12/18 12:45:34 tb Exp $ */
/*
* Copyright (c) 2001 Eric Jackson <ericj@monkey.org>
* Copyright (c) 2015 Bob Beck. All rights reserved.
int socks_connect(const char *, const char *, struct addrinfo,
const char *, const char *, struct addrinfo, int, const char *);
int udptest(int);
+void connection_info(const char *, const char *, const char *);
int unix_bind(char *, int);
int unix_connect(char *);
int unix_listen(char *);
char *host, *uport;
char ipaddr[NI_MAXHOST];
struct addrinfo hints;
- struct servent *sv;
socklen_t len;
struct sockaddr_storage cliaddr;
char *proxy = NULL, *proxyport = NULL;
socksv = 5;
host = NULL;
uport = NULL;
- sv = NULL;
Rflag = tls_default_ca_cert_file();
signal(SIGPIPE, SIG_IGN);
}
}
- /* Don't look up port if -n. */
- if (nflag)
- sv = NULL;
- else {
- sv = getservbyport(
- ntohs(atoi(portlist[i])),
- uflag ? "udp" : "tcp");
- }
-
- fprintf(stderr, "Connection to %s", host);
-
- /*
- * if we aren't connecting thru a proxy and
- * there is something to report, print IP
- */
- if (!nflag && !xflag &&
- strcmp(host, ipaddr) != 0)
- fprintf(stderr, " (%s)", ipaddr);
-
- fprintf(stderr, " %s port [%s/%s] succeeded!\n",
- portlist[i], uflag ? "udp" : "tcp",
- sv ? sv->s_name : "*");
+ connection_info(host, portlist[i], ipaddr);
}
if (Fflag)
fdpass(s);
return ret;
}
+void
+connection_info(const char *host, const char *port, const char *ipaddr)
+{
+ struct servent *sv;
+
+ /* Don't look up port if -n. */
+ if (nflag)
+ sv = NULL;
+ else {
+ sv = getservbyport(ntohs(atoi(port)), uflag ? "udp" : "tcp");
+ }
+
+ fprintf(stderr, "Connection to %s", host);
+
+ /*
+ * if we aren't connecting thru a proxy and
+ * there is something to report, print IP
+ */
+ if (!nflag && !xflag && strcmp(host, ipaddr) != 0)
+ fprintf(stderr, " (%s)", ipaddr);
+
+ fprintf(stderr, " %s port [%s/%s] succeeded!\n",
+ port, uflag ? "udp" : "tcp", sv ? sv->s_name : "*");
+}
+
void
set_common_sockopts(int s, int af)
{