Dear all,

I have a program attached below to send raw Ethernet packet. The program run normally, and I can see the packet in local machine by some network sniffer. However, I use another computer (Windows XP) which is connected to this computer by a hub, but I can't see any packet from this computer by sniffer. What is the problem?

Thanks.

Jacky


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

void main(void)
{
int s; /*socketdescriptor*/
int j;

s = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
if (s == -1)
{
printf("Cannot open socket %s\n", strerror(errno));
return;
}

/*target address*/
struct sockaddr_ll socket_address;

/*buffer for ethernet frame*/
void* buffer = (void*)malloc(ETH_FRAME_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] = {0x90, 0xe6, 0xba, 0xde, 0x7d, 0x44};

/*other host MAC address*/
unsigned char dest_mac[6] = {0x00, 0x82, 0x83, 0x84, 0x85, 0x19};

/*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] = 0x00;
socket_address.sll_addr[1] = 0x82;
socket_address.sll_addr[2] = 0x83;
socket_address.sll_addr[3] = 0x84;
socket_address.sll_addr[4] = 0x85;
socket_address.sll_addr[5] = 0x19;
/*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*/
for (j = 0; j < 1500-4; j++) {
data[j] = (unsigned char)((int) (255.0*rand()/(RAND_MAX+1.0)));
}

/*send the packet*/
while(1)
{
send_result = sendto(s, buffer, ETH_FRAME_LEN, 0,
(struct sockaddr*)&socket_address, sizeof(socket_address));
printf("%d %s\n", send_result, strerror(errno));
}
if (send_result == -1) exit;
}