What's the "hints" mean for the addrinfo name in socket programming

From the FreeBSD man page:

hints is an optional pointer to a struct addrinfo, as defined by <netdb.h> ... This structure can be used to provide hints concerning the type of socket that the caller supports or wishes to use.

It's called "hints" because it can be used to provide, well, hints (in the sense of a tip; a suggestion that might come in useful but could be ignored). This indicates things like what protocol family (IPv4 vs. IPv6, for example) the caller wants, what socket type (datagram vs. straming), what protocol (TCP vs. UDP), etc. You can pass NULL in for hints and thus indicate that you don't care what protocol family, socket type, or protocol you get back.


From http://linux.die.net/man/3/getaddrinfo

The hints parameter specifies the preferred socket type, or protocol. A NULL hints specifies that any network address or protocol is acceptable. If this parameter is not NULL it points to an addrinfo structure whose ai_family, ai_socktype, and ai_protocol members specify the preferred socket type. AF_UNSPEC in ai_family specifies any protocol family (either IPv4 or IPv6, for example). 0 in ai_socktype or ai_protocol specifies that any socket type or protocol is acceptable as well. The ai_flags member specifies additional options, defined below. Multiple flags are specified by logically OR-ing them together. All the other members in the hints parameter must contain either 0, or a null pointer.

Tags:

C

Sockets