#232996 packet(7): wrong information about "sending a packet using sendto"

Package:
manpages
Source:
manpages
Submitter:
Francesco Potorti`
Date:
2023-12-23 14:24:02 UTC
Severity:
normal
Tags:
#232996#5
Date:
2004-02-16 08:55:32 UTC
From:
To:
The man page for packet(7) says:

    ================================================================
 sll_protocol is the standard ethernet protocol type in network order as
 defined in the linux/if_ether.h  include  file.   It  defaults  to  the
 socket's protocol.  [...]

 When  you  send  packets  it is enough to specify sll_family, sll_addr,
 sll_halen, sll_ifindex.  The other fields should be 0.  sll_hatype  and
 sll_pkttype are set on received packets for your information.  For bind
 only sll_protocol and sll_ifindex are used.
    ================================================================

This is wrong.  In fact, when sending a packet using sendto, the
socket's protocol is apparently ignored, while the value in sll_protocol
is used.  I do not know if this is a bug in the kernel, in the C library
or in the man page.  I easily discovered the problem by looking at the
working code of free programs.  I can provide test code, if necessary.

#232996#10
Date:
2007-01-06 18:08:59 UTC
From:
To:
Hi Francesco,

Sorry that nobody has commented on this bug.  Can you check if it still
applies to recent linux/glibc/manpages releases?  If so, can you provide
test code?

Thanks
Justin

References

[0] http://bugs.debian.org/232996

#232996#15
Date:
2007-01-08 13:53:46 UTC
From:
To:
I use a Debian testing, just upgraded.  The man page says the same as
before, and the behaviour has not changed.  Kernel is 2.6.18.

Appended is a test program and here is the output of tcpdump when the
test program is launched (as root):

 00:00:00:00:00:00 (oui Ethernet) > 00:00:00:00:00:00 (oui Ethernet) Null Information
 00:00:00:00:00:00 (oui Ethernet) > 00:00:00:00:00:00 (oui Ethernet), ethertype Unknown (0x2007)
 00:00:00:00:00:00 (oui Ethernet) > 00:00:00:00:00:00 (oui Ethernet), ethertype Unknown (0x2008)

The first packet has type 0x0000, the second one has type 0x2007, the
third one has type 0x2008.  If the man page were correct, all three
would have type 0x2006.

===File /home/work/wichmo/vbrsr/packetbug.c=================
#include <netpacket/packet.h>		/* the socket packet interface */
#include <iwlib.h>			/* wireless extensions */

int buf;

int main ()
{
  int sd, ifindex;
  struct sockaddr_storage saddr;	/* socket destination address (max storage) */

  if ((sd = socket(AF_PACKET, SOCK_DGRAM, htons(0x2006))) < 0)
    { perror("while opening socket"); return 2; }

  /* Find the interface index */
  if ((ifindex = if_nametoindex("lo")) == 0)
    return 3;

  /* Create address for sendto */
  struct sockaddr_ll zeroaddr = {0};
  struct sockaddr_ll *sap = (struct sockaddr_ll *)&saddr;
  *sap = zeroaddr;			/* clear the address struct */
  sap->sll_family = AF_PACKET;		/* address family */

  /* The packet(7) man page says that setting the protocol number is
     useless when sending, but in fact the third argument of the socket
     syscall is ignored and setting this is necessary. */
 sap->sll_halen = IFHWADDRLEN;		/* address length */
 sap->sll_ifindex = ifindex;		/* interface index */

 if (sendto(sd, &buf, sizeof(buf), 0,
	    (struct sockaddr *)&saddr, sizeof(struct sockaddr_ll)) < 0)
   return 4;

 sap->sll_protocol = htons(0x2007); /* our private protocol number */
 if (sendto(sd, &buf, sizeof(buf), 0,
	    (struct sockaddr *)&saddr, sizeof(struct sockaddr_ll)) < 0)
   return 4;

 sap->sll_protocol = htons(0x2008); /* our private protocol number */
 if (sendto(sd, &buf, sizeof(buf), 0,
	    (struct sockaddr *)&saddr, sizeof(struct sockaddr_ll)) < 0)
   return 4;

}
============================================================

#232996#18
Date:
2007-01-08 13:53:46 UTC
From:
To:
I use a Debian testing, just upgraded.  The man page says the same as
before, and the behaviour has not changed.  Kernel is 2.6.18.

Appended is a test program and here is the output of tcpdump when the
test program is launched (as root):

 00:00:00:00:00:00 (oui Ethernet) > 00:00:00:00:00:00 (oui Ethernet) Null Information
 00:00:00:00:00:00 (oui Ethernet) > 00:00:00:00:00:00 (oui Ethernet), ethertype Unknown (0x2007)
 00:00:00:00:00:00 (oui Ethernet) > 00:00:00:00:00:00 (oui Ethernet), ethertype Unknown (0x2008)

The first packet has type 0x0000, the second one has type 0x2007, the
third one has type 0x2008.  If the man page were correct, all three
would have type 0x2006.

===File /home/work/wichmo/vbrsr/packetbug.c=================
#include <netpacket/packet.h>		/* the socket packet interface */
#include <iwlib.h>			/* wireless extensions */

int buf;

int main ()
{
  int sd, ifindex;
  struct sockaddr_storage saddr;	/* socket destination address (max storage) */

  if ((sd = socket(AF_PACKET, SOCK_DGRAM, htons(0x2006))) < 0)
    { perror("while opening socket"); return 2; }

  /* Find the interface index */
  if ((ifindex = if_nametoindex("lo")) == 0)
    return 3;

  /* Create address for sendto */
  struct sockaddr_ll zeroaddr = {0};
  struct sockaddr_ll *sap = (struct sockaddr_ll *)&saddr;
  *sap = zeroaddr;			/* clear the address struct */
  sap->sll_family = AF_PACKET;		/* address family */

  /* The packet(7) man page says that setting the protocol number is
     useless when sending, but in fact the third argument of the socket
     syscall is ignored and setting this is necessary. */
 sap->sll_halen = IFHWADDRLEN;		/* address length */
 sap->sll_ifindex = ifindex;		/* interface index */

 if (sendto(sd, &buf, sizeof(buf), 0,
	    (struct sockaddr *)&saddr, sizeof(struct sockaddr_ll)) < 0)
   return 4;

 sap->sll_protocol = htons(0x2007); /* our private protocol number */
 if (sendto(sd, &buf, sizeof(buf), 0,
	    (struct sockaddr *)&saddr, sizeof(struct sockaddr_ll)) < 0)
   return 4;

 sap->sll_protocol = htons(0x2008); /* our private protocol number */
 if (sendto(sd, &buf, sizeof(buf), 0,
	    (struct sockaddr *)&saddr, sizeof(struct sockaddr_ll)) < 0)
   return 4;

}
============================================================

#232996#27
Date:
2023-12-23 12:30:58 UTC
From:
To:
tags 232996 - moreinfo
# The submitter provided a test script and further information
# And no furter information request was made in the last 16 years
thanks

Hello Tobias,
Am Mon, Jan 08, 2007 at 02:53:46PM +0100 schrieb Francesco Potorti`:

The man page is almost the same as given in this old report, except
the last sentence is missing (which does not seem relevant here).

I propose to forward this to upstream. If this is not a bug in the man
page, then it should be reassigned to the proper package.

(Apologies, if upstream has already been informed, this is not
visisble from the bug).

Greetings

         Helge

#232996#30
Date:
2023-12-23 12:30:58 UTC
From:
To:
tags 232996 - moreinfo
# The submitter provided a test script and further information
# And no furter information request was made in the last 16 years
thanks

Hello Tobias,
Am Mon, Jan 08, 2007 at 02:53:46PM +0100 schrieb Francesco Potorti`:

The man page is almost the same as given in this old report, except
the last sentence is missing (which does not seem relevant here).

I propose to forward this to upstream. If this is not a bug in the man
page, then it should be reassigned to the proper package.

(Apologies, if upstream has already been informed, this is not
visisble from the bug).

Greetings

         Helge