Solved

Raw sockets to receive IP packets

Posted on 2014-03-03
2
1,142 Views
Last Modified: 2014-03-04
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.
0
Comment
Question by:ambuli
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 34

Accepted Solution

by:
sarabande earned 500 total points
ID: 39900915
an IPPROTO_RAW protocol is for send only. if you want to receive raw messages you should use htons(ETH_P_ALL) for protocol.

see
http://ubuntuforums.org/archive/index.php/t-1292481.html

for sample code or man pages

http://manpages.ubuntu.com/manpages/lucid/man7/raw.7.html

http://manpages.ubuntu.com/manpages/lucid/man7/packet.7.html

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.

Sara
0

Featured Post

Monthly Recap

May was a big month for new releases from Linux Academy! Take a look at what our team built recently in our blog. You can access the newest releases from our blog.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.

724 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question