Dew Kumar
Dew Kumar

Reputation: 173

why does <linux/socket.h> file not define socket types?

The Linux provided header file "/usr/include/linux/socket.h" contains definitions for Supported address families and Protocol families:

/* Supported address families. */
#define AF_UNSPEC       0
....

/* Protocol families, same as address families. */
#define PF_UNSPEC       AF_UNSPEC
...

But why does it not define socket types?

I can find it's definition in "/usr/include/bits/socket.h" as

enum sock_type {
    SOCK_DGRAM  = 1,
    SOCK_STREAM = 2,
    SOCK_RAW    = 3,
    SOCK_RDM    = 4,
    SOCK_SEQPACKET  = 5,
    SOCK_DCCP   = 6,
    SOCK_PACKET = 10,
};

I wonder why these are not defined in the header file provided by Linux?

Upvotes: 2

Views: 3478

Answers (1)

Alnitak
Alnitak

Reputation: 339816

User space programs should be using:

#include <sys/socket.h>

NB: sys, not linux.

This will then #include the appropriate low level header files.

The fact that some definitions are in <bits/socket.h> and some in <linux/socket.h> is just an implementation detail.

Upvotes: 5

Related Questions