Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 08-28-2010, 05:36 AM   #1
faeze kalantari
LQ Newbie
Registered: Aug 2010
Posts: 5

Rep: Reputation: 0
diffrent between SOCK_DGRAM and SOCK_RAW

I am confused to understand the diffrence between SOCK_DGRAM and SOCK_RAW, can you help me?
1- should i call structure sockaddr_ll for both SOCK_DGRAM and SOCK_RAW?
2- what's the diffrence between these two kind of socket creation:
a) sock = socket(PF_INET , SOCK_RAW , protocol);
b) sock = socket(PF_PACKET , SOCK_RAW, protocol);
Old 08-28-2010, 08:08 AM   #2
Registered: Aug 2007
Location: Vietnam
Distribution: RedHat based, Debian based, Slackware, Gentoo
Posts: 724

Rep: Reputation: 101Reputation: 101
Old 08-31-2010, 02:42 AM   #3
faeze kalantari
LQ Newbie
Registered: Aug 2010
Posts: 5

Original Poster
Rep: Reputation: 0
thank you for the link. but could'nt find my answer for question 1 and 2. could you help me?
Old 08-31-2010, 03:52 AM   #4
Registered: Oct 2006
Location: Slovak Republic
Distribution: Slackware 14.2, current
Posts: 445

Rep: Reputation: 62
AF_INET is the normal IP family whit this you can have TCP, UDP, or raw sockets in the classic InterNet based network (IP).
AF_PACKET is the Linux-specific packet family, designed for creating link-level packets.
With an AF_PACKET socket, you can make not only IP traffic, but anything else ...

If you capture some packet with wireshark you can see several headers in the packet:

1. Frame
2. Ethernet II
3. Internet Protocol
4. Transmission Control Protocol (or UDP)

With AF_PACKET you can handle them all.
If you use SOCK_RAW you can use your own structures for UDP and TCP packet headers.(But I think that the standard structures can be used too)

Last edited by hua; 08-31-2010 at 04:25 AM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
is it possible to Broadcast msg using PF_LOCAL + SOCK_DGRAM wkhoo Programming 1 11-02-2008 06:51 PM
PF_PACKET + SOCK_RAW equivalent on Windoze krizzz Programming 1 06-28-2006 04:15 PM
How to assign diffrent ip/hostnames to diffrent services koppaspider Linux - General 1 02-10-2006 10:03 PM
source mac from SOCK_DGRAM bbeers Programming 3 08-17-2005 11:57 PM
Using streams over AF_INET SOCK_DGRAM in C programs worldmagic Programming 2 12-03-2003 05:54 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:51 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration