diff options
Diffstat (limited to 'accel-pppd')
-rw-r--r-- | accel-pppd/utils.c | 21 | ||||
-rw-r--r-- | accel-pppd/utils.h | 1 |
2 files changed, 22 insertions, 0 deletions
diff --git a/accel-pppd/utils.c b/accel-pppd/utils.c index 491e650..a6a76c9 100644 --- a/accel-pppd/utils.c +++ b/accel-pppd/utils.c @@ -1,4 +1,6 @@ +#include <errno.h> #include <stdio.h> +#include <stdlib.h> #include "triton.h" #include "utils.h" @@ -9,3 +11,22 @@ void __export u_inet_ntoa(in_addr_t addr, char *str) { sprintf(str, "%i.%i.%i.%i", addr & 0xff, (addr >> 8) & 0xff, (addr >> 16) & 0xff, (addr >> 24) & 0xff); } + +int __export u_readlong(long int *dst, const char *src, + long int min, long int max) +{ + char *src_stop = NULL; + long int rv; + + if (dst == NULL || src == NULL || src[0] == '\0') + return -1; + + errno = 0; + rv = strtol(src, &src_stop, 0); + if (errno != 0 || *src_stop != '\0' || rv < min || rv > max) { + return -1; + } else { + *dst = rv; + return 0; + } +} diff --git a/accel-pppd/utils.h b/accel-pppd/utils.h index 27d4d05..bb1a00a 100644 --- a/accel-pppd/utils.h +++ b/accel-pppd/utils.h @@ -4,5 +4,6 @@ #include <netinet/in.h> void u_inet_ntoa(in_addr_t, char *str); +int u_readlong(long int *dst, const char *src, long int min, long int max); #endif |