Raw sockets to receive IP packets

ambuli used Ask the Experts™
Hi there,
I am trying to open a raw socket to capture IP packets.
When I use the option, "IPPROTO_TCP" I am able to capture the tcp packets, and similarly IPPROTO_UDP works for udp packets.  However, when I use IPPROTO_RAW I am not capturing any packets.  I am using Ubuntu Linux.  What could be wrong here?

When using IPPROTO_IP, I am getting an error( 93 - Protocol not supported)

 sock_raw = socket(AF_INET , SOCK_RAW , IPPROTO_RAW);

thank you.
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2016
an IPPROTO_RAW protocol is for send only. if you want to receive raw messages you should use htons(ETH_P_ALL) for protocol.


for sample code or man pages



for more information.

note, raw sockets normally were used to implement a new ip4 protocol or by net sniffers. they are badly portable and you may get issues with installed security mechanisms.


Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial