From f01369e4fd327273b326a82b3e082210ceee631b Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sun, 18 May 2014 14:02:34 +0800 Subject: [PATCH] Usermode/libnet - Fix IPV4 parsing code to use stroul --- Usermode/Libraries/libnet.so_src/address.c | 48 +++++++++++++--------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/Usermode/Libraries/libnet.so_src/address.c b/Usermode/Libraries/libnet.so_src/address.c index 66a28b1b..8887362d 100644 --- a/Usermode/Libraries/libnet.so_src/address.c +++ b/Usermode/Libraries/libnet.so_src/address.c @@ -7,7 +7,8 @@ */ #include #include -#include +//#include +#include #define DEBUG 0 static inline uint32_t htonl(uint32_t v) @@ -37,43 +38,50 @@ static inline uint16_t htons(uint16_t v) */ static int Net_ParseIPv4Addr(const char *String, uint8_t *Addr) { - int i = 0; int j; - int val; + const char *pos = String; - for( j = 0; String[i] && j < 4; j ++ ) + for( j = 0; *pos && j < 4; j ++ ) { - val = 0; - for( ; String[i] && String[i] != '.'; i++ ) - { - if('0' > String[i] || String[i] > '9') { - #if DEBUG - printf("0 255) { #if DEBUG - printf("val > 255 (%i)\n", val); + _SysDebug("%s: val > 255 (%i)", __func__, val); #endif return 0; } + #if DEBUG + _SysDebug("%s: Comp '%.*s' = %lu", __func__, end - pos, pos, val); + #endif Addr[j] = val; - if(String[i] == '.') - i ++; + pos = end; + + if(*pos == '.') + pos ++; } if( j != 4 ) { #if DEBUG - printf("4 parts expected, %i found\n", j); + _SysDebug("%s: 4 parts expected, %i found", __func__, j); #endif return 0; } - if(String[i] != '\0') { + if(*pos != '\0') { #if DEBUG - printf("EOS != '\\0', '%c'\n", String[i]); + _SysDebug("%s: EOS != '\\0', '%c'", __func__, *pos); #endif return 0; } -- 2.20.1