get ip addresses
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > get ip addresses




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    get ip addresses  
vertigo


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-02-04 11:51 PM

Hello
I want to read all ip addresses connected with local machine. I did:

if  (gethostname(hostname,MAX_STRING_SIZE)!=
0){
exit(0);
}
struct hostent *h=gethostbyname((const char*)hostname);
int n=0;
for (char** ptr=h->h_addr_list; *ptr; ++ptr,n++){
printf("%s\n",inet_ntoa(*(struct in_addr*)h->h_addr_list[n]));
}

but i received only one ip address connected with eth0.
Morover on freebsd i received only 127.0.0.1.
What about aliases ? On linux i have eth0:1 and i did not received
that ip this way.
Where's my mistake ?

Thanx
Michal






[ Post a follow-up to this message ]



    Re: get ip addresses  
Fletcher Glenn


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-02-04 11:51 PM


"vertigo" <none@dev.null> wrote in message
news:ch79d8$ert$1@atlantis.news.tpi.pl...
> Hello
> I want to read all ip addresses connected with local machine. I did:
>
>      if  (gethostname(hostname,MAX_STRING_SIZE)!=
0){
>          exit(0);
>      }
>      struct hostent *h=gethostbyname((const char*)hostname);
>      int n=0;
>      for (char** ptr=h->h_addr_list; *ptr; ++ptr,n++){
>          printf("%s\n",inet_ntoa(*(struct in_addr*)h->h_addr_list[n]))
;
>      }
>
> but i received only one ip address connected with eth0.
> Morover on freebsd i received only 127.0.0.1.
> What about aliases ? On linux i have eth0:1 and i did not received
> that ip this way.
> Where's my mistake ?
>
> Thanx
> Michal
>

The program "netstat" knows how to get the answer.  Try looking at the
FreeBSD source for netstat.  I'm sure you can get some hints from that.
However, whenever you're looking for information about stuff that is not
part of your own process, be prepared to have to be root in order to get the
info.

--

Fletcher Glenn







[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 10:00 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register