diff options
author | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2006-08-03 17:14:13 +0000 |
---|---|---|
committer | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2006-08-03 17:14:13 +0000 |
commit | ca70ad77509b6756228ab168b7e5d381f49a7ccc (patch) | |
tree | 6b3cfe5f52b1541d79dcecb4bd23f9ab877543cf | |
parent | f16930668a928471847cd327e1edc69b6d27b979 (diff) |
Improved ip6.int builder (no more HUGE sprintf craq)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@4678 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r-- | src/dns.cpp | 47 |
1 files changed, 13 insertions, 34 deletions
diff --git a/src/dns.cpp b/src/dns.cpp index 9788284b7..fac10d98e 100644 --- a/src/dns.cpp +++ b/src/dns.cpp @@ -425,40 +425,19 @@ int DNS::GetName(const insp_inaddr *ip) void DNS::MakeIP6Int(char* query, const in6_addr *ip) { - sprintf(query,"%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.ip6.int", - ip->s6_addr[15] & 0x0f, - (ip->s6_addr[15] & 0xf0) >> 4, - ip->s6_addr[14] & 0x0f, - (ip->s6_addr[14] & 0xf0) >> 4, - ip->s6_addr[13] & 0x0f, - (ip->s6_addr[13] & 0xf0) >> 4, - ip->s6_addr[12] & 0x0f, - (ip->s6_addr[12] & 0xf0) >> 4, - ip->s6_addr[11] & 0x0f, - (ip->s6_addr[11] & 0xf0) >> 4, - ip->s6_addr[10] & 0x0f, - (ip->s6_addr[10] & 0xf0) >> 4, - ip->s6_addr[9] & 0x0f, - (ip->s6_addr[9] & 0xf0) >> 4, - ip->s6_addr[8] & 0x0f, - (ip->s6_addr[8] & 0xf0) >> 4, - ip->s6_addr[7] & 0x0f, - (ip->s6_addr[7] & 0xf0) >> 4, - ip->s6_addr[6] & 0x0f, - (ip->s6_addr[6] & 0xf0) >> 4, - ip->s6_addr[5] & 0x0f, - (ip->s6_addr[5] & 0xf0) >> 4, - ip->s6_addr[4] & 0x0f, - (ip->s6_addr[4] & 0xf0) >> 4, - ip->s6_addr[3] & 0x0f, - (ip->s6_addr[3] & 0xf0) >> 4, - ip->s6_addr[2] & 0x0f, - (ip->s6_addr[2] & 0xf0) >> 4, - ip->s6_addr[1] & 0x0f, - (ip->s6_addr[1] & 0xf0) >> 4, - ip->s6_addr[0] & 0x0f, - (ip->s6_addr[0] & 0xf0) >> 4 - ); + const char* hex = "0123456789abcdef"; + int step = 31; /* 32 nibbles, 0..31 */ + for (int index = 15; index > -1; (!(step-- % 2) ? index-- : index = index)) /* for() loop steps twice per byte */ + { + if (step % 2) + /* low nibble */ + *query++ = hex[ip->s6_addr[index] & 0x0F]; + else + /* high nibble */ + *query++ = hex[(ip->s6_addr[index] & 0xF0) >> 4]; + *query++ = '.'; /* Seperator */ + } + strcpy(query,"ip6.int"); /* Suffix the string */ } /* Return the next id which is ready, and the result attached to it */ |