1

So I created a socket with socket(AF_INET, SOCK_RAW, IPPROTO_UDP). And then I have it recv() with a infinite loop. I know it can captures all datagrams. But will it stop datagrams going to the right places? I made a little experiment. I send very simple UDP message from one program to another. And they both received the message. I assume the raw socket won't block any UDP messages. I then read about it in the second paragraph of this question's best answer. It says an unbound udp socket will mess up the system. So I am not sure that is the same with raw socket. Or is it different on linux and windows?

And another quick question: binding socket(AF_INET, SOCK_RAW, IPPROTO_UDP) with a port won't do anything, right? I did it and the socket still receive messages going to all kinds of other ports.

Community
  • 1
  • 1
Xiwen Li
  • 47
  • 1
  • 4
  • I am having the same problem in Linux. I have a Linux server using raw UDP sockets (IPPROTO_UDP) and it is able to receive and send but the client (using SOCK_DGRAM) does not receive it even though the server receives the packet it just sent.... Did you manage to solve the problem? – rutex Dec 16 '18 at 13:25
  • BTW, I also tried to bind() the local address of the client but still didn't get the response from the server. I see the server receives the message it sends and also see it in Wireshark.... – rutex Dec 16 '18 at 13:46

1 Answers1

1

Not. Raw sockets deliver all packets to all registered socket users, so you'll get a copy of the packet as soon as it is got into the system, but a UDP socket will receive it also.

To the second question... you don't bind(2) a raw socket, so you cannot associate it with a port number.

Luis Colorado
  • 10,974
  • 1
  • 16
  • 31