Question

I'm wirting two programms for sending and receiving raw ethernet packets. I can send packets and I can receive, but I have two problems with my receiver.

First: All packtes are duplicated, it means all in comming packets are shown twice. It's only with a connection on 2 virtual networkinterfaces.(e.g. src tap0 mac 00:00:8F:00:00:02 -> dest tap1 mac 00:00:8F:00:00:03)

Second: All packets in the network are received form my programm, but it should receive packets from the specific interface.

Informations: I work on Ubuntu 12.04.01 LTS in a VirtualBox

Here my receiver code:

/*read while first char not * */
while(frame.data[0] != '*'){
    length_in_byte = recvfrom(sock_desc, buffer, ETH_FRAME_LEN,0,NULL,NULL);
    if(length_in_byte == -1){
        error handling
    }

    frame.dest_mac[0] = buffer[0];
    frame.dest_mac[1] = buffer[1];
    frame.dest_mac[2] = buffer[2];
    frame.dest_mac[3] = buffer[3];
    frame.dest_mac[4] = buffer[4];
    frame.dest_mac[5] = buffer[5];

    frame.src_mac[0] = buffer[6];
    frame.src_mac[1] = buffer[7];
    frame.src_mac[2] = buffer[8];
    frame.src_mac[3] = buffer[9];
    frame.src_mac[4] = buffer[10];
    frame.src_mac[5] = buffer[11];

    for(dataRun = 14; dataRun < length_in_byte; dataRun++){
        frame.data[dataRun-14] = buffer[dataRun];
    }
    /*print struct*/
    printf("\n");
    printf("src: %02x:%02x:%02x:%02x:%02x:%02x\t->\tdest: %02x:%02x:%02x:%02x:%02x:%02x\n",frame.src_mac[0],frame.src_mac[1],frame.src_mac[2],frame.src_mac[3],frame.src_mac[4],frame.src_mac[5],frame.dest_mac[0],frame.dest_mac[1],frame.dest_mac[2],frame.dest_mac[3],frame.dest_mac[4],frame.dest_mac[5]);
    printf("Data: %s\n", frame.data);

}

Terminal Output: send data = test

src: 00:00:8f:00:00:03  ->  dest: 00:00:8f:00:00:02
Data: test

src: 00:00:8f:00:00:03  ->  dest: 00:00:8f:00:00:02
Data: test

send data = a

src: 00:00:8f:00:00:03  ->  dest: 00:00:8f:00:00:02
Data: a

src: 00:00:8f:00:00:03  ->  dest: 00:00:8f:00:00:02
Data: a

src: 00:00:8f:00:00:03  ->  dest: 33:33:00:00:00:fb
Data: `

src: 00:00:8f:00:00:03  ->  dest: 33:33:00:00:00:fb
Data: `
Was it helpful?

Solution 2

I have found a solution for my problem with the duplication, it's not the source code for my programms.

The problem was the connection from the virtual ethernet devices, I've change the connection methode form tap0 to tap1.

I use yet the vde_switch. For Problem two I must find a filter.

Thanks a lot for your help

OTHER TIPS

for the first problem :

the while loop " while(frame.data[0] != '*') " cause the duplication of packet. maybe you have to check also if the packet is fragmented

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top