Questions tagged [setsockopt]
142 questions
118
votes
8 answers
When is TCP option SO_LINGER (0) required?
I think I understand the formal meaning of the option. In some legacy code I'm handling now, the option is used. The customer complains about RST as response to FIN from its side on connection close from its side.
I am not sure I can remove it…

dimba
- 26,717
- 34
- 141
- 196
109
votes
3 answers
What is the meaning of SO_REUSEADDR (setsockopt option) - Linux?
From the man page:
SO_REUSEADDR Specifies that the rules
used in validating addresses supplied
to bind() should allow reuse of local
addresses, if this is supported by the
protocol. This option takes an int
value. This is a Boolean…

Ray Templeton
- 1,091
- 2
- 8
- 3
34
votes
1 answer
TCP_NODELAY not found on Ubuntu
I am trying to disable the Nagle's Algorithm with my TCP sockets on an Ubuntu Linux box by setting the TCP_NODELAY parameter. For some reason, this constant is not defined in or . Has this constant been deprecated and…

rplankenhorn
- 2,075
- 2
- 22
- 32
24
votes
7 answers
What was the motivation for adding the IPV6_V6ONLY flag?
In IPv6 networking, the IPV6_V6ONLY flag is used to ensure that a socket will only use IPv6, and in particular that IPv4-to-IPv6 mapping won't be used for that socket. On many OS's, the IPV6_V6ONLY is not set by default, but on some OS's (e.g.…

Jeremy Friesner
- 70,199
- 15
- 131
- 234
15
votes
4 answers
Error "No such device" in call setsockopt when joining multicast group
I have a code in which send multicast datagrams.
A critical piece of code:
uint32_t port;
int sockfd, err_ip;
const uint32_t sizebuff = 65535 - (20 + 8);
unsigned char *buff = (unsigned char *) malloc(sizebuff);
struct sockaddr_in servaddr,…

Mephi_stofel
- 355
- 2
- 6
- 15
15
votes
3 answers
How to set TCP_NODELAY flag when loading URL with urllib2?
I am using urllib2 for loading web-page, my code is:
httpRequest = urllib2.Request("http:/www....com")
pageContent = urllib2.urlopen(httpRequest)
pageContent.readline()
How can I get hold of the socket properties to set TCP_NODELAY?
In normal…

Andrey Rubliov
- 1,359
- 2
- 17
- 24
12
votes
1 answer
Socket programming - setsockopt: Protocol not available?
I'm doing some basic socket programming in C and I'm running into this error on every computer I try to run the code on. The code compiles fine, but when I try to run it I get the error setsockopt: Protocol not available. It doesn't seem to be a…
user8768055
11
votes
2 answers
Why changing value of SO_RCVBUF doesn't work?
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 buffer) I wait 5s.
When I run the program, I send about 200 packets with…

Flow
- 187
- 1
- 2
- 8
10
votes
3 answers
Setting TCP receive window in C and working with tcpdump in Linux
I am running a Linux box running 2.6.9-55.ELsmp, x86_64.
I am trying to set the TCP receive window by using the setsockopt() function using C. I try the following:
rwnd = 1024;
setsockopt(sock, SOL_SOCKET, SO_RCVBUF, (char *)&rwnd,…

Sonny
- 2,103
- 1
- 26
- 34
9
votes
2 answers
Effect of SO_SNDBUF
I am unable to make sense of how and why the following code segments work :
/* Now lets try to set the send buffer size to 5000 bytes */
size = 5000;
err = setsockopt(sockfd, SOL_SOCKET, SO_SNDBUF, &size, sizeof(int));
if (err != 0)…

Arun
- 3,401
- 3
- 17
- 14
9
votes
1 answer
When to call setsockopt? Before bind() and connect()?
I inherited some TCP code that called:
bind(tcpSocket, (struct sockaddr*)&server_addr, sizeof(server_addr));
before the call to
setsockopt(tcpSocket, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int));
Not surprisingly, this lead to the message:…

jski
- 685
- 6
- 14
9
votes
2 answers
How is it possible to have send timeout on a non blocking socket?
I have some problems understanding the working of sockets in Linux.
setsockopt(sockfd, SOL_SOCKET, SO_SNDTIMEO, &timeout, sizeof(int));
write = write(sockfd, buf, len);
In the above code as writes are buffered, send timeout doesn't make any…

0xhacker
- 1,091
- 2
- 14
- 26
6
votes
1 answer
Why are IP_TTL and IP_MULTICAST_TTL separate socket options?
When sending UDP multicast you can use IP_MULTICAST_TTL to set the TTL. But otherwise you would use IP_TTL. Why are these two different options in the eyes of setsockopt() and getsockopt()? Is there any situation in which setting them separately…

John Zwinck
- 239,568
- 38
- 324
- 436
6
votes
1 answer
set socket option is why so important for a socket (IP_HDRINCL) In ICMP request?
I am new to socket programming
I saw a ICMP request program , in that they used setsockopt to a socket
int on = 1;
setsockopt(s, IPPROTO_IP, IP_HDRINCL, &on, sizeof(on))
but even if I do not use this statement, the program runs correctly. Why is…

Siva Kannan
- 2,237
- 4
- 27
- 39
5
votes
1 answer
Linux TCP socket timestamping option
Quoting form this online kernel doc
SO_TIMESTAMPING
Generates timestamps on reception, transmission or both. Supports
multiple timestamp sources, including hardware. Supports generating
timestamps for stream sockets.
Linux supports TCP…

FaceBro
- 787
- 2
- 13
- 29