From: Bert Hubert Date: Sat, 25 Mar 2006 17:55:54 +0000 (+0000) Subject: provide helpful u32 ip function X-Git-Tag: rec-3-0~133 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5730f30cc28f457dbc32cb936bee4e512086f504;p=pdns provide helpful u32 ip function git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@620 d19b8d6e-7fed-0310-83ef-9ca221ded41b --- diff --git a/pdns/misc.cc b/pdns/misc.cc index af7f78c31..f4d77cbf0 100644 --- a/pdns/misc.cc +++ b/pdns/misc.cc @@ -315,6 +315,17 @@ bool IpToU32(const string &str, uint32_t *ip) return false; } +string U32ToIP(uint32_t val) +{ + char tmp[17]; + snprintf(tmp, sizeof(tmp)-1, "%u.%u.%u.%u", + (val >> 24)&0xff, + (val >> 16)&0xff, + (val >> 8)&0xff, + (val )&0xff); + return tmp; +} + const string sockAddrToString(struct sockaddr_in *remote, Utility::socklen_t socklen) { if(socklen==sizeof(struct sockaddr_in)) { diff --git a/pdns/misc.hh b/pdns/misc.hh index 17b1f4350..13187eb97 100644 --- a/pdns/misc.hh +++ b/pdns/misc.hh @@ -118,6 +118,7 @@ stringtok (Container &container, string const &in, const string toLower(const string &upper); const string toLowerCanonic(const string &upper); bool IpToU32(const string &str, uint32_t *ip); +string U32ToIP(uint32_t); string stringerror(); string itoa(int i); string uitoa(unsigned int i);