Why include multiple headers for a single POSIX function?

According to the man page getaddrinfo(3)I need

#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>

use function getaddrinfo. Or, according to the standard :

#include <sys/socket.h>
#include <netdb.h>

I understand, I need things like AF_INETand SOCK_STEAMfrom <sys/socket.h>. But I still have the following questions.

Suppose I will only use a function getaddrinfo, should I have a #include <sys/socket.h>standard match? If so, why <netdb.h>not include it yourself? If not, why does this man page contain a summary of it?

+4
source share
1 answer

, getaddrinfo , netdb.h. getnameinfo NI_NUMERICHOST, (), . - netdb.h.

, , , (sys/socket.h). , sys/socket.h. , , , , ( ) getaddrinfo.

sys/types.h, , Linux. sys/types.h , , , .

+5

Source: https://habr.com/ru/post/1650107/


All Articles