LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-06-2008, 03:10 PM   #1
davidkline
LQ Newbie
 
Registered: Nov 2005
Location: Chiago, IL
Distribution: VectorLinux
Posts: 26

Rep: Reputation: 15
LLC / DGRAM sockets usage


hello,

i'm trying to get llc dgram sockets to work as a client and having some problems. i have *no* experience using these types of sockets and the listed source code is not mine, but i'd like to try and get it to work. i'm using vectorlinux standard v5.1 with a 2.6.19 kernel. i configured the kernel under Networking | Networking Options | ANSI/IEEE 802.2 LLC type 2 as modules. it created four modules llc.ko, llc2.ko, p8022.ko, and psnap.ko. i loaded them successfully by hand (insmod). after loading them, i can see llc listed in the protocols file.

Code:
[epicsioc@iocdmk01 iocLinux]$ cat /proc/net/protocols
protocol  size sockets  memory press maxhdr  slab module     cl co di ac io in de sh ss gs se re sp bi br ha uh gp em
LLC        744     -1      -1   NI       0   no   llc2        n  n  n  n  n  n  n  n  n  n  n  n  n  n  n  n  n  n  n
PACKET     588     -1      -1   NI       0   no   kernel      n  n  n  n  n  n  n  n  n  n  n  n  n  n  n  n  n  n  n
UNIX       612     -1      -1   NI       0   yes  kernel      n  n  n  n  n  n  n  n  n  n  n  n  n  n  n  n  n  n  n
RAW        640     -1      -1   NI       0   yes  kernel      y  y  y  n  y  y  n  n  y  y  y  y  n  y  y  y  y  n  n
UDP        648     -1      -1   NI       0   yes  kernel      y  y  y  n  y  n  y  n  y  y  y  y  y  n  y  y  y  y  n
TCP       1328     11       1   no     160   yes  kernel      y  y  y  y  y  y  y  y  y  y  y  y  n  n  y  y  y  y  y
NETLINK    608     -1      -1   NI       0   no   kernel      n  n  n  n  n  n  n  n  n  n  n  n  n  n  n  n  n  n  n
does this look ok?

now, the basic code looks like this:
Code:
struct nmc_comm_info_struct *i;    /* application specific struct */
struct sockaddr_llc saddr;
                     :
                     :
                     :
/* Open up a communications socket */
i->sockfd = socket(AF_LLC, SOCK_DGRAM, 0);
if (i->sockfd == -1) {
    s = errno;
    perror("nmc_initialize: socket() error");
    goto signal;
}
	 
/* Bind the socket to the SNAP LSAP */
memset(&saddr, 0, sizeof(struct sockaddr_llc));
saddr.sllc_family = AF_LLC;
saddr.sllc_arphrd = ARPHRD_ETHER;
saddr.sllc_sap = LLC_SNAP_LSAP;

if (bind(i->sockfd, (struct sockaddr *)&saddr, sizeof(struct sockaddr_llc)) == -1) {
    s = errno;
    perror("nmc_initialize: bind() error");
    goto signal;
}
                     :
                     :
the call to socket() is successful, but the returned error from bind() is: "nmc_initialize: bind() error: No such device".

has anyone worked with these type of sockets and has an example i can look at? what am i doing wrong?

please advise, thanks in advance.
 
Old 08-05-2019, 06:29 PM   #2
waltk
LQ Newbie
 
Registered: Aug 2019
Location: Moscow
Posts: 1

Rep: Reputation: Disabled
Re: LLC / DGRAM sockets usage

Hello

Google still gives this thread on LLC searches.
So I think it's good to post the answer.

Kernel modules p8022.ko & psnap.ko are used by IPX and AppleTalk, and as far as I understand, can be called inside kernel only, so have no user space interface.

The LLC user code should bind to ethernet interface and to SAP.
If LLC socket intended to receive multicasts, it also should add ether multicast address to ethernet card filters.

So the code may look like this:
Code:
    int sock_fd, ret_val;
    char if_name[] = "eth0";

    /* create LLC socket */
    sock_fd = socket(AF_LLC, SOCK_DGRAM, 0);
    if (sock_fd < 0) {
        perror("socket(LLC)");
        exit(EXIT_FAILURE);
    }

    /* bind LLC socket to interface */
    ret_val = setsockopt(sock_fd, SOL_SOCKET, SO_BINDTODEVICE, if_name, strlen(if_name)+1);
    if (ret_val < 0) {
        perror("setsockopt(BINDTODEVICE)");
        close(sock_fd);
        exit(EXIT_FAILURE);
    }

    /* add multicast address */
    {
      struct ifreq ifr;
      memset(&ifr, 0, sizeof(ifr));
      strncpy(ifr.ifr_name, if_name, IFNAMSIZ);
      ifr.ifr_hwaddr.sa_family = AF_UNSPEC;
      ifr.ifr_hwaddr.sa_data[0] = 0x01; ifr.ifr_hwaddr.sa_data[1] = 0x80; ifr.ifr_hwaddr.sa_data[2] = 0xC2;

      ret_val = ioctl(sock_fd, SIOCADDMULTI, &ifr);
      if (ret_val < 0) {
          perror("ioctl(SIOCADDMULTI)");
      }
    }

    /* bind LLC socket to SAP */
    {
      struct sockaddr_llc my_sllc;
      memset(&my_sllc, 0, sizeof(my_sllc));
      my_sllc.sllc_family = AF_LLC;
      my_sllc.sllc_arphrd = ARPHRD_ETHER;
      my_sllc.sllc_sap = LLC_SAP_BSPAN; // 0x42

      ret_val = bind(sock_fd, (struct sockaddr *)&my_sllc, sizeof(my_sllc));
      if (ret_val < 0) {
        perror("bind()");
        close(sock_fd);
        exit(EXIT_FAILURE);
      }
    }

    do {
        struct sockaddr peer_sa;
        socklen_t peer_sa_len;
        ssize_t ret_val2;
        u_int8_t buf[1536];

        /* receive LLC packet */
        memset(&peer_sa, 0, sizeof(peer_sa));
        peer_sa_len = sizeof(peer_sa);
        ret_val2 = recvfrom(sock_fd, buf, sizeof(buf), 0, &peer_sa, &peer_sa_len);
        if (ret_val2 < 0) {
            perror("recvfrom()");
            break;
        }

        if (peer_sa.sa_family == AF_LLC) {
            struct sockaddr_llc *peer_sllc;

            peer_sllc = (struct sockaddr_llc *)&peer_sa;
            /* do job with peer_llc & buf */
        }
    } while (1);

    /* del multicast address */
    {
      struct ifreq ifr;
      memset(&ifr, 0, sizeof(ifr));
      strncpy(ifr.ifr_name, if_name, IFNAMSIZ);
      ifr.ifr_hwaddr.sa_family = AF_UNSPEC;
      ifr.ifr_hwaddr.sa_data[0] = 0x01; ifr.ifr_hwaddr.sa_data[1] = 0x80; ifr.ifr_hwaddr.sa_data[2] = 0xC2;

      ret_val = ioctl(sock_fd, SIOCDELMULTI, &ifr);
      if (ret_val < 0) {
          perror("ioctl(SIOCDELMULTI)");
      }
    }
Best regards
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Netlink sockets usage to communicate b/w user and kernel space. vinodkr83 Linux - Newbie 1 07-03-2009 03:22 AM
Program to forward tcp sockets to unix domain sockets mikepol Linux - Networking 0 09-27-2007 09:49 AM
problem with changing llc of wireless data frame in C fundoos4me Programming 1 03-31-2007 04:06 PM
LXer: Infradapt LLC Announces Formation, Acquisition of McFadden ... LXer Syndicated Linux News 0 07-06-2006 02:03 AM
sockets usage in kernel modules cipicip Programming 3 12-22-2005 09:10 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:26 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration