summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNiklas Hallqvist <niklas@cvs.openbsd.org>1998-12-22 02:25:17 +0000
committerNiklas Hallqvist <niklas@cvs.openbsd.org>1998-12-22 02:25:17 +0000
commit469283453fa7d725c88addb1f3cecb78399a2f36 (patch)
tree78ae3ac68fee8fa3df61c813bcea5d030d327347
parent1811f757a04bf7d8b9e375df19433f5e7e42b65a (diff)
Generalize udp port decoding. Remove unneeded decls.
-rw-r--r--sbin/isakmpd/isakmpd.c15
-rw-r--r--sbin/isakmpd/udp.c59
-rw-r--r--sbin/isakmpd/udp.h5
3 files changed, 47 insertions, 32 deletions
diff --git a/sbin/isakmpd/isakmpd.c b/sbin/isakmpd/isakmpd.c
index dafe9fbb544..8f14e18755e 100644
--- a/sbin/isakmpd/isakmpd.c
+++ b/sbin/isakmpd/isakmpd.c
@@ -1,5 +1,5 @@
-/* $OpenBSD: isakmpd.c,v 1.5 1998/12/21 01:02:25 niklas Exp $ */
-/* $EOM: isakmpd.c,v 1.24 1998/12/01 10:18:43 niklas Exp $ */
+/* $OpenBSD: isakmpd.c,v 1.6 1998/12/22 02:25:16 niklas Exp $ */
+/* $EOM: isakmpd.c,v 1.25 1998/12/22 02:23:44 niklas Exp $ */
/*
* Copyright (c) 1998 Niklas Hallqvist. All rights reserved.
@@ -52,9 +52,6 @@
#include "udp.h"
#include "ui.h"
-extern char *optarg;
-extern int optind;
-
/*
* Set if -d is given, currently just for running in the foreground and log
* to stderr instead of syslog.
@@ -117,10 +114,14 @@ parse_args (int argc, char *argv[])
app_none++;
break;
case 'p':
- udp_default_port = atoi (optarg);
+ udp_default_port = udp_decode_port (optarg);
+ if (!udp_default_port)
+ exit (1);
break;
case 'P':
- udp_bind_port = atoi (optarg);
+ udp_bind_port = udp_decode_port (optarg);
+ if (!udp_bind_port)
+ exit (1);
break;
case 'r':
srandom (strtoul (optarg, NULL, 0));
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;
+}
diff --git a/sbin/isakmpd/udp.h b/sbin/isakmpd/udp.h
index eec8f13e0fb..143064dd552 100644
--- a/sbin/isakmpd/udp.h
+++ b/sbin/isakmpd/udp.h
@@ -1,5 +1,5 @@
-/* $OpenBSD: udp.h,v 1.3 1998/11/17 11:10:21 niklas Exp $ */
-/* $EOM: udp.h,v 1.3 1998/10/08 20:22:18 niklas Exp $ */
+/* $OpenBSD: udp.h,v 1.4 1998/12/22 02:25:15 niklas Exp $ */
+/* $EOM: udp.h,v 1.4 1998/12/22 02:23:43 niklas Exp $ */
/*
* Copyright (c) 1998 Niklas Hallqvist. All rights reserved.
@@ -40,6 +40,7 @@
extern in_port_t udp_default_port;
extern in_port_t udp_bind_port;
+extern in_port_t udp_decode_port (char *);
extern void udp_init (void);
#endif /* _UDP_H_ */