diff options
author | Ben Longbons <b.r.longbons@gmail.com> | 2012-08-30 17:37:27 -0700 |
---|---|---|
committer | Ben Longbons <b.r.longbons@gmail.com> | 2012-09-03 16:23:10 -0700 |
commit | 31544d2b6973931be7fdec898ea3672bea831de2 (patch) | |
tree | dcf946429b406f39297404be662b0a840094e477 /src/common/md5calc.cpp | |
parent | 41974ae5265fbc23a06f276f9e008d5dad020e0b (diff) | |
download | tmwa-31544d2b6973931be7fdec898ea3672bea831de2.tar.gz tmwa-31544d2b6973931be7fdec898ea3672bea831de2.tar.bz2 tmwa-31544d2b6973931be7fdec898ea3672bea831de2.tar.xz tmwa-31544d2b6973931be7fdec898ea3672bea831de2.zip |
Fix compiler errors of C++ conversion
Diffstat (limited to 'src/common/md5calc.cpp')
-rw-r--r-- | src/common/md5calc.cpp | 23 |
1 files changed, 9 insertions, 14 deletions
diff --git a/src/common/md5calc.cpp b/src/common/md5calc.cpp index f00861d..b0f8e5f 100644 --- a/src/common/md5calc.cpp +++ b/src/common/md5calc.cpp @@ -309,31 +309,26 @@ bool pass_ok(const char *password, const char *crypted) { // [M|h]ashes up an IP address and a secret key // to return a hopefully unique masked IP. -in_addr_t MD5_ip(char *secret, in_addr_t ip) +struct in_addr MD5_ip(char *secret, struct in_addr ip) { char ipbuf[32]; uint8_t obuf[16]; union { - struct bytes { - uint8_t b1; - uint8_t b2; - uint8_t b3; - uint8_t b4; - } bytes; - in_addr_t ip; + uint8_t bytes[4]; + struct in_addr ip; } conv; // MD5sum a secret + the IP address memset(&ipbuf, 0, sizeof(ipbuf)); - snprintf(ipbuf, sizeof(ipbuf), "%lu%s", (unsigned long)ip, secret); + snprintf(ipbuf, sizeof(ipbuf), "%u%s", ip.s_addr, secret); /// TODO stop it from being a cstring MD5_to_bin(MD5_from_cstring(ipbuf), obuf); - // Fold the md5sum to 32 bits, pack the bytes to an in_addr_t - conv.bytes.b1 = obuf[0] ^ obuf[1] ^ obuf[8] ^ obuf[9]; - conv.bytes.b2 = obuf[2] ^ obuf[3] ^ obuf[10] ^ obuf[11]; - conv.bytes.b3 = obuf[4] ^ obuf[5] ^ obuf[12] ^ obuf[13]; - conv.bytes.b4 = obuf[6] ^ obuf[7] ^ obuf[14] ^ obuf[15]; + // 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; } |