Where is setsockopt() defined?

Konstantin Kharlamov hi-angel@yandex.ru
Wed Mar 3 06:40:15 GMT 2021


On Wed, 2021-03-03 at 00:14 -0600, Peng Yu via Libc-help wrote:
> > It's in sysdeps/unix/sysv/linux/setsockopt.c.
> 
> https://github.com/bminor/glibc/blob/21c3f4b5368686ade28d90d8c7d79c4c95c72c1b/sysdeps/unix/sysv/linux/setsockopt.c
> 
> There is not much code in this file. Based on the manpage of
> setsockopt() (which refers to socket(7)), setsockopt() should be able
> to process many different cases. So I'd expect many branch statements.
> Where are they defined?
> 
> Things like INLINE_SYSCALL and SOCKETCALL are too complicated to
> comprehend. How to understand what they do?
> 
> https://github.com/bminor/glibc/blob/21c3f4b5368686ade28d90d8c7d79c4c95c72c1b/sysdeps/unix/sysv/linux/sysdep.h#L42
> https://github.com/bminor/glibc/blob/83908b3a1ea51e3aa7ff422275940e56dbba989f/sysdeps/unix/sysv/linux/socketcall.h#L85


(disclaimer: I'm not a glibc dev)

The INLINE_SYSCALL as it name says is apparently syscall. A syscall simply places its arguments into registers/stack as defined by the architecture and calls into kernel.

The SOCKETCALL version indeed looks involved, but as far I as see it just basically chooses between __SOCKETCALL1..__SOCKETCALL6 macroses based on the number of arguments. And all 6 of those, in turn, are a wrapper around INLINE_SYSCALL.

So, all roads lead to Rome aka kernel.



More information about the Libc-help mailing list