public inbox for libc-help@sourceware.org
 help / color / mirror / Atom feed
* Where is setsockopt() defined?
@ 2021-03-02 20:52 Peng Yu
  2021-03-02 21:30 ` Florian Weimer
  0 siblings, 1 reply; 4+ messages in thread
From: Peng Yu @ 2021-03-02 20:52 UTC (permalink / raw)
  To: libc-help

https://github.com/bminor/glibc/blob/21c3f4b5368686ade28d90d8c7d79c4c95c72c1b/socket/sys/socket.h#L215

I see setsockopt() is declared above. But I don't find its source
code. Where is it defined? Thanks.

https://github.com/bminor/glibc/blob/21c3f4b5368686ade28d90d8c7d79c4c95c72c1b/socket/setsockopt.c

-- 
Regards,
Peng

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Where is setsockopt() defined?
  2021-03-02 20:52 Where is setsockopt() defined? Peng Yu
@ 2021-03-02 21:30 ` Florian Weimer
  2021-03-03  6:14   ` Peng Yu
  0 siblings, 1 reply; 4+ messages in thread
From: Florian Weimer @ 2021-03-02 21:30 UTC (permalink / raw)
  To: Peng Yu via Libc-help

* Peng Yu via Libc-help:

> https://github.com/bminor/glibc/blob/21c3f4b5368686ade28d90d8c7d79c4c95c72c1b/socket/sys/socket.h#L215
>
> I see setsockopt() is declared above. But I don't find its source
> code. Where is it defined? Thanks.

It's in sysdeps/unix/sysv/linux/setsockopt.c.

Florian


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Where is setsockopt() defined?
  2021-03-02 21:30 ` Florian Weimer
@ 2021-03-03  6:14   ` Peng Yu
  2021-03-03  6:40     ` Konstantin Kharlamov
  0 siblings, 1 reply; 4+ messages in thread
From: Peng Yu @ 2021-03-03  6:14 UTC (permalink / raw)
  To: Florian Weimer; +Cc: Peng Yu via Libc-help

> 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

-- 
Regards,
Peng

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Where is setsockopt() defined?
  2021-03-03  6:14   ` Peng Yu
@ 2021-03-03  6:40     ` Konstantin Kharlamov
  0 siblings, 0 replies; 4+ messages in thread
From: Konstantin Kharlamov @ 2021-03-03  6:40 UTC (permalink / raw)
  To: Peng Yu, Florian Weimer; +Cc: Peng Yu via Libc-help

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.


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-03-03  6:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-02 20:52 Where is setsockopt() defined? Peng Yu
2021-03-02 21:30 ` Florian Weimer
2021-03-03  6:14   ` Peng Yu
2021-03-03  6:40     ` Konstantin Kharlamov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).