Hi,
I am creating packets and sending with sockets to the network. But I am
unable to send packets to my own system. I want to be able to send form
my system some ICMP query to eth0 interface so that my own system will
send reply. For now I can tcpdump the query and it is visible in the net
but it seems to be outgoing only. Maybe I have to put in to network rx
buffer but I don't know how.
Thanks for any help.
Tom
Here is my actual sending procedure:
int send_ethernet_raw_lan(char *frame, int frame_length) {
int sendBytes;
static struct sockaddr_ll ll;
memset(&ll, 0, sizeof(struct sockaddr_ll));
ll.sll_family = AF_PACKET;
ll.sll_ifindex = config.lanindex;
ll.sll_protocol = htons(ETH_P_ALL);
sendBytes=sendto(lansock,frame,frame_length,0,(str uct sockaddr *)
&ll, sizeof(struct sockaddr_ll));
return sendBytes;
}
int initialize_socket_lan(void) {
struct ifreq ifr;
struct sockaddr_ll ll;
int dummy,ret;
lansock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
memset(&ll, 0, sizeof(struct sockaddr_ll));
memset(&ifr,0,sizeof(ifr));
strncpy(ifr.ifr_name, config.devlan, sizeof (ifr.ifr_name));
dummy = socket(AF_INET, SOCK_DGRAM, 0);
ret = ioctl(dummy, SIOCGIFINDEX, &ifr);
config.lanindex=ifr.ifr_ifindex;
ll.sll_family = AF_PACKET;
ll.sll_ifindex = ifr.ifr_ifindex;
ll.sll_protocol = htons(ETH_P_ALL);
if (bind(lansock, (struct sockaddr *) &ll, sizeof(struct
sockaddr_ll)) < 0) {
perror("bind");
exit(1);
}
return 0;
}
|