A forum for questions and answers about network programming on Linux and all other Unix-like systems

You are not logged in.

#1 2019-04-18 05:10 AM

Registered: 2019-04-18
Posts: 1

raw socket for udp loopback

I have a requirement for using raw sockets with protocol as UDP. The communication is between two user processes on the same system. The destination address that i will have to use is only loopback.
Basically i have 2 processes which are communication using normal UDP sockets with loopback address as the destination address. Now i have to move away from these sockets to raw sockets.

If i use the destination address as loopback, will the packet be received by the process which transmitted the packet as well ? I believe so ...
If that is the case, how can i ignore this packet ? I need a way to ignore the packet or somehow make sure that the transmitting process doesnt receive the packet. (Any setsockopt() ? to solve this )

Both the process will be transmitting and would do a recvfrom() on the raw sockets created.

2) If two processes on the same system use sockets as IPC, isnt it true that the kernel will actually bypass the IP stack and provide a shortcircuit ? or does it take the same path as in the case of the peer being on a remote system

Best Regards,


#2 2019-04-18 02:37 PM

From: Boston, MA
Registered: 2002-06-12
Posts: 3,839

Re: raw socket for udp loopback

I'm assuming this is just some silly project for a class or something?  Because, it sounds stupid to use raw sockets in such a situation...  Even regular UDP sockets are overkill, and what you really want are AF_UNIX sockets...

But, if receiving from raw sockets, you'll have the protocol headers available to you, so you could simply have each sender use a specific source port# (just as they presumably did when using regular UDP sockets), then check for packets with your own source port# and discard them...

Yes, the kernel does various optimization tricks for senders/receivers on the same local system, but it's effectively just the same as using the loopback interface, which you're already doing...  Things still go through the standard stack, though...


Board footer

Powered by FluxBB