public inbox for developer@lists.illumos.org (since 2011-08)
 help / color / mirror / Atom feed
From: Denis Kozadaev <denis@tambov.ru>
To: developer@lists.illumos.org
Cc: Marcel Telka <marcel@telka.sk>
Subject: Re: [developer] Raw ethernet packets
Date: Fri, 31 May 2024 12:13:37 +0300	[thread overview]
Message-ID: <202405311213.37389.denis@tambov.ru> (raw)
In-Reply-To: <ZlmQQqCuNyWBQGlr@telcontar>

witch% cat main.c 
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/sockio.h>
#include <sys/ioctl.h>

#include <net/if.h>

#include <stdio.h>
#include <unistd.h>
#include <string.h>

int
main(void)
{
        int                     sock;
        struct sockaddr_ll      sll;
        struct lifreq           ifr;
        char                    buf[8192], dev[] = "dpi0";
        ssize_t                 result;

        sock = socket(AF_PACKET, SOCK_RAW, 0);
        if (sock < 0) {
                perror("socket");
                return (1);
        }

        strcpy(ifr.lifr_name, dev);
        result = ioctl(sock, SIOCGLIFINDEX, &ifr);
        sll.sll_family = AF_PACKET;
        sll.sll_ifindex = ifr.lifr_index;
        sll.sll_protocol = 0;
        result = bind(sock, (struct sockaddr *)&sll, sizeof(sll));

        for (;;) {
                result = recvfrom(sock, buf, sizeof(buf), 0, NULL, NULL);
                fprintf(stderr, "received %d bytes\n", (int)result);
        }

        close(sock);

        return (0);
}
/****************************/
This is my old code I played long time ago.
I hope this will help you...

On Friday 31 May 2024 11:54:26 Marcel Telka wrote:
> On Fri, May 31, 2024 at 10:43:03AM +0200, Marcel Telka wrote:
> > 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.
>
> ... with ENOENT.  When I change the bind call to:
>
>         bind(s, (struct sockaddr *)&llp, sizeof (struct sockaddr));
>
> then it fails with EINVAL.


  reply	other threads:[~2024-05-31  9:13 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 [this message]
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

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=202405311213.37389.denis@tambov.ru \
    --to=denis@tambov.ru \
    --cc=developer@lists.illumos.org \
    --cc=marcel@telka.sk \
    /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).