]> git.ipfire.org Git - thirdparty/dhcp.git/blobdiff - common/inet.c
Merged rt35711c (DHCPv4-over-DHCPv6 support)
[thirdparty/dhcp.git] / common / inet.c
index 0cff19d0dc61bdc071c41e3ea00b36ac22001b45..52852d8300a39eb5130218fb26e8c80f400b8f46 100644 (file)
@@ -4,7 +4,7 @@
    way... */
 
 /*
- * Copyright (c) 2011,2013,2014 by Internet Systems Consortium, Inc. ("ISC")
+ * Copyright (c) 2011,2013,2014,2016 by Internet Systems Consortium, Inc. ("ISC")
  * Copyright (c) 2007-2009 by Internet Systems Consortium, Inc. ("ISC")
  * Copyright (c) 2004,2005 by Internet Systems Consortium, Inc. ("ISC")
  * Copyright (c) 1995-2003 by Internet Software Consortium
@@ -622,3 +622,29 @@ validate_port(char *port) {
 
        return htons((u_int16_t)local_port);
 }
+
+/* \brief Validate that the string represents a valid port pair (i.e. n,n+1)
+ *
+ * \param the string to validate
+ * \return the first port number in network byte order
+ */
+
+u_int16_t
+validate_port_pair(char *port) {
+       long local_port = 0;
+       long lower = 1;
+       long upper = 65534;
+       char *endptr;
+
+       errno = 0;
+       local_port = strtol(port, &endptr, 10);
+       
+       if ((*endptr != '\0') || (errno == ERANGE) || (errno == EINVAL))
+               log_fatal ("Invalid port pair specification: %s", port);
+
+       if (local_port < lower || local_port > upper)
+               log_fatal("Port pair specified is out of range (%ld-%ld).",
+                         lower, upper);
+
+       return htons((u_int16_t)local_port);
+}