How to increase net.core.rmem_max value by c code

2019-09-14 04:06发布

问题:

This question already has an answer here:

  • How to increase net.core.rmem_max value from c code 2 answers

I tried to increase the value SO_RCVBUF using

getsockopt(udp_fd, SOL_SOCKET, SO_RCVBUF, &rcvBufferSize, &sockOptSize)

but I am not able to increase it more than rmem_max value .

How can I increase it using c language.

I don't want to increase it by command :

$ sysctl -w net.core.rmem_max=value

回答1:

As The Man says

SO_RCVBUF

Sets or gets the maximum socket receive buffer in bytes. The kernel doubles this value (to allow space for bookkeeping overhead) when it is set using setsockopt(2), and this doubled value is returned by getsockopt(2). The default value is set by the /proc/sys/net/core/rmem_default file, and the maximum allowed value is set by the /proc/sys/net/core/rmem_max file. The minimum (doubled) value for this option is 256.

Emphasis mine

So with permissions on that file you can directly modify it.