From a5861a4c81bb616b7fba2028cf9ee31f890357c5 Mon Sep 17 00:00:00 2001 From: Ben Longbons Date: Sun, 8 Sep 2013 19:43:28 -0700 Subject: Use IP4 classes and rename conf variables --- src/common/md5calc.cpp | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) (limited to 'src/common/md5calc.cpp') diff --git a/src/common/md5calc.cpp b/src/common/md5calc.cpp index ae134b7..1c48a24 100644 --- a/src/common/md5calc.cpp +++ b/src/common/md5calc.cpp @@ -327,26 +327,21 @@ bool pass_ok(AccountPass password, AccountCrypt crypted) // [M|h]ashes up an IP address and a secret key // to return a hopefully unique masked IP. -struct in_addr MD5_ip(struct in_addr ip) +IP4Address MD5_ip(IP4Address ip) { static SaltString secret = make_salt(); - union - { - uint8_t bytes[4]; - struct in_addr ip; - } conv; // MD5sum a secret + the IP address VString<31> ipbuf; - SNPRINTF(ipbuf, 32, "%u%s", ip.s_addr, secret); + SNPRINTF(ipbuf, 32, "%s %s", ip, secret); md5_binary obuf; MD5_to_bin(MD5_from_string(ipbuf), obuf); // Fold the md5sum to 32 bits, pack the bytes to an in_addr - conv.bytes[0] = obuf[0] ^ obuf[1] ^ obuf[8] ^ obuf[9]; - conv.bytes[1] = obuf[2] ^ obuf[3] ^ obuf[10] ^ obuf[11]; - conv.bytes[2] = obuf[4] ^ obuf[5] ^ obuf[12] ^ obuf[13]; - conv.bytes[3] = obuf[6] ^ obuf[7] ^ obuf[14] ^ obuf[15]; - - return conv.ip; + return IP4Address({ + static_cast(obuf[0] ^ obuf[1] ^ obuf[8] ^ obuf[9]), + static_cast(obuf[2] ^ obuf[3] ^ obuf[10] ^ obuf[11]), + static_cast(obuf[4] ^ obuf[5] ^ obuf[12] ^ obuf[13]), + static_cast(obuf[6] ^ obuf[7] ^ obuf[14] ^ obuf[15]), + }); } -- cgit v1.2.3-60-g2f50