#include #include #include #include #include /* Structure to represent IGMP extra information */ struct igmp_extra { u_int8_t igmp_version; char *igmp_tag; u_int8_t igmp_type; /* IGMP type */ u_int8_t igmp_code; /* routing code */ char *igmp_dst; int group_override_dst; } g_igmp_pkts[] = { /* name, type (or version+type), code */ { 1, "query", 0x11, 0, "224.0.0.1", 0 }, { 1, "report", 0x12, 0, "224.0.0.1", 1 }, { 1, "dvmrp", 0x13, 0, "224.0.0.1", 0 }, { 2, "query", 0x11, 1, "224.0.0.1", 0 }, { 2, "report", 0x16, 1, "224.0.0.2", 1 }, { 2, "leave", 0x17, 1, "224.0.0.2", 0 }, { 0, 0, 0, 0 }, }; void usage(char *name) { fprintf(stderr, "usage: %s -i ethdevice\n", name); } int main(int argc, char **argv) { /* ip addresses */ u_int32_t ip_src = 0; char *ip_src_str = NULL; /* libnet stuff */ char neterr[LIBNET_ERRBUF_SIZE]; libnet_t *netcontext = NULL; /* misc */ int c; char *device = NULL; printf("IGMP packet generator\n\n"); printf("Parsing command line...\n"); while((c = getopt(argc, argv, "i:")) != EOF) { switch (c) { case 'i': printf(" Net interface = [%s]\n", optarg); device = optarg; break; default: usage(argv[0]); exit(1); } } if (!device) { usage(argv[0]); exit(EXIT_FAILURE); } printf("done\n"); /* * Memory initialization */ printf("Initializing libnet context..."); netcontext = libnet_init(LIBNET_RAW4, device, neterr); if (!netcontext){ fprintf(stderr,neterr); exit(1); } libnet_clear_packet(netcontext); if (!ip_src_str) { ip_src = libnet_get_ipaddr4(netcontext); ip_src_str = libnet_addr2name4(ip_src, LIBNET_DONT_RESOLVE); } printf("done\n"); return 0; }