diff options
author | Niklas Hallqvist <niklas@cvs.openbsd.org> | 1998-12-22 02:25:17 +0000 |
---|---|---|
committer | Niklas Hallqvist <niklas@cvs.openbsd.org> | 1998-12-22 02:25:17 +0000 |
commit | 469283453fa7d725c88addb1f3cecb78399a2f36 (patch) | |
tree | 78ae3ac68fee8fa3df61c813bcea5d030d327347 /sbin/isakmpd/udp.c | |
parent | 1811f757a04bf7d8b9e375df19433f5e7e42b65a (diff) |
Generalize udp port decoding. Remove unneeded decls.
Diffstat (limited to 'sbin/isakmpd/udp.c')
-rw-r--r-- | sbin/isakmpd/udp.c | 59 |
1 files changed, 36 insertions, 23 deletions
diff --git a/sbin/isakmpd/udp.c b/sbin/isakmpd/udp.c index a483bbefb4a..2597d628ff6 100644 --- a/sbin/isakmpd/udp.c +++ b/sbin/isakmpd/udp.c @@ -1,5 +1,5 @@ -/* $OpenBSD: udp.c,v 1.5 1998/12/22 01:46:04 niklas Exp $ */ -/* $EOM: udp.c,v 1.24 1998/12/22 01:40:23 niklas Exp $ */ +/* $OpenBSD: udp.c,v 1.6 1998/12/22 02:25:15 niklas Exp $ */ +/* $EOM: udp.c,v 1.25 1998/12/22 02:23:42 niklas Exp $ */ /* * Copyright (c) 1998 Niklas Hallqvist. All rights reserved. @@ -224,31 +224,13 @@ udp_create (char *name) char *addr_str, *port_str; in_addr_t addr; in_port_t port; - char *port_str_end; - long port_long; - struct servent *service; port_str = conf_get_str (name, "Port"); if (port_str) { - port_long = strtol (port_str, &port_str_end, 0); - if (port_str == port_str_end) - { - service = getservbyname (port_str, "udp"); - if (!service) - { - log_print ("udp_create: service \"%s\" unknown", port_str); - return 0; - } - port = service->s_port; - } - else if (port_long < 1 || port_long > 65535) - { - log_print ("udp_create: port %l out of range", port_long); - return 0; - } - else - port = port_long; + port = udp_decode_port (port_str); + if (!port) + return 0; } else port = UDP_DEFAULT_PORT; @@ -422,3 +404,34 @@ udp_get_src (struct transport *t, struct sockaddr **src, int *src_len) *src = (struct sockaddr *)&((struct udp_transport *)t)->src; *src_len = sizeof ((struct udp_transport *)t)->src; } + +/* + * Take a string containing an ext representation of port and return a + * binary port number. Return zero if anything goes wrong. + */ +in_port_t +udp_decode_port (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 ("udp_decode_port: service \"%s\" unknown", port_str); + return 0; + } + return service->s_port; + } + else if (port_long < 1 || port_long > 65535) + { + log_print ("udp_decode_port: port %ld out of range", port_long); + return 0; + } + + return port_long; +} |