LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 11-07-2009, 10:07 AM   #1
aagajaba
LQ Newbie
 
Registered: Apr 2009
Posts: 7

Rep: Reputation: 0
Problem with getaddrinfo() function


I am new to network programming.
I just copied the code from Beej's Guide, to fill in the addrinfo structure using getaddrinfo.
It said that if I have hints.ai_flags-AI_PASSIVE and NULL in the first argument of getaddrinfo, i'll get a linked list of structures suitable for binding some port, i.e. my own ip address will be filled.
So 127.0.0.1 (loopback address) should be filled.
But when I see the value, it is giving 0.0.0.0

<code>

char address[100];
struct addrinfo hints, *res,*first;
int sockfd;
// first, load up address structs with getaddrinfo():
memset(&hints, 0, sizeof hints);
hints.ai_family = AF_UNSPEC; // use IPv4 or IPv6, whichever
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_PASSIVE;
// fill in my IP for me
getaddrinfo(NULL, "3490", &hints, &res);
first=res;
// make a socket:
sockfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
inet_ntop(first->ai_family,&(((struct sockaddr_in *)(first->ai_addr))->sin_addr),address,100);
perror("inet_ntop");
printf("%s\n",address);
printf("%d\n",first->ai_protocol);
printf("%hu\n",ntohs(((struct sockaddr_in *)(first->ai_addr))->sin_port));
</code>
 
Old 11-07-2009, 10:55 AM   #2
ammorais
Member
 
Registered: Nov 2009
Location: Lisbon, Portugal
Distribution: Gentoo, CentOs, Ubuntu, Debian
Posts: 182

Rep: Reputation: 49
The server side has bound all addresses via 0.0.0.0 or :: in the case of IPV6
This include the localhost address 127.0.0.1

You can test it by:
Code:
netstat -t -a -n -p | grep 0.0.0.0
Resuming. It's normal, and the output is correct.
 
Old 11-08-2009, 02:20 AM   #3
aagajaba
LQ Newbie
 
Registered: Apr 2009
Posts: 7

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by ammorais View Post
The server side has bound all addresses via 0.0.0.0 or :: in the case of IPV6
This include the localhost address 127.0.0.1

You can test it by:
Code:
netstat -t -a -n -p | grep 0.0.0.0
Resuming. It's normal, and the output is correct.
Thanx. I got it.
Can u just tell me what all ip addresses 0.0.0.0 include in addition to 127.0.0.1
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
getaddrinfo - Segmentation fault gursoz Linux - Networking 5 11-26-2009 01:34 AM
reverse mapping checking getaddrinfo failed when ssh to newly named host jspeaks Linux - Newbie 1 10-06-2009 11:15 AM
Glibc warning concerning use of getaddrinfo() in static library dwhitney67 Programming 3 06-19-2009 01:43 PM
/etc/hosts and getaddrinfo() parthaswathi Linux - Networking 3 05-17-2007 03:48 PM
Sockets : Getaddrinfo call fails abrb220 Programming 2 06-06-2004 11:26 PM


All times are GMT -5. The time now is 07:52 PM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration