Quantcast
Channel: Processors
Viewing all articles
Browse latest Browse all 124377

Forum Post: RE: Dual port ethernet troubles

$
0
0

The problem is not that eth1 is not enabled. It shows a MAC and an IP address that was given to in from DHCP. The problem is eth1 can reveive frames through eth0. Also when I ping from my PC eth1 it forwards them to the MAC address associated with eth0. Could it be an ARP issue from eth1? Also, when I bind my raw ethernet socket to the eth1 interface, I can unplug the ethernet cable from eth1 and the frame will still transmit through eth0. I setting the destication as the broadcast MAC and am using wireshark to examine packets. Here is my code if you wanted to see it:

#include <sys/socket.h>
#include <netinet/in.h>
#include <linux/if_packet.h>
#include <linux/if_ether.h>
#include <linux/if_arp.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


int main(void)
{

 int s; /*socketdescriptor*/

 s = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
 if (s == -1)
 {
  printf("ERROR[1]: Socket Error\n");
  return -1;
 }
 
 char *opt;
 opt = "eth1";
 setsockopt(s, SOL_SOCKET, SO_BINDTODEVICE, opt, 4);

 

 /*target address*/
 struct sockaddr_ll socket_address;

 /*buffer for ethernet frame*/
 void* buffer = (void*)malloc(ETH_FRAME_LEN + ETH_FCS_LEN);

 /*pointer to ethenet header*/
 unsigned char* etherhead = buffer;

 /*userdata in ethernet frame*/
 unsigned char* data = buffer + 14;

 /*another pointer to ethernet header*/
 struct ethhdr *eh = (struct ethhdr *)etherhead;

 int send_result = 0;

 /*our MAC address*/
 unsigned char src_mac[6] = {0x02, 0x18, 0x31, 0x7E, 0x3E, 0x6F};

 /*other host MAC address*/
 unsigned char dest_mac[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
 

 /*prepare sockaddr_ll*/

 /*RAW communication*/
 socket_address.sll_family   = PF_PACKET; 
 /*we don't use a protocoll above ethernet layer
   ->just use anything here*/
 socket_address.sll_protocol = htons(ETH_P_IP); 

 /*index of the network device
 see full code later how to retrieve it*/
 socket_address.sll_ifindex  = 2;

 /*ARP hardware identifier is ethernet*/
 socket_address.sll_hatype   = ARPHRD_ETHER;

 /*target is another host*/
 socket_address.sll_pkttype  = PACKET_OTHERHOST;

 /*address length*/
 socket_address.sll_halen    = ETH_ALEN;  
 /*MAC - begin */
 socket_address.sll_addr[0]  = 0xFF;  
 socket_address.sll_addr[1]  = 0xFF;  
 socket_address.sll_addr[2]  = 0xFF;
 socket_address.sll_addr[3]  = 0xFF;
 socket_address.sll_addr[4]  = 0xFF;
 socket_address.sll_addr[5]  = 0xFF;
 
 
 /*MAC - end*/
 socket_address.sll_addr[6]  = 0x00;/*not used*/
 socket_address.sll_addr[7]  = 0x00;/*not used*/


 /*set the frame header*/
 memcpy((void*)buffer, (void*)dest_mac, ETH_ALEN);
 memcpy((void*)(buffer+ETH_ALEN), (void*)src_mac, ETH_ALEN);
 eh->h_proto = 0x00;
 /*fill the frame with some data*/
 int j;
 for (j = 0; j < 1500; j++) {
  data[j] = (unsigned char)((int) (255.0*rand()/(RAND_MAX+1.0)));
 }

 /*send the packet*/
 send_result = sendto(s, buffer, ETH_FRAME_LEN, 0,
        (struct sockaddr*)&socket_address, sizeof(socket_address));
 if (send_result == -1)
 {
  printf("ERROR[2]: Send Failed\n");
  return -1;
 }
 
 printf("Transmitter Finished\n");
 return 0;
 

}

 


Viewing all articles
Browse latest Browse all 124377

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>