diff --git a/src/Makefile b/src/Makefile index e5f79b4..9215177 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,8 +1,9 @@ IGMPPROG=igmpgen -CFLAGS=-Wall +CFLAGS=-Wall `libnet-config --defines` +LDFLAGS=`libnet-config --libs` all: - gcc $(CFLAGS) $(IGMPPROG).c -o $(IGMPPROG) + gcc $(CFLAGS) $(IGMPPROG).c -o $(IGMPPROG) $(LDFLAGS) clean: rm -f $(IGMPPROG) diff --git a/src/igmpgen.c b/src/igmpgen.c index 984ee59..a0a85a3 100644 --- a/src/igmpgen.c +++ b/src/igmpgen.c @@ -1,6 +1,7 @@ #include #include #include + #include #include @@ -30,6 +31,14 @@ void usage(char *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; @@ -58,6 +67,24 @@ int main(int argc, char **argv) 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; }