feat: prepare group & packet version/type argument handling
This commit is contained in:
parent
5813cd1e72
commit
a93a54a014
1 changed files with 16 additions and 9 deletions
|
@ -21,12 +21,13 @@ struct igmp_extra {
|
|||
{ 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 },
|
||||
/* Note: end of list (please keep) */
|
||||
{ 0, 0, 0, 0 },
|
||||
};
|
||||
|
||||
void usage(char *name)
|
||||
{
|
||||
fprintf(stderr, "usage: %s -i ethdevice\n", name);
|
||||
fprintf(stderr, "usage: %s -i ethdevice -g group -t packet.version\n", name);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
|
@ -37,7 +38,7 @@ int main(int argc, char **argv)
|
|||
|
||||
/* libnet stuff */
|
||||
char neterr[LIBNET_ERRBUF_SIZE];
|
||||
libnet_t * netcontext = NULL;
|
||||
libnet_t *netcontext = NULL;
|
||||
char *device = NULL;
|
||||
|
||||
/* misc */
|
||||
|
@ -45,7 +46,7 @@ int main(int argc, char **argv)
|
|||
printf("IGMP packet generator\n\n");
|
||||
|
||||
printf("Parsing command line...\n");
|
||||
while((c = getopt(argc, argv, "i:")) != EOF)
|
||||
while((c = getopt(argc, argv, "i:g:t:")) != EOF)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
|
@ -53,7 +54,14 @@ int main(int argc, char **argv)
|
|||
printf(" Net interface = [%s]\n", optarg);
|
||||
device = optarg;
|
||||
break;
|
||||
|
||||
case 'g':
|
||||
/* Group argument handling */
|
||||
printf(" Group = [%s]\n", optarg);
|
||||
break;
|
||||
case 't':
|
||||
/* Packet version/type argument handling */
|
||||
printf(" Packet version/type = [%s]\n", optarg);
|
||||
break;
|
||||
default:
|
||||
usage(argv[0]);
|
||||
exit(1);
|
||||
|
@ -67,13 +75,11 @@ int main(int argc, char **argv)
|
|||
|
||||
printf("done\n");
|
||||
|
||||
/*
|
||||
* Memory initialization
|
||||
*/
|
||||
/* Memory initialization */
|
||||
printf("Initializing libnet context...");
|
||||
netcontext = libnet_init(LIBNET_RAW4, device, neterr);
|
||||
if (!netcontext){
|
||||
fprintf(stderr,neterr);
|
||||
fprintf(stderr, neterr);
|
||||
exit(1);
|
||||
}
|
||||
libnet_clear_packet(netcontext);
|
||||
|
@ -85,6 +91,7 @@ int main(int argc, char **argv)
|
|||
|
||||
printf("done\n");
|
||||
|
||||
/* Clean up and exit */
|
||||
libnet_destroy(netcontext);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue