diff options
author | Hans-Joerg Hoexer <hshoexer@cvs.openbsd.org> | 2005-03-04 16:51:53 +0000 |
---|---|---|
committer | Hans-Joerg Hoexer <hshoexer@cvs.openbsd.org> | 2005-03-04 16:51:53 +0000 |
commit | e33c7b046085dbe714d5e1a231eb0b16e5c00f18 (patch) | |
tree | 234f8657857ae507215b6f6542c0187bc9d71da2 /sbin/isakmpd/util.c | |
parent | ccc2ee524f8a3d40f352a30d1e15d76830f470ba (diff) |
remove unused function udp_decode_port(), add modified version as text2port() to
utilities.
ok cloder ho
Diffstat (limited to 'sbin/isakmpd/util.c')
-rw-r--r-- | sbin/isakmpd/util.c | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/sbin/isakmpd/util.c b/sbin/isakmpd/util.c index 005ae1e8d8c..4cfb2899d08 100644 --- a/sbin/isakmpd/util.c +++ b/sbin/isakmpd/util.c @@ -1,4 +1,4 @@ -/* $OpenBSD: util.c,v 1.50 2005/02/27 13:12:12 hshoexer Exp $ */ +/* $OpenBSD: util.c,v 1.51 2005/03/04 16:51:52 hshoexer Exp $ */ /* $EOM: util.c,v 1.23 2000/11/23 12:22:08 niklas Exp $ */ /* @@ -242,6 +242,29 @@ hex2raw(char *s, u_int8_t *buf, size_t sz) return 0; } +in_port_t +text2port(char *port_str) +{ + char *port_str_end; + long port_long; + struct servent *service; + + port_long = strtol(port_str, &port_str_end, 0); + if (port_str == port_str_end) { + service = getservbyname(port_str, "udp"); + if (!service) { + log_print("text2port: service \"%s\" unknown", + port_str); + return 0; + } + return ntohs(service->s_port); + } else if (port_long < 1 || port_long > (long)USHRT_MAX) { + log_print("text2port: port %ld out of range", port_long); + return 0; + } + return port_long; +} + int text2sockaddr(char *address, char *port, struct sockaddr **sa, sa_family_t af, int netmask) |