I created a server using sockets that runs on my home network. socket address=192.168.88.123:7777
When I call getaddrinfo() function I put "192.168.88.123" as first parameter and "7777" as second and also some hints (AF_INET, SOCK_STREAM) and pointer to the result linked list. I noticed that in this case I always get linked list with only one structure.
Question: should I think about linked list in such case (when I am working over my own server) or getaddrinfo will always return linked list with one element?
CodePudding user response:
The whole point of getaddrinfo()
is to get a list of IPs.
If you request a specific IP address as input, the resulting list will contain only 1 element for that same IP.
If you request a hostname as input, the resulting list will contain an element for every IP that the hostname resolves to.
If you don't request an IP/hostname at all, the resulting list will depend on whether the AI_PASSIVE
flag is used. If the flag is used, the list will contain elements for 0.0.0.0
and/or ::0
, depending on the ai_family
requested. If the flag is not used, then the list will contain elements for 127.0.0.1
and/or ::1
, depending on the ai_family
requested.