public inbox for developer@lists.illumos.org (since 2011-08)
 help / color / mirror / Atom feed
* Raw ethernet packets
@ 2024-05-31  8:43 Marcel Telka
  2024-05-31  8:54 ` [developer] " Marcel Telka
                   ` (3 more replies)
  0 siblings, 4 replies; 20+ messages in thread
From: Marcel Telka @ 2024-05-31  8:43 UTC (permalink / raw)
  To: developer

Hi,

I'm trying to send a raw ethernet packet from an userland application
but all my attempts so far were unsuccessful.  I basically tried two
approaches (see below) but maybe both are in wrong direction.  I'd
appreciate some help, suggestion or pointer to an working example or
application already doing that.


1) socket()/bind()

	int s = socket(AF_PACKET, SOCK_RAW, 0);

	struct sockaddr_ll llp = {};
	llp.sll_family = AF_PACKET;
	llp.sll_protocol = 0x0800;
	llp.sll_ifindex = 5;	/* this is from ifconfig -a */

	bind(s, (struct sockaddr *)&llp, sizeof (struct sockaddr_ll));

The bind() call above failed.


2) bpf

	/* Copy of real ARP packet from snoop capture */
	char buf[] =
	"\xff\xff\xff\xff\xff\xff"
	"\x00\x1c\x25\xa0\xb7\x2e"
	"\x08\x06\x00\x01"
	"\x08\x00\x06\x04\x00\x01"
	"\x00\x1c\x25\xa0\xb7\x2e"
	"\x0a\x00\x00\x0d"
	"\xff\xff\xff\xff\xff\xff"
	"\x0a\x00\x00\x37"
	;

	int fd = open("/dev/bpf", O_RDWR);

	struct ifreq ifr = { .ifr_name = {} };
	memcpy(&ifr.ifr_name, "e1000g0", 7);
	ioctl(fd, BIOCSETIF, (caddr_t)&ifr);

	int enable = 1;
	ioctl(fd, BIOCIMMEDIATE, (caddr_t)&enable);

	enable = 1;
	ioctl(fd, BIOCSHDRCMPLT, (caddr_t)&enable);

	write(fd, buf, sizeof buf - 1);


In this case all functions passed so it looks like everything works, but
I'm unable to snoop the packet on the network.


Thank you.

-- 
+-------------------------------------------+
| Marcel Telka   e-mail:   marcel@telka.sk  |
|                homepage: http://telka.sk/ |
+-------------------------------------------+

^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2024-06-06 16:51 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-31  8:43 Raw ethernet packets Marcel Telka
2024-05-31  8:54 ` [developer] " Marcel Telka
2024-05-31  9:13   ` Denis Kozadaev
2024-05-31  9:51     ` Marcel Telka
2024-05-31 11:08       ` Marcel Telka
2024-05-31 11:23         ` Denis Kozadaev
2024-05-31 12:07           ` Marcel Telka
2024-05-31 12:18             ` Denis Kozadaev
2024-05-31 13:33               ` Marcel Telka
2024-05-31 14:15                 ` Denis Kozadaev
2024-05-31 15:04                   ` Marcel Telka
2024-05-31 15:20                     ` Denis Kozadaev
2024-05-31  9:03 ` Joshua M. Clulow
2024-05-31  9:50   ` Marcel Telka
2024-05-31 13:45     ` Marcel Telka
2024-05-31  9:43 ` Pramod Batni
2024-05-31  9:49   ` Marcel Telka
2024-06-02  9:05 ` Marcel Telka
2024-06-06 12:54   ` Marcel Telka
2024-06-06 16:51     ` Alan Coopersmith

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).