]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
Add versions of string_to_number() for use in 32bit userspace with 64bit kernel.
authorMartin Josefsson <gandalf@wlug.westbo.se>
Wed, 26 May 2004 15:54:49 +0000 (15:54 +0000)
committerMartin Josefsson <gandalf@wlug.westbo.se>
Wed, 26 May 2004 15:54:49 +0000 (15:54 +0000)
include/iptables_common.h
ip6tables.c
iptables.c

index 25f23c3cd6f1947e44f6c17348ec29b870184475..ca65594ee1dce446d32205fdd9c10d955975c51e 100644 (file)
@@ -14,6 +14,14 @@ extern int string_to_number(const char *,
                            unsigned int, 
                            unsigned int,
                            unsigned int *);
+extern int string_to_number_l(const char *, 
+                           unsigned long int, 
+                           unsigned long int,
+                           unsigned long *);
+extern int string_to_number_ll(const char *, 
+                           unsigned long long int, 
+                           unsigned long long int,
+                           unsigned long long *);
 extern int iptables_insmod(const char *modname, const char *modprobe);
 void exit_error(enum exittype, char *, ...)__attribute__((noreturn,
                                                          format(printf,2,3)));
index ee42c087dbc81e735bc3342babce77b42735d7b4..714632d2b72b49acc692b60eca183ed58ddb17ea 100644 (file)
@@ -900,18 +900,18 @@ parse_target(const char *targetname)
 }
 
 int
-string_to_number(const char *s, unsigned int min, unsigned int max,
-                unsigned int *ret)
+string_to_number_ll(const char *s, unsigned long long min, unsigned long long max,
+                unsigned long long *ret)
 {
-       long number;
+       unsigned long long number;
        char *end;
 
        /* Handle hex, octal, etc. */
        errno = 0;
-       number = strtol(s, &end, 0);
+       number = strtoull(s, &end, 0);
        if (*end == '\0' && end != s) {
                /* we parsed a number, let's see if we want this */
-               if (errno != ERANGE && min <= number && number <= max) {
+               if (errno != ERANGE && min <= number && (!max || number <= max)) {
                        *ret = number;
                        return 0;
                }
@@ -919,6 +919,31 @@ string_to_number(const char *s, unsigned int min, unsigned int max,
        return -1;
 }
 
+int
+string_to_number_l(const char *s, unsigned long min, unsigned long max,
+                unsigned long *ret)
+{
+       int result;
+       unsigned long long number;
+
+       result = string_to_number_ll(s, min, max, &number);
+       *ret = (unsigned long)number;
+
+       return result;
+}
+
+int string_to_number(const char *s, unsigned int min, unsigned int max,
+               unsigned int *ret)
+{
+       int result;
+       unsigned long number;
+
+       result = string_to_number_l(s, min, max, &number);
+       *ret = (unsigned int)number;
+
+       return result;
+}
+
 static void
 set_option(unsigned int *options, unsigned int option, u_int8_t *invflg,
           int invert)
index 648f988f2bb67ce443d5131a9535199b797e2461..fab46430874aad963d5e7c67302e7a4ee8748ed4 100644 (file)
@@ -900,18 +900,18 @@ mask_to_dotted(const struct in_addr *mask)
 }
 
 int
-string_to_number(const char *s, unsigned int min, unsigned int max,
-                unsigned int *ret)
+string_to_number_ll(const char *s, unsigned long long min, unsigned long long max,
+                unsigned long long *ret)
 {
-       long number;
+       unsigned long long number;
        char *end;
 
        /* Handle hex, octal, etc. */
        errno = 0;
-       number = strtol(s, &end, 0);
+       number = strtoull(s, &end, 0);
        if (*end == '\0' && end != s) {
                /* we parsed a number, let's see if we want this */
-               if (errno != ERANGE && min <= number && number <= max) {
+               if (errno != ERANGE && min <= number && (!max || number <= max)) {
                        *ret = number;
                        return 0;
                }
@@ -919,6 +919,31 @@ string_to_number(const char *s, unsigned int min, unsigned int max,
        return -1;
 }
 
+int
+string_to_number_l(const char *s, unsigned long min, unsigned long max,
+                unsigned long *ret)
+{
+       int result;
+       unsigned long long number;
+
+       result = string_to_number_ll(s, min, max, &number);
+       *ret = (unsigned long)number;
+
+       return result;
+}
+
+int string_to_number(const char *s, unsigned int min, unsigned int max,
+               unsigned int *ret)
+{
+       int result;
+       unsigned long number;
+
+       result = string_to_number_l(s, min, max, &number);
+       *ret = (unsigned int)number;
+
+       return result;
+}
+
 static void
 set_option(unsigned int *options, unsigned int option, u_int8_t *invflg,
           int invert)