feat: add basic support for libnet
This commit is contained in:
parent
98d6331ebc
commit
248f9e83d1
2 changed files with 30 additions and 2 deletions
|
@ -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)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <libnet.h>
|
||||
#include <netinet/igmp.h>
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue