Re: How to find socket buffer size

Prasanta Sadhukhan <[email protected]>
Newsgroups gmane.os.netbsd.help
Message-ID <[email protected]>
Rob Newberry wrote:

>>> I think it's:
>>> sysctl kern.sbmax
>>
>> Thanks.. I knew that but the question is how to obtain the value
>> programatically?
>
>
> sysctl(3)
>
>
Thanks....I tried to limit the sock buffer to the maximum sockbuf as 
specified by the kern.sbmax variable like this
int *bufsize = (int *)arg;
int mib[2], sockbufmax;
        size_t len;
        mib[0] = CTL_KERN;
        mib[1] = KERN_SBMAX;
        len = sizeof(sockbufmax);
        sysctl(mib, 2, &sockbufmax, &len, NULL, 0);
        if (*bufsize > sockbufmax)
                *bufsize = sockbufmax;
        fprintf(stdout, "buffersize %d\n", *bufsize);
        fflush(stdout);
    }
    return setsockopt(fd, SOL_SOCKET, SO_RCVBUF, arg, len);

although kern.sbmax shows 262144 i.e., 256KB, but while setting 
setsockopt for sockbufsize of 2147483646 which will get limited to 
262144 I am getting -1. Only if I limit it within 227KB, then it passes
Any clue?!

Regards
Prasanta
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.