public inbox for developer@lists.illumos.org (since 2011-08)
 help / color / mirror / Atom feed
From: Pramod Batni <pramod.batni@gmail.com>
To: illumos-developer <developer@lists.illumos.org>
Subject: Re: [developer] Raw ethernet packets
Date: Fri, 31 May 2024 15:13:35 +0530	[thread overview]
Message-ID: <CAKEriGBfyY-DbP6AvMAruz3JYE0pyd98aTHhhG=uWeLBGUR4VQ@mail.gmail.com> (raw)
In-Reply-To: <ZlmNl2B7u36Iyz7a@telcontar>

[-- Attachment #1: Type: text/plain, Size: 2555 bytes --]

Regarding 2.

    I think the reason snoop not showing the
    Ethernet packet is probably because /dev/bpf
   works at the same (or lower) level than
   the level at which snoop captures the packet.


   Not sure but worth checking (is the
   Ethernet packet on the network by some
    other host on the same network)



On Fri, 31 May 2024 at 14:14, Marcel Telka <marcel@telka.sk> wrote:

> 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/ |
> +-------------------------------------------+
>
> ------------------------------------------
> illumos: illumos-developer
> Permalink:
> https://illumos.topicbox.com/groups/developer/T9ea91ef91413959c-M0f5ac7181f7a9e8e1120f867
> Delivery options:
> https://illumos.topicbox.com/groups/developer/subscription
>

[-- Attachment #2: Type: text/html, Size: 3921 bytes --]

  parent reply	other threads:[~2024-05-31  9:43 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-31  8:43 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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAKEriGBfyY-DbP6AvMAruz3JYE0pyd98aTHhhG=uWeLBGUR4VQ@mail.gmail.com' \
    --to=pramod.batni@gmail.com \
    --cc=developer@lists.illumos.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).