version 1.52, 2007/06/26 20:26:13
|
version 1.53, 2007/07/10 19:59:55
|
|
|
// Get all ip addresses on the node and compare them with the given hostname. | // Get all ip addresses on the node and compare them with the given hostname. |
#ifdef PEGASUS_ENABLE_IPV6 | #ifdef PEGASUS_ENABLE_IPV6 |
CString csName = hostName.getCString(); | CString csName = hostName.getCString(); |
struct addrinfo hints, *res1, *res2; |
struct addrinfo hints, *res1, *res2, *res1root, *res2root; |
char localHostName[PEGASUS_MAXHOSTNAMELEN]; | char localHostName[PEGASUS_MAXHOSTNAMELEN]; |
gethostname(localHostName, PEGASUS_MAXHOSTNAMELEN); | gethostname(localHostName, PEGASUS_MAXHOSTNAMELEN); |
Boolean isLocal = false; | Boolean isLocal = false; |
|
|
hints.ai_family = AF_INET; | hints.ai_family = AF_INET; |
hints.ai_socktype = SOCK_STREAM; | hints.ai_socktype = SOCK_STREAM; |
hints.ai_protocol = IPPROTO_TCP; | hints.ai_protocol = IPPROTO_TCP; |
res1 = res2 = 0; |
res1root = res2root = 0; |
getaddrinfo(csName, 0, &hints, &res1); |
getaddrinfo(csName, 0, &hints, &res1root); |
getaddrinfo(localHostName, 0, &hints, &res2); |
getaddrinfo(localHostName, 0, &hints, &res2root); |
| |
|
res1 = res1root; |
while (res1 && !isLocal) | while (res1 && !isLocal) |
{ | { |
if (isLoopBack(AF_INET, | if (isLoopBack(AF_INET, |
|
|
break; | break; |
} | } |
| |
struct addrinfo *tmp = res2; |
res2 = res2root; |
while (tmp) |
while (res2) |
{ | { |
if (!memcmp(&((struct sockaddr_in*)res1->ai_addr)->sin_addr, | if (!memcmp(&((struct sockaddr_in*)res1->ai_addr)->sin_addr, |
&((struct sockaddr_in*)res2->ai_addr)->sin_addr, | &((struct sockaddr_in*)res2->ai_addr)->sin_addr, |
|
|
isLocal = true; | isLocal = true; |
break; | break; |
} | } |
tmp = tmp->ai_next; |
res2 = res2->ai_next; |
} | } |
res1 = res1->ai_next; | res1 = res1->ai_next; |
} | } |
freeaddrinfo(res1); |
freeaddrinfo(res1root); |
freeaddrinfo(res2); |
freeaddrinfo(res2root); |
if (isLocal) | if (isLocal) |
{ | { |
return true; | return true; |
} | } |
| |
hints.ai_family = AF_INET6; | hints.ai_family = AF_INET6; |
res1 = res2 = 0; |
res1root = res2root = 0; |
getaddrinfo(csName, 0, &hints, &res1); |
getaddrinfo(csName, 0, &hints, &res1root); |
getaddrinfo(localHostName, 0, &hints, &res2); |
getaddrinfo(localHostName, 0, &hints, &res2root); |
|
|
|
res1 = res1root; |
while (res1 && !isLocal) | while (res1 && !isLocal) |
{ | { |
if (isLoopBack(AF_INET6, | if (isLoopBack(AF_INET6, |
|
|
break; | break; |
} | } |
| |
struct addrinfo *tmp = res2; |
res2 = res2root; |
while (tmp) |
while (res2) |
{ | { |
if (!memcmp(&((struct sockaddr_in6*)res1->ai_addr)->sin6_addr, | if (!memcmp(&((struct sockaddr_in6*)res1->ai_addr)->sin6_addr, |
&((struct sockaddr_in6*)res2->ai_addr)->sin6_addr, | &((struct sockaddr_in6*)res2->ai_addr)->sin6_addr, |
|
|
isLocal = true; | isLocal = true; |
break; | break; |
} | } |
tmp = tmp->ai_next; |
res2 = res2->ai_next; |
} | } |
res1 = res1->ai_next; | res1 = res1->ai_next; |
} | } |
freeaddrinfo(res1); |
freeaddrinfo(res1root); |
freeaddrinfo(res2); |
freeaddrinfo(res2root); |
| |
return isLocal; | return isLocal; |
#else | #else |