From: Aki Tuomi Date: Wed, 5 Nov 2014 10:05:29 +0000 (+0200) Subject: Allow changing the Sockaddr in ComboAddress X-Git-Tag: auth-3.4.2~10^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5b58a443baa1c1217a70e9253b1689579c10e65d;p=pdns Allow changing the Sockaddr in ComboAddress (cherry picked from commit a7360cd9e1daeb99e0d0632b807e90fc34bedb65) --- diff --git a/pdns/iputils.hh b/pdns/iputils.hh index 9d0aa9375..c7e081488 100644 --- a/pdns/iputils.hh +++ b/pdns/iputils.hh @@ -110,6 +110,23 @@ union ComboAddress { sin4.sin_port=0; } + ComboAddress(const struct sockaddr *sa, socklen_t salen) { + setSockaddr(sa, salen); + }; + + ComboAddress(const struct sockaddr_in6 *sa) { + setSockaddr((const struct sockaddr*)sa, sizeof(struct sockaddr_in6)); + }; + + ComboAddress(const struct sockaddr_in *sa) { + setSockaddr((const struct sockaddr*)sa, sizeof(struct sockaddr_in)); + }; + + void setSockaddr(const struct sockaddr *sa, socklen_t salen) { + if (salen > sizeof(struct sockaddr_in6)) throw PDNSException("ComboAddress can't handle other than sockaddr_in or sockaddr_in6"); + memcpy(this, sa, salen); + } + // 'port' sets a default value in case 'str' does not set a port explicit ComboAddress(const string& str, uint16_t port=0) {