summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRalf Baechle <ralf@linux-mips.org>2017-08-01 02:37:32 +0200
committerRalf Baechle <ralf@linux-mips.org>2017-08-03 04:21:23 +0200
commit4ae678eaf8a48d548308a57e23df38c7afca8a0e (patch)
tree9f210ff77c324340d7164f02577f608b28a8a310
parentdc615514c9bcc1895d7d2082fce7d3add084c90c (diff)
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 <ralf@linux-mips.org>
-rw-r--r--tcpip/rip98d.c50
1 files changed, 4 insertions, 46 deletions
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);