From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fa528,b308574f9841b3bf X-Google-Attributes: gidfa528,public X-Google-ArrivalTime: 2004-04-23 06:04:41 PST Path: archiver1.google.com!postnews1.google.com!not-for-mail From: calista_heart@yahoo.com (Calista) Newsgroups: comp.unix.tru64 Subject: Re: gethostbyname returns only single IP address Date: 23 Apr 2004 06:04:41 -0700 Organization: http://groups.google.com Message-ID: <5d1678ff.0404230504.2eb35ac4@posting.google.com> References: <5d1678ff.0404220743.37a2d7e1@posting.google.com> <2as96c.7gf.ln@dadsys2.fuller.local> NNTP-Posting-Host: 208.42.8.141 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1082725481 385 127.0.0.1 (23 Apr 2004 13:04:41 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 23 Apr 2004 13:04:41 +0000 (UTC) Xref: archiver1.google.com comp.unix.tru64:11380 hostname is passed to this function. if ((hp = gethostbyname(hostname)) <= (struct hostent *)0 return -1; for( i = 0; i < 4; i++ ) { /* I can have max 4 ip addresses */ if( hp->h_addr_list[i] == NULL ) break; memzero (&sin, sizeof(sin)); memcpy (hp->h_addr_list[i], &sin.sin_addr, hp->h_length); sin.sin_family = hp->h_addrtype; /* Get IP address. */ strncpy( ipaddress[i], inet_ntoa(sin.sin_addr), length ); /* take care of NULL character at end in ipaddress[i] */ } Now I print all IP addresses. It prints only one IP address although my machine has multiple interfaces (two ip addresses). Let me know if you need more info. Calista. Stuart Fuller wrote in message news:<2as96c.7gf.ln@dadsys2.fuller.local>... > Calista wrote: > > > Hi, > > > > I use gethostbyname() to get all the IP addresses on my machine. But > > it only returns the first one in /etc/hosts file. > > > > Should I do anything different? > > > > Post exactly what you're doing, what you expect to see, and what you're > seeing.