Networking Forums

Networking Forums > Computer Networking > Linux Networking > can't get multi-homed host address using getaddrinfo() Options

Reply
Thread Tools Display Modes

can't get multi-homed host address using getaddrinfo() Options

 
 
Arthur
Guest
Posts: n/a

 
      07-17-2007, 01:52 AM
I'm using getaddrinfo("test.domain.com", NULL, &hint, &info) to
get IP addresses.

Below is /etc/hosts:
....
10.200.28.120 test.domain.com
172.0.20.120 test.domain.com
....

The problem is getaddrinfo always return only one IP address
10.200.28.120. From the man page, I think I should get a address
linked list
that mean I can get both.

Please see my demo code below:
int main()
{
struct addrinfo hints;
struct addrinfo *info;
int s;
memset((char*) &hints, '\0', sizeof(hints));
hints.ai_family = AF_INET; // just IPv4 for now
hints.ai_socktype = SOCK_STREAM; // just TCP
s = getaddrinfo("test.domain.com", NULL, &hints, &info);
if (s != 0) { printf ("error\n"); }
printf ("ok\n");
return 0;
}

I have checked info->ai_next with gdb, it's always NULL. Is there
anything wrong in my demo code? My platform it RHEL 4.0.

BTW: This demo code can get the right result on Solaris.

Thanks

Arthur

 
Reply With Quote
 
 
 
 
Doug Laidlaw
Guest
Posts: n/a

 
      07-19-2007, 12:32 AM
Arthur wrote:

> I'm using getaddrinfo("test.domain.com", NULL, &hint, &info) to
> get IP addresses.
>
> Below is /etc/hosts:
> ...
> 10.200.28.120 test.domain.com
> 172.0.20.120 test.domain.com
> ...
>
> The problem is getaddrinfo always return only one IP address
> 10.200.28.120. From the man page, I think I should get a address
> linked list
> that mean I can get both.
>
> Please see my demo code below:
> int main()
> {
> struct addrinfo hints;
> struct addrinfo *info;
> int s;
> memset((char*) &hints, '\0', sizeof(hints));
> hints.ai_family = AF_INET; // just IPv4 for now
> hints.ai_socktype = SOCK_STREAM; // just TCP
> s = getaddrinfo("test.domain.com", NULL, &hints, &info);
> if (s != 0) { printf ("error\n"); }
> printf ("ok\n");
> return 0;
> }
>
> I have checked info->ai_next with gdb, it's always NULL. Is there
> anything wrong in my demo code? My platform it RHEL 4.0.
>
> BTW: This demo code can get the right result on Solaris.
>
> Thanks
>
> Arthur


Can one domain have two addresses? I think that the multiple addresses that
ISPs use all have slightly different domain names (for example,
hotkey.net.au is boomer.hotkey.net.au. Another IP is frog. Something else
is duckula.) and are linked to one another. But I don't really know.

Doug.
--
Orthodoxy is my doxy; heterodoxy is your doxy.
- Wm Warburton, 18th c. Bishop of Gloucester.

 
Reply With Quote
 
Philippe WEILL
Guest
Posts: n/a

 
      07-20-2007, 09:02 AM


Doug Laidlaw wrote:
> Arthur wrote:
>
>> I'm using getaddrinfo("test.domain.com", NULL, &hint, &info) to
>> get IP addresses.
>>
>> Below is /etc/hosts:
>> ...
>> 10.200.28.120 test.domain.com
>> 172.0.20.120 test.domain.com
>> ...
>>
>> The problem is getaddrinfo always return only one IP address
>> 10.200.28.120. From the man page, I think I should get a address
>> linked list
>> that mean I can get both.
>>
>> Please see my demo code below:
>> int main()
>> {
>> struct addrinfo hints;
>> struct addrinfo *info;
>> int s;
>> memset((char*) &hints, '\0', sizeof(hints));
>> hints.ai_family = AF_INET; // just IPv4 for now
>> hints.ai_socktype = SOCK_STREAM; // just TCP
>> s = getaddrinfo("test.domain.com", NULL, &hints, &info);
>> if (s != 0) { printf ("error\n"); }
>> printf ("ok\n");
>> return 0;
>> }
>>
>> I have checked info->ai_next with gdb, it's always NULL. Is there
>> anything wrong in my demo code? My platform it RHEL 4.0.
>>
>> BTW: This demo code can get the right result on Solaris.
>>
>> Thanks
>>
>> Arthur

>
> Can one domain have two addresses?

yes

host www.google.com
www.google.com is an alias for www.l.google.com.
www.l.google.com has address 209.85.129.147
www.l.google.com has address 209.85.129.99
www.l.google.com has address 209.85.129.104
www.google.com is an alias for www.l.google.com.


> I think that the multiple addresses that
> ISPs use all have slightly different domain names (for example,
> hotkey.net.au is boomer.hotkey.net.au. Another IP is frog. Something else
> is duckula.) and are linked to one another. But I don't really know.
>
> Doug.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Change DC from multi-homed to single homed segmented Terry Windows Networking 7 03-01-2007 06:13 PM
3 multi-homed phwashington@comcast.net Linux Networking 7 03-01-2006 04:40 AM
multi-homed lph Windows Networking 7 07-07-2004 05:27 PM
Multi-homed server and VPN NeoAdmin Windows Networking 5 04-28-2004 03:52 PM
Multi-homed Server Samuel Shum Windows Networking 9 12-17-2003 07:11 AM



1 2 3 4 5 6 7 8 9 10 11