summaryrefslogtreecommitdiffstats
path: root/misc.c
diff options
context:
space:
mode:
authornaddy@openbsd.org <naddy@openbsd.org>2018-10-05 14:26:09 +0000
committerDamien Miller <djm@mindrot.org>2018-10-07 14:58:24 +1100
commit2581333d564d8697837729b3d07d45738eaf5a54 (patch)
treed0fba4a6a1df98cbd17e428a07321f5339d5471a /misc.c
parente0d6501e86734c48c8c503f81e1c0926e98c5c4c (diff)
upstream: Support using service names for port numbers.
* Try to resolve a port specification with getservbyname(3) if a numeric conversion fails. * Make the "Port" option in ssh_config handle its argument as a port rather than a plain integer. ok dtucker@ deraadt@ OpenBSD-Commit-ID: e7f03633133205ab3dfbc67f9df7475fabae660d
Diffstat (limited to 'misc.c')
-rw-r--r--misc.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/misc.c b/misc.c
index c4ca1256..bdc06fdb 100644
--- a/misc.c
+++ b/misc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: misc.c,v 1.132 2018/10/03 06:38:35 djm Exp $ */
+/* $OpenBSD: misc.c,v 1.133 2018/10/05 14:26:09 naddy Exp $ */
/*
* Copyright (c) 2000 Markus Friedl. All rights reserved.
* Copyright (c) 2005,2006 Damien Miller. All rights reserved.
@@ -50,6 +50,7 @@
#include <netinet/in_systm.h>
#include <netinet/ip.h>
#include <netinet/tcp.h>
+#include <arpa/inet.h>
#include <ctype.h>
#include <errno.h>
@@ -332,13 +333,16 @@ pwcopy(struct passwd *pw)
int
a2port(const char *s)
{
+ struct servent *se;
long long port;
const char *errstr;
port = strtonum(s, 0, 65535, &errstr);
- if (errstr != NULL)
- return -1;
- return (int)port;
+ if (errstr == NULL)
+ return (int)port;
+ if ((se = getservbyname(s, "tcp")) != NULL)
+ return ntohs(se->s_port);
+ return -1;
}
int