From 4ae678eaf8a48d548308a57e23df38c7afca8a0e Mon Sep 17 00:00:00 2001 From: Ralf Baechle Date: Tue, 1 Aug 2017 02:37:32 +0200 Subject: rip98d: Perform a crapectomy on hex2intrev(). hex2intrev is a hilariously complicated function which combine parsing a hexadecimal integer in network byte order and swapping the result to host byte order. Move the endianess swapping to the caller which allows to remove double endianess swapping. Now that hex2intrev no longer deals with byte order rename it to hex2int and replace its implementation with a simple invocation of strtoul. Signed-off-by: Ralf Baechle --- tcpip/rip98d.c | 50 ++++---------------------------------------------- 1 file changed, 4 insertions(+), 46 deletions(-) (limited to 'tcpip') diff --git a/tcpip/rip98d.c b/tcpip/rip98d.c index 43d31ba..b375d70 100644 --- a/tcpip/rip98d.c +++ b/tcpip/rip98d.c @@ -67,51 +67,9 @@ unsigned int bits2mask(unsigned int bits) return ~0 << (sizeof(unsigned int) * 8 - bits); } -static unsigned long int hex2intrev(char *buffer) +static unsigned int hex2int(char *buffer) { - unsigned long int result = 0L; - - if (buffer[0] >= 'A') - result += (buffer[0] - 'A' + 10) * 16; - else - result += (buffer[0] - '0') * 16; - - if (buffer[1] >= 'A') - result += buffer[1] - 'A' + 10; - else - result += buffer[1] - '0'; - - if (buffer[2] >= 'A') - result += (buffer[2] - 'A' + 10) * 16 * 16 * 16; - else - result += (buffer[2] - '0') * 16 * 16 * 16; - - if (buffer[3] >= 'A') - result += (buffer[3] - 'A' + 10) * 16 * 16; - else - result += (buffer[3] - '0') * 16 * 16; - - if (buffer[4] >= 'A') - result += (buffer[4] - 'A' + 10) * 16 * 16 * 16 * 16 * 16; - else - result += (buffer[4] - '0') * 16 * 16 * 16 * 16 * 16; - - if (buffer[5] >= 'A') - result += (buffer[5] - 'A' + 10) * 16 * 16 * 16 * 16; - else - result += (buffer[5] - '0') * 16 * 16 * 16 * 16; - - if (buffer[6] >= 'A') - result += (buffer[6] - 'A' + 10) * 16 * 16 * 16 * 16 * 16 * 16 * 16; - else - result += (buffer[6] - '0') * 16 * 16 * 16 * 16 * 16 * 16 * 16; - - if (buffer[7] >= 'A') - result += (buffer[7] - 'A' + 10) * 16 * 16 * 16 * 16 * 16 * 16; - else - result += (buffer[7] - '0') * 16 * 16 * 16 * 16 * 16 * 16; - - return result; + return strtoul(buffer, NULL, 16); } static int read_routes(void) @@ -152,8 +110,8 @@ static int read_routes(void) if (n != 10) continue; - address.s_addr = htonl(hex2intrev(net_addr)); - netmask = mask2bits(hex2intrev(mask_addr)); + address.s_addr = hex2int(net_addr); + netmask = mask2bits(ntohl(hex2int(mask_addr))); network = inet_netof(address); -- cgit v1.2.3