diff options
author | Adam Ierymenko <adam.ierymenko@gmail.com> | 2014-01-31 15:55:45 -0800 |
---|---|---|
committer | Adam Ierymenko <adam.ierymenko@gmail.com> | 2014-01-31 15:55:45 -0800 |
commit | 64231aa3f0e4dd7cf90fa3a5b8c555f9f39b137b (patch) | |
tree | d4593edea0a1284575efa3479ed3f40b124ad840 /node/InetAddress.hpp | |
parent | 117e6fb356aa6c523ce6fa097e15987e1a943994 (diff) | |
download | infinitytier-64231aa3f0e4dd7cf90fa3a5b8c555f9f39b137b.tar.gz infinitytier-64231aa3f0e4dd7cf90fa3a5b8c555f9f39b137b.zip |
Fix for GitHub issue #36 on OSX... results in a duplicate entry for IPv6 link-local but seems okay... need to test on OSX 10.6 though.
Diffstat (limited to 'node/InetAddress.hpp')
-rw-r--r-- | node/InetAddress.hpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/node/InetAddress.hpp b/node/InetAddress.hpp index 49729017..9c10dfc6 100644 --- a/node/InetAddress.hpp +++ b/node/InetAddress.hpp @@ -36,6 +36,7 @@ #include "Constants.hpp" #include "Utils.hpp" +#include "MAC.hpp" #ifdef __WINDOWS__ #include <WinSock2.h> @@ -387,6 +388,35 @@ public: _sa.saddr.sa_family = 0; } + /** + * @param mac MAC address seed + * @return IPv6 link-local address + */ + static inline InetAddress makeIpv6LinkLocal(const MAC &mac) + throw() + { + InetAddress ip; + ip._sa.saddr.sa_family = AF_INET6; + ip._sa.sin6.sin6_addr.s6_addr[0] = 0xfe; + ip._sa.sin6.sin6_addr.s6_addr[1] = 0x80; + ip._sa.sin6.sin6_addr.s6_addr[2] = 0x00; + ip._sa.sin6.sin6_addr.s6_addr[3] = 0x00; + ip._sa.sin6.sin6_addr.s6_addr[4] = 0x00; + ip._sa.sin6.sin6_addr.s6_addr[5] = 0x00; + ip._sa.sin6.sin6_addr.s6_addr[6] = 0x00; + ip._sa.sin6.sin6_addr.s6_addr[7] = 0x00; + ip._sa.sin6.sin6_addr.s6_addr[8] = mac.data[0] & 0xfd; + ip._sa.sin6.sin6_addr.s6_addr[9] = mac.data[1]; + ip._sa.sin6.sin6_addr.s6_addr[10] = mac.data[2]; + ip._sa.sin6.sin6_addr.s6_addr[11] = 0xff; + ip._sa.sin6.sin6_addr.s6_addr[12] = 0xfe; + ip._sa.sin6.sin6_addr.s6_addr[13] = mac.data[3]; + ip._sa.sin6.sin6_addr.s6_addr[14] = mac.data[4]; + ip._sa.sin6.sin6_addr.s6_addr[15] = mac.data[5]; + ip._sa.sin6.sin6_port = Utils::hton((uint16_t)64); + return ip; + } + private: union { struct sockaddr saddr; |