LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 10-18-2013, 04:34 AM   #1
preb82
LQ Newbie
 
Registered: Oct 2013
Posts: 1

Rep: Reputation: Disabled
Broadcast Ethernet pacages


Hello,
I have circuit board board that is made up of:
USB <-> LAN9500 <-> MII <-> PHY IC

LAN9500 is a USB to MII IC. The LAN9500 do contain one mac address. PHY IC is a special IC that also contains a MAC address.

So there is total 2 MAC address on this circuit board.
Togheter they generate a small network. The circuit board is not connected to the copper. The reason for this is because I need to load a firmware into the PHY before it works on the copper.

With WireShark I see that the PHY is broadcasting network packages. I have a small program that broadcast network packages:
* These is not shown in WireShark.
* The sendto function does not give any error.

So the packages I try to send disappears somehow in the linux kernel. I do suspect that linux kernel see that something is wrong with the link, and decide not to send the package.

Any ideas?




# dmesg
[82754.087355] usb 5-1.1: new high-speed USB device number 7 using xhci_hcd
[82754.106134] smsc95xx v1.0.4
[82754.188761] smsc95xx 5-1.1:1.0: eth1: register 'smsc95xx' at usb-0000:02:00.0-1.1, smsc95xx USB 2.0 Ethernet, 5a:71:10:58:df:ad
[82754.273593] ADDRCONF(NETDEV_UP): eth1: link is not ready


# ifconfig eth1 192.168.0.5 netmask 255.255.255.0 up


# ifconfig -a
eth1 Link encap:Ethernet HWaddr 5a:71:10:58:df:ad
inet addr:192.168.0.5 Bcast:192.168.0.255 Mask:255.255.255.0
UP BROADCAST MULTICAST MTU:1488 Metric:1
RX packets:185 errors:0 dropped:185 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:8510 (8.5 KB) TX bytes:0 (0.0 B)


# sudo tcpdump -i eth1
16:36:26.083072 00:b0:52:00:00:01 (oui Unknown) > Broadcast, ethertype Unknown (0x88e1), length 60:
0x0000: 0062 a000 b052 0400 0000 0000 0000 0000 .b...R..........
0x0010: 0000 0000 0000 0000 0000 0000 0000 0000 ................
0x0020: 0000 0000 0000 0000 0000 0000 0000 ..............

# sudo ethtool eth1
Settings for eth1:
Supported ports: [ TP MII ]
Supported link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
Supported pause frame use: No
Supports auto-negotiation: Yes
Advertised link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
Advertised pause frame use: Symmetric Receive-only
Advertised auto-negotiation: Yes
Link partner advertised link modes: 100baseT/Full
Link partner advertised pause frame use: Symmetric
Link partner advertised auto-negotiation: Yes
Speed: 100Mb/s
Duplex: Full
Port: MII
PHYAD: 0
Transceiver: internal
Auto-negotiation: on
Current message level: 0x00000007 (7)
drv probe link
Link detected: yes



# sudo ethtool -i eth1
driver: smsc95xx
version: 22-Aug-2005
firmware-version: smsc95xx USB 2.0 Ethernet
bus-info: usb-0000:02:00.0-1.1
supports-statistics: no
supports-test: no
supports-eeprom-access: yes
supports-register-dump: no

Code:
/*
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 */

#include <arpa/inet.h>
#include <linux/if_packet.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <net/if.h>
#include <netinet/ether.h>

#define MY_DEST_MAC0	0xFF
#define MY_DEST_MAC1	0xFF
#define MY_DEST_MAC2	0xFF
#define MY_DEST_MAC3	0xFF
#define MY_DEST_MAC4	0xFF
#define MY_DEST_MAC5	0xFF

#define DEFAULT_IF	"eth1"
#define BUF_SIZ		1024

int main(int argc, char *argv[])
{
	int sockfd;
	struct ifreq if_idx;
	struct ifreq if_mac;
	int tx_len = 0;
	char sendbuf[BUF_SIZ];
	struct ether_header *eh = (struct ether_header *) sendbuf;
	struct iphdr *iph = (struct iphdr *) (sendbuf + sizeof(struct ether_header));
	struct sockaddr_ll socket_address;
	char ifName[IFNAMSIZ];
	
	/* Get interface name */
	if (argc > 1)
		strcpy(ifName, argv[1]);
	else
		strcpy(ifName, DEFAULT_IF);

	/* Open RAW socket to send on */
	if ((sockfd = socket(AF_PACKET, SOCK_RAW, IPPROTO_RAW)) == -1) {
	    perror("socket");
	}

	/* Get the index of the interface to send on */
	memset(&if_idx, 0, sizeof(struct ifreq));
	strncpy(if_idx.ifr_name, ifName, IFNAMSIZ-1);
	if (ioctl(sockfd, SIOCGIFINDEX, &if_idx) < 0)
	    perror("SIOCGIFINDEX");
	/* Get the MAC address of the interface to send on */
	memset(&if_mac, 0, sizeof(struct ifreq));
	strncpy(if_mac.ifr_name, ifName, IFNAMSIZ-1);
	if (ioctl(sockfd, SIOCGIFHWADDR, &if_mac) < 0)
	    perror("SIOCGIFHWADDR");

	/* Construct the Ethernet header */
	memset(sendbuf, 0, BUF_SIZ);
	/* Ethernet header */
	eh->ether_shost[0] = ((uint8_t *)&if_mac.ifr_hwaddr.sa_data)[0];
	eh->ether_shost[1] = ((uint8_t *)&if_mac.ifr_hwaddr.sa_data)[1];
	eh->ether_shost[2] = ((uint8_t *)&if_mac.ifr_hwaddr.sa_data)[2];
	eh->ether_shost[3] = ((uint8_t *)&if_mac.ifr_hwaddr.sa_data)[3];
	eh->ether_shost[4] = ((uint8_t *)&if_mac.ifr_hwaddr.sa_data)[4];
	eh->ether_shost[5] = ((uint8_t *)&if_mac.ifr_hwaddr.sa_data)[5];
	eh->ether_dhost[0] = MY_DEST_MAC0;
	eh->ether_dhost[1] = MY_DEST_MAC1;
	eh->ether_dhost[2] = MY_DEST_MAC2;
	eh->ether_dhost[3] = MY_DEST_MAC3;
	eh->ether_dhost[4] = MY_DEST_MAC4;
	eh->ether_dhost[5] = MY_DEST_MAC5;
	/* Ethertype field */
	eh->ether_type = htons(ETH_P_IP);
	tx_len += sizeof(struct ether_header);

	/* Packet data */
	sendbuf[tx_len++] = 0xde;
	sendbuf[tx_len++] = 0xad;
	sendbuf[tx_len++] = 0xbe;
	sendbuf[tx_len++] = 0xef;

	/* Index of the network device */
	socket_address.sll_ifindex = if_idx.ifr_ifindex;
	/* Address length*/
	socket_address.sll_halen = ETH_ALEN;
	/* Destination MAC */
	socket_address.sll_addr[0] = MY_DEST_MAC0;
	socket_address.sll_addr[1] = MY_DEST_MAC1;
	socket_address.sll_addr[2] = MY_DEST_MAC2;
	socket_address.sll_addr[3] = MY_DEST_MAC3;
	socket_address.sll_addr[4] = MY_DEST_MAC4;
	socket_address.sll_addr[5] = MY_DEST_MAC5;

	/* Send packet */
	int lenr = 0;
	lenr = sendto(sockfd, sendbuf, tx_len, 0, (struct sockaddr*)&socket_address, sizeof(struct sockaddr_ll));
	if (lenr < 0){
	    printf("Send failed\n");
	}
	else{
	    printf("Send %d bytes\n", lenr);
	}

	return 0;
}
 
  


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
How to send a DHCP Ethernet Broadcast packet(s) through the network okorkie Red Hat 1 03-19-2009 08:38 AM
Ethernet driver - kernel crashes after passing a few Ethernet frames to upper layers AustinMarton Linux - Kernel 0 03-12-2009 07:27 PM
Problem with Broadcast UDP in two ethernet machine inakizi Linux - Networking 1 03-28-2007 04:56 AM
Automatic generation of fluxbox menu - based on debian pacages. alien3456 Linux - General 3 02-09-2006 08:33 PM
Impossible to turn BROADCAST mode off on ethernet device subjazz Linux - Networking 1 08-17-2004 04:47 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 10:09 AM.

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
Open Source Consulting | Domain Registration