Include linux socket h

why does 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

I am calling Linux system calls directly. I noticed that SOCK_DGRAM is not defined in Linux provided header file. Wanted to know why is it not defined in Linux header files.

As Alnitak says, by POSIX the header is and if you #include that you will have access to the correct defines. DO NOT just look them up and use the numbers.

That’s correct. Macro name may or may not be same as POSIX defined macros. However, those numbers for socket type should be defined in any header files shipped with Linux. Isn’t it?

If you look at «/usr/src/kernels//include/linux/net.h» file, you’ll see the definition for SOCK_DGRAM etc. I wonder why is it not defined in the header files shipped with Linux?

1 Answer 1

User space programs should be using:

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

The fact that some definitions are in and some in is just an implementation detail.

Agree. I am making my own socket library and need to invoke system calls directly. I wonder why socket types are not defined on Linux header files. is an Linux provided header file while is a part of GNU C library. I don’t know why socket types are not defined in Linux provided header files.

Читайте также:  Какие есть виды линукса

@Dew ah, I see what you mean — I suspect the SOCK_* values are defined in some standard somewhere (POSIX?) and should therefore be consistent even if the underlying O/S isn’t Linux.

Yes, the values for SOCK_* are defined by POSIX and should be defined in System Library not in OS provided libs. However, the C run time lib. has to pass socket type to System Call which may be different. The question is how will Library writer be sure about the supported socket types and integer values associated with them? One can’t just assume that constant defined by POSIX for sock type what kernel uses. If yes, somewhere it should be written. Isn’t it?

As far as I understand, the POSIX standard refers to APIs and not to system calls. Socket type an input to socket system call. Thus supported Socket types (as macros) should be exposed by kernel. Isn’t it?

@DewKumar the point is that while the kernel internal values may be different, it would be bloody stupid not to re-use the POSIX defined values.

Источник

Оцените статью
Adblock
detector