Why changing value of SO_RCVBUF doesn't work?

后端 未结 2 478
别那么骄傲
别那么骄傲 2020-11-29 10:16

I\'m making a program which create a RAW socket in order to read all traffic. Between the call of socket() and recvfrom() (last one is in a loop to get out all packets from

相关标签:
2条回答
  • 2020-11-29 11:01

    The level argument to setsockopt should be SOL_SOCKET, not 0:

    int a = 65535;
    if (setsockopt(sockfd, SOL_SOCKET, SO_RCVBUF, &a, sizeof(int)) == -1) {
        fprintf(stderr, "Error setting socket opts: %s\n", strerror(errno));
    }
    
    0 讨论(0)
  • 2020-11-29 11:02

    You may also be limited by the OS, if it still doesn't seem to be working. Check the values in:

    /proc/sys/net/core/rmem_default
    /proc/sys/net/core/rmem_max
    

    If it's TCP as you say in your example, and not actually a raw socket, you can also check the values in:

    /proc/sys/net/ipv4/tcp_mem
    

    If you run cat on these files they'll show you the current settings. To change them permanently, use sysctl. It's a good idea to write these settings down before you start changing things. Here's a great tutorial on making those changes: http://fasterdata.es.net/fasterdata/host-tuning/linux/.

    0 讨论(0)
提交回复
热议问题