00001
00002
00003
00004
00005 #include <stdio.h>
00006 #include <netinet/in.h>
00007 #include <netdb.h>
00008 #include <linux/if_ether.h>
00009 #include <linux/if_packet.h>
00010 #include <linux/if.h>
00011 #include <fcntl.h>
00012 #include <sys/ioctl.h>
00013 #include <sys/types.h>
00014 #include <sys/socket.h>
00015
00016 int main(int argc, char **argv)
00017 {
00018 struct sockaddr_ll sll;
00019 int sin_len = sizeof(sll);
00020 char fd_str[10];
00021 int fd;
00022 struct ifreq ifr;
00023
00024 if (argc != 2) {
00025 printf("You must specify network interface name\n");
00026 return -1;
00027 }
00028
00029 if ((fd = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL))) < 0) {
00030 printf("Can create AF_PACKET RAW socket\n");
00031 return -1;
00032 }
00033
00034 strcpy(ifr.ifr_name, argv[1]);
00035 ioctl (fd, SIOCGIFINDEX, &ifr);
00036
00037 sll.sll_family = AF_PACKET;
00038 sll.sll_ifindex = ifr.ifr_ifindex;
00039 sll.sll_protocol = htons(ETH_P_ALL);
00040
00041 printf("Binding to %s\n", argv[1]);
00042 bind(fd, (struct sockaddr *)&sll, sin_len);
00043
00044 sprintf(fd_str, "%d", fd);
00045 printf("%d\n", execl("/bin/bash", "bash", "/mnt/hdc5/src/agnix-sf/emulators/qemu/start.sh", fd_str, NULL));
00046 }
00047