{code} -#ifndef CONDOR_IPADDRESS_H -#define CONDOR_IPADDRESS_H - class ipaddr { sockaddr_in6 storage; - const unsigned char* get_addr() const { - // field name of in6_addr is different from platform to platform - return (const unsigned char*)&storage.sin6_addr; - } - - unsigned char* get_addr() { - // field name of in6_addr is different from platform to platform - return (unsigned char*)&storage.sin6_addr; - } + const unsigned char* get_addr() const; + unsigned char* get_addr(); - unsigned int& get_addr_header() { return *(unsigned int*)get_addr(); } - const unsigned int& get_v4_addr() const { return *(const unsigned int*)(get_addr()+12); } - unsigned int& get_v4_addr() { return *(unsigned int*)(get_addr()+12); } + unsigned int& get_addr_header(); + const unsigned int& get_v4_addr() const; + unsigned int& get_v4_addr(); public: - ipaddr() - { - memset(&storage, 0, sizeof(storage)); - } + // accepts network byte ordered ip and port + void init(int ip, unsigned port); - ipaddr(int ip, unsigned port = 0) - { ipaddr(); - storage.sin6_family = AF_INET; - storage.sin6_port = htons(port); - // IPv4-mapped region - get_addr_header() = 0xffff0000; - get_v4_addr() = (unsigned int)ip; - } - - ipaddr(in_addr ip, unsigned port = 0) - { - ipaddr(ip.s_addr, port); - } - ipaddr(sockaddr_in* sin) - { - ipaddr(sin->sin_addr, sin->sin_port); - } - - ipaddr(sockaddr_in6* sin6) - { - storage = *sin6; - } - - sockaddr_in to_sin() const - { - sockaddr_in ret; - memset(&ret, 0, sizeof(ret)); - if (!is_ipv4()) { - // error.. - return ret; - } - - ret.sin_family = AF_INET; - ret.sin_port = storage.sin6_port; - ret.sin_addr.s_addr = get_v4_addr(); - } - - const sockaddr_in6& to_sin6() const - { - return storage; - } - - bool is_ipv4() const - { - return storage.sin6_family == AF_INET; - } + // ip address is always network byte order but port is not. + ipaddr(int ip, unsigned port = 0); + ipaddr(in_addr ip, unsigned port = 0); + ipaddr(const in6_addr& in6, unsigned port = 0); + ipaddr(sockaddr_in* sin) ; + ipaddr(sockaddr_in6* sin6); + + sockaddr_in to_sin() const; + const sockaddr_in6& to_sin6() const; + bool is_ipv4() const; }; -#endif - {endcode} As you see here, sockaddr_in6 is super-set of sockaddr_in. So, this implementation considers IPv6 as basis and providing compatibility to IPv4 usage. @@ -206,6 +156,22 @@ In bottom line, I recommend you to have class IpAddr (which is basically sockaddr_in6 with helper functions) even you only want IP address. +{section: Make configure for IPv6 support} + +When creating sockets and binding to local address, you need to specify whether it is IPv4 or IPv6. To supply these parameters, I am considering to use ifdef for C/C++ source codes. + +{code} + +#ifdef CONDOR_IPV6_SUPPORT +fd = socket(AF_INET6, ...); +#else +fd = socket(AF_INET,...); +#endif + +Let's find a way to configure it. It may be done by using "configure" script. + +{endcode} + {section: Condor NO_DNS option} In Condor, NO_DNS option eliminates its dependency to Domain Name System. According to condor_netdb.c @@ -465,3 +431,4 @@ ... (omissioned) ... Jan, 25 : tackling with inet_ntoa Jan, 26 : completed condor_inet_pton and wrote unit test. +Jan, 28 : tackling with internet.c, mostly is_ip_addr related.