Re: PF_LLC sockets working code on 2.6.17

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Apparently it worked for the server side, thx!

But now I have problems with the client side, I trying a lot of things
and parameters, but withou success. errno on the "connect" call
returns "Software caused connection abort" on the code below. Since
LLC sockets is new on Linux kernel, I don't know where to search for
information. Searching on lists and foruns I read about tests Acme and
others were doing, but I cannot found code.

client side:

	if( (sock = socket(PF_LLC, SOCK_STREAM, 0)) < 0){
		perror("socket");
		return sock;
	}
	
	memset(&ifr, 0, sizeof(ifr));
	strncpy(ifr.ifr_name, "eth0", sizeof("eth0"));
	if (ioctl(sock, SIOCGIFHWADDR, &ifr) < 0) {
		perror("ioctl");
		return -1;
	}

	memset(&remoteaddr, 0, sizeof(remoteaddr));
	remoteaddr.sllc_family = AF_LLC;
	remoteaddr.sllc_sap = LLC_SAP_NULL;
	remoteaddr.sllc_arphrd = ARPHRD_ETHER;
	memcpy(remoteaddr.sllc_mac, ifr.ifr_hwaddr.sa_data, IFHWADDRLEN);

	if( (ret = connect(sock, (struct sockaddr *)&remoteaddr,
sizeof(remoteaddr))) < 0 ){
		perror("connect");
		close(sock);
		return ret;
	}

/*---------------------------------------------------------------*/

server side:

	if( (sock = socket(PF_LLC, SOCK_STREAM, 0)) < 0){
		perror("socket");
		return sock;
	}

	memset(&ifr, 0, sizeof(ifr));
	strncpy(ifr.ifr_name, "eth0", sizeof("eth0"));
	if (ioctl(sock, SIOCGIFHWADDR, &ifr) < 0) {
		perror("ioctl");
		fprintf(stderr, "get address failed: %s\n", strerror(errno));
		return -1;
	}

	memset(&localaddr, 0, sizeof(localaddr));
	localaddr.sllc_family = AF_LLC;
	localaddr.sllc_sap = LLC_SAP_NULL;
	localaddr.sllc_arphrd = ARPHRD_ETHER;
	memcpy(localaddr.sllc_mac, ifr.ifr_hwaddr.sa_data, IFHWADDRLEN);

	if( (ret = bind(sock, (struct sockaddr *)&localaddr, sizeof(localaddr))) < 0 ){
		perror("bind");
		close(sock);
		return ret;
	}
	
	if( (ret = listen(sock, 10)) < 0 ){
		perror("listen");
		return ret;
	}
	
	while(1){
		remoteaddrsize = sizeof(remoteaddr);
		if( (slavesock = accept(sock, (struct sockaddr *)&remoteaddr,
&remoteaddrsize)) < 0 ){
			perror("accept");
			return slavesock;
		}
		printf("server: %d, %x %x %x\n", ret, buffer[0], buffer[1], buffer[2]);
	}

On 8/2/06, Stephen Hemminger <shemminger@xxxxxxxx> wrote:
On Wed, 2 Aug 2006 14:12:11 -0300
"Evandro Clivatti Dall'Agnol" <evandrocd@xxxxxxxxx> wrote:

> Hi all, sorry if this question has another more pertinent list to
> send, but I guess this is the one.
>
> I'm trying to use PF_LLC sockets on 2.6.17 based on llcping examples
> of the now gone www.linux-sna.org (http://www.vanheusden.com/sna/old/)
> but I'm not getting success.
>
> Specifically, the bind() command returns < 0 and perror returns "No
> such device".
>
> Since that code was working apparently only with patches for 2.4
> series, does anybody knows another place I can get working examples of
> PF_LLC for 2.6? Or anybody has a working code?

Since there can be multiple devices in the system and LLC does no routing,
you probably need to bind your application to a specific device mac address.

Something like this would set address to match command line arg.
        struct ifreq ifr;
...
        memset(&ifr, 0, sizeof(ifr));
        strncpy(ifr.ifr_name, argv[1], IFNAMSIZ);
        if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
                fprintf(stderr, "%s: get address failed: %s\n",
                        argv[1], strerror(errno));
                return 1;
        }

...
        memcpy(localaddr.sllc_mac, ifr.ifr_hwaddr.sa_data, IFHWADDRLEN);

-
: send the line "unsubscribe linux-net" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux 802.1Q VLAN]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Git]     [Bugtraq]     [Yosemite News and Information]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux PCI]     [Linux Admin]     [Samba]

  Powered by Linux