does setsockopt(SO_RCVTIMEO) work?

Dmitry Sivachenko trtrmitya at gmail.com
Wed Jul 16 11:49:28 UTC 2014


Hello!

I am having trouble using {g,s}etsockopt(SO_RCVTIMEO).  Consider the following small test program.
I expect to retrieve the value of 1 second via getsockopt call, I expect the following output:
tv_sec=1, tv_usec=0
But I actually get
tv_sec=0, tv_usec=0

What am I missing? 

Thanks!

PS: on Linux it works as I expect.


#include <err.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/time.h>

int main() {
    struct timeval tv;
    int fd;
    tv.tv_sec=1;
    tv.tv_usec=0;
    fd = socket(PF_UNIX, SOCK_STREAM, 0);
    if (fd < 0)
        err(1, "socket");
    socklen_t len = sizeof(struct timeval);
    if (setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &tv, len))
        err(1, "setsockopt");
    if (getsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &tv, &len))
        err(1, "getsockopt");
    printf("tv_sec=%ld, tv_usec=%ld\n", tv.tv_sec, tv.tv_usec);
}



More information about the freebsd-net mailing list