[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <5d0f78b4-f850-4f73-dbb7-6c3d15d99c86@suse.cz>
Date: Mon, 24 Oct 2016 14:54:52 +0200
From: Jiri Slaby <jslaby@...e.cz>
To: ML netdev <netdev@...r.kernel.org>
Subject: UDP does not autobind on recv
Hello,
as per man 7 udp:
In order to receive packets, the socket can be bound to
a local address first by using bind(2). Otherwise,
the socket layer will automatically assign a free local
port out of the range defined by /proc/sys/net/ipv4
/ip_local_port_range and bind the socket to INADDR_ANY.
I did not know that bind is unneeded, so I tried that. But it does not
work with this piece of code:
int main()
{
char buf[128];
int fd = socket(AF_INET, SOCK_DGRAM, 0);
recv(fd, buf, sizeof(buf), 0);
}
The recv above never returns (even if I bomb all ports from the range).
ss -ulpan is silent too. As a workaround, I can stick a dummy write/send
before recv:
write(fd, "", 0);
And it starts working. ss suddenly displays a port which the program
listens on.
I think the UDP recv path should do inet_autobind as I have done in the
attached patch. But my knowledge is very limited in that area, so I have
no idea whether that is correct at all.
thanks,
--
js
suse labs
View attachment "0001-net-autobind-UDP-on-recv.patch" of type "text/x-patch" (2789 bytes)
Powered by blists - more mailing lists