-1

man getaddrinfo:

 int getaddrinfo(const char *node, const char *service,
                       const struct addrinfo *hints,
                       struct addrinfo **res);

Either node or service, but not both, may be NULL.

Specifying node only is comprehensible, then it gives you all the available services related to one particular host. But what does it mean if only specify a service without a node/host ? Scanning all hosts in the Web ?

1

Specifying node only is comprehensible, then it gives you all the available services related to one particular host.

Absolutely not. If the service is NULL, the returned addrinfo structs will have the port/service set to 0, it will not return a struct for each service available on the host.

But what does it mean if only specify a service without a node/host?

If AI_PASSIVE is not specified in .ai_flags, it will return the address of the loop device (127.0.0.1 for ipv4, ::1 for ipv6).

If AI_PASSIVE is specified, it will return the "wildcard" address (0.0.0.0 for ipv4, :: for ipv6).

You can read the whole thing in the standard, in the paragraph starting with "If the AI_PASSIVE flag is specified ...".

Everything is also clearly stated in the manpage you quote from.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.