-/* $OpenBSD: netcat.c,v 1.221 2022/12/18 12:47:31 tb Exp $ */
+/* $OpenBSD: netcat.c,v 1.222 2022/12/18 12:48:28 tb Exp $ */
/*
* Copyright (c) 2001 Eric Jackson <ericj@monkey.org>
* Copyright (c) 2015 Bob Beck. All rights reserved.
const char *ipaddr)
{
struct servent *sv;
+ char *service = "*";
- /* Don't look up port if -n. */
- if (nflag)
- sv = NULL;
- else {
+ /* Look up service name unless -n. */
+ if (!nflag) {
sv = getservbyport(ntohs(atoi(port)), proto);
+ if (sv != NULL)
+ service = sv->s_name;
}
fprintf(stderr, "Connection to %s", host);
if (!nflag && !xflag && strcmp(host, ipaddr) != 0)
fprintf(stderr, " (%s)", ipaddr);
- fprintf(stderr, " %s port [%s/%s] succeeded!\n", port, proto,
- sv ? sv->s_name : "*");
+ fprintf(stderr, " %s port [%s/%s] succeeded!\n", port, proto, service);
}
void