Linux - NetworkingThis forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
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>
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.