LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux > 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
 
Thread Tools
Old 11-07-2009, 11:07 AM   #1
aagajaba
LQ Newbie
 
Registered: Apr 2009
Posts: 7
Thanked: 0
Problem with getaddrinfo() function


[Log in to get rid of this advertisement]
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>
linuxfedora aagajaba is offline     Reply With Quote
Old 11-07-2009, 11:55 AM   #2
ammorais
Member
 
Registered: Nov 2009
Location: Lisbon, Portugal
Distribution: Gentoo, CentOs, Ubuntu
Posts: 95
Thanked: 16
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.
linuxubuntu ammorais is offline     Reply With Quote
Old 11-08-2009, 03:20 AM   #3
aagajaba
LQ Newbie
 
Registered: Apr 2009
Posts: 7
Thanked: 0

Original Poster
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
linuxfedora aagajaba is offline     Reply With Quote

Reply

Bookmarks


Thread Tools

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


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


All times are GMT -5. The time now is 03:01 AM.

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
RSS2  LQ Podcast
RSS2  LQ Radio
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration