Raw packets

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View
Well next step in this project after I have got UDP alive is to receive and
send raw packets too. My first impression was that this should be even
simpler by just changing a couple of parameters in the socket but it just
doesn't work. I have just taken my functional UDP code and modified a few
lines. It executes with no errors until "sento" that always claims to have
an invalid argument.

Am I missing something or are the raw packets not as simple as this in
Linux? (In windows they are a pain and here I am using PWinCap)

Thanks,

Jens.


int sendRAW(void)
{
  struct sockaddr_in si_other;
  int s, i, slen=sizeof(si_other);
  char buf[BUFLEN];

  if ((s=socket(PF_PACKET, SOCK_DGRAM, htons((short)ETH_P_ALL)))==-1)
    diep("socket");

  memset((char *) &si_other, sizeof(si_other), 0);
  si_other.sin_family = PF_PACKET;

  for (i=0; i<NPACK; i++)
  {
    printf("Sending packet %d\n", i);
    sprintf(buf, "This is packet %d\n", i);
    if (sendto(s, buf, BUFLEN, 0, &si_other, slen)==-1)
      diep("sendto()");
   }

  close(s);
  return 0;
}




Re: Raw packets
Hi Jens,

you should open the socket with other arguments like here

ethInterface->devDescr = socket( PF_INET,
                                 SOCK_PACKET,
                                 htons( ETH_P_ALL ) );
ethInterface->sa.sa_family = AF_INET;
strncpy( (char*) &ethInterface->sa.sa_data,
        "eth0",
        sizeof( ethInterface->sa.sa_data ) );
bind( ethInterface->devDescr,
      &ethInterface->sa,
      sizeof(ethInterface->sa) );

Bye,

--
Markus Pietrek

(Remove _nospam from email address before replying)

Re: Raw packets
Thanks,

But would this give me the real raw packets? As far as I can see, this gives
me the IP header too?

Jens.


Quoted text here. Click to load it



Re: Raw packets
Hi Jens,

Quoted text here. Click to load it

From my point of view a raw (ethernet) packet is a packet with all header
information, untouched by the OS.

Bye,

--
Markus Pietrek

(Remove _nospam from email address before replying)

Re: Raw packets
On Tue, 23 Sep 2003 09:25:23 +0200, Markus Pietrek

Quoted text here. Click to load it

To get raw ethernet packets, you have to put the ethernet controller
into the promiscuous mode. I have no idea if current controllers still
support the promiscuous mode.

Paul


Re: Raw packets
Thanks,

Jens.

Quoted text here. Click to load it



Re: Raw packets
Don't you need to bind to a local port first?  Also this is UDP not raw
ethernet.

Quoted text here. Click to load it
and



Site Timeline