_ RU.LINUX (2:5077/15.22) ___________________________________________ RU.LINUX _
From : Sergey I. Clushin 2:5020/400 14 Apr 99 00:57:06
Subj : SOCK_RAW
________________________________________________________________________________
From: "Sergey I. Clushin" <serg@aviacom.ru>
Andrey Kuzmin wrote:
>
> ...
> >Использовать SOCK_PACKET.
> >
>
> А можно поподробнее, т.к. когда я ставлю SOCK_PACKET вместо SOCK_RAW
SOCK_PACKET
Forum: The Linux Kernel Hackers' Guide
Re: Difference between SOCK_RAW SOCK_PACKET (Chris Leung)
Keywords: SOCK_PACKET
Date: Wed, 10 Jun 1998 18:01:01 GMT
From: Eddie Leung <edleung@uclink4.berkeley.edu>
Body-URL: http://www.senie.com/dan/technology/sock_packet.html
f78
Using the SOCK_PACKET mechanism in Linux
To Gain Complete Control of an Ethernet Interface
Daniel Senie
Amaranth Networks, Inc.
I have put together this web page in response to many queries from
multiple people. Rather than continue
to write individual responses, I have put together this page to explain
what I was trying to do, and how I
got it to work.
First, some background. To simulate software that was intended to run on
a different (and not yet built)
platform, I needed a convenient way to exercise the code against live
networks. I first tried using a
Solaris system, using the DLPI driver. This allowed me to do most things,
but failed when I needed to be
able to set the source Ethernet MAC address. The Solaris DLPI driver
provides no way to override the
hardware on a per-packet basis.
Next, I started looking at mechanisms in Linux. The mechanism that seemed
to fit the best was
SOCK_PACKET, which is used by tcpdump among other things. To Make this
work for me, though, it
was necessary to keep the Linux machine from doing anything on the
interface, other than letting my
programs at it.
How To Do It
This information and these instructions work for RedHat Linux 4.2 with a
2.0.30 kernel. I expect they'll
work fine on a 2.0.32 kernel as well, and with other Linux distributions.
I have heard that a better
mechanism for providing this facility is coming in a newer kernel. If or
when I get more information on
that, I'll see about adding another page on that.
First, the interface needs to be told NOT to run ARP. Promiscuous mode
should be enabled if you need
to hear everything on the wire.:
ifconfig eth1 -ARP PROMISC UP 10.1.1.1
Then tell the Linux stack it's not supposed to see any of the traffic to
or from this port:
ipfwadm -O -a deny -P all -S 0/0 -D 0/0 -W eth1
ipfwadm -I -a deny -P all -S 0/0 -D 0/0 -W eth1
In the program, you need to do several things. First, the socket call: