chore: re-indent code (linux style)
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
parent
429f9aced8
commit
c92f1580df
3 changed files with 341 additions and 334 deletions
|
@ -29,4 +29,3 @@ typedef struct {
|
|||
extern ipg_igmp_extra_t g_igmp_pkts[];
|
||||
|
||||
#endif /* IGP_TYPES_H */
|
||||
|
||||
|
|
94
src/main.c
94
src/main.c
|
@ -32,7 +32,9 @@ ipg_igmp_extra_t g_igmp_pkts[] = {
|
|||
|
||||
void usage(char *);
|
||||
|
||||
ipg_igmp_extra_t * igmp_packet_type_find(u_int8_t igmp_version, char *igmp_request) {
|
||||
ipg_igmp_extra_t *igmp_packet_type_find(u_int8_t igmp_version,
|
||||
char *igmp_request)
|
||||
{
|
||||
ipg_igmp_extra_t *pkt_ptr;
|
||||
|
||||
pkt_ptr = g_igmp_pkts;
|
||||
|
@ -85,10 +87,8 @@ int main(int argc, char **argv)
|
|||
printf("Detected options:\n");
|
||||
|
||||
/* Parsing command line */
|
||||
while((c = getopt(argc, argv, "i:t:g:d:s:")) != EOF)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
while ((c = getopt(argc, argv, "i:t:g:d:s:")) != EOF) {
|
||||
switch (c) {
|
||||
case 'i':
|
||||
printf(" Net interface = [%s]\n", optarg);
|
||||
device = optarg;
|
||||
|
@ -105,7 +105,8 @@ int main(int argc, char **argv)
|
|||
|
||||
pkt_ptr = igmp_packet_type_find(igmp_version, cp);
|
||||
if (!pkt_ptr) {
|
||||
printf("ERROR: Packet type %d.%s not found!\n", igmp_version, cp);
|
||||
printf("ERROR: Packet type %d.%s not found!\n",
|
||||
igmp_version, cp);
|
||||
usage(argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
|
@ -114,7 +115,8 @@ int main(int argc, char **argv)
|
|||
igmp_code = pkt_ptr->igmp_code;
|
||||
ip_dst_str = pkt_ptr->igmp_dst;
|
||||
igmp_override = pkt_ptr->group_override_dst;
|
||||
printf(" Packet = [%s] version [%d]\n", pkt_ptr->igmp_tag, igmp_version);
|
||||
printf(" Packet = [%s] version [%d]\n",
|
||||
pkt_ptr->igmp_tag, igmp_version);
|
||||
break;
|
||||
|
||||
case 'g':
|
||||
|
@ -135,27 +137,27 @@ int main(int argc, char **argv)
|
|||
* just the IP address, and cp points to the port.
|
||||
*/
|
||||
|
||||
if ((cp = strrchr(optarg, ':')))
|
||||
{
|
||||
if ((cp = strrchr(optarg, ':'))) {
|
||||
*cp++ = 0;
|
||||
dst_prt = (u_short) atoi(cp);
|
||||
} else {
|
||||
dst_prt = 0;
|
||||
}
|
||||
ip_dst_str = strdup(optarg);
|
||||
printf(" Destination = ip [%s] port [%d]\n", ip_dst_str, dst_prt);
|
||||
printf(" Destination = ip [%s] port [%d]\n",
|
||||
ip_dst_str, dst_prt);
|
||||
break;
|
||||
|
||||
case 's':
|
||||
if ((cp = strrchr(optarg, ':')))
|
||||
{
|
||||
if ((cp = strrchr(optarg, ':'))) {
|
||||
*cp++ = 0;
|
||||
src_prt = (u_short) atoi(cp);
|
||||
} else {
|
||||
src_prt = 0;
|
||||
}
|
||||
ip_src_str = strdup(optarg);
|
||||
printf(" Source = ip [%s] port [%d]\n", ip_src_str, src_prt);
|
||||
printf(" Source = ip [%s] port [%d]\n", ip_src_str,
|
||||
src_prt);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -164,15 +166,13 @@ int main(int argc, char **argv)
|
|||
}
|
||||
}
|
||||
|
||||
if (!igmp_group_str)
|
||||
{
|
||||
if (!igmp_group_str) {
|
||||
usage(argv[0]);
|
||||
fprintf(stderr, "ERROR: missing destination IGMP group\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (!device)
|
||||
{
|
||||
if (!device) {
|
||||
usage(argv[0]);
|
||||
fprintf(stderr, "ERROR: missing device\n");
|
||||
exit(EXIT_FAILURE);
|
||||
|
@ -198,8 +198,7 @@ int main(int argc, char **argv)
|
|||
|
||||
/* Packet construction: IGMP */
|
||||
printf(" Building IGMP content...\n");
|
||||
ptag = libnet_build_igmp(
|
||||
igmp_type, // IGMP type
|
||||
ptag = libnet_build_igmp(igmp_type, // IGMP type
|
||||
igmp_code, // IGMP code
|
||||
0, // checksum
|
||||
0, // group address
|
||||
|
@ -209,7 +208,8 @@ int main(int argc, char **argv)
|
|||
0 // ptag
|
||||
);
|
||||
if (ptag == -1) {
|
||||
fprintf(stderr, "Error building IGMP header: %s\n", libnet_geterror(netcontext));
|
||||
fprintf(stderr, "Error building IGMP header: %s\n",
|
||||
libnet_geterror(netcontext));
|
||||
libnet_destroy(netcontext);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
@ -218,7 +218,8 @@ int main(int argc, char **argv)
|
|||
|
||||
/* Send packet */
|
||||
if (libnet_write(netcontext) == -1) {
|
||||
fprintf(stderr, "Error sending packet: %s\n", libnet_geterror(netcontext));
|
||||
fprintf(stderr, "Error sending packet: %s\n",
|
||||
libnet_geterror(netcontext));
|
||||
} else {
|
||||
printf("Packet sent successfully.\n");
|
||||
}
|
||||
|
@ -255,22 +256,24 @@ int main(int argc, char **argv)
|
|||
}
|
||||
|
||||
if (ip_src_test
|
||||
&& !(ip_src = libnet_name2addr4(netcontext, ip_src_str, LIBNET_RESOLVE)))
|
||||
{
|
||||
&& !(ip_src =
|
||||
libnet_name2addr4(netcontext, ip_src_str, LIBNET_RESOLVE))) {
|
||||
fprintf(stderr, "Bad source IP address: %s\n", ip_src_str);
|
||||
fprintf(stderr, "%s\n", libnet_geterror(netcontext));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (ip_dst_test
|
||||
&& !(ip_dst = libnet_name2addr4(netcontext, ip_dst_str, LIBNET_RESOLVE)))
|
||||
{
|
||||
&& !(ip_dst =
|
||||
libnet_name2addr4(netcontext, ip_dst_str, LIBNET_RESOLVE))) {
|
||||
fprintf(stderr, "Bad destination IP address: %s\n", ip_dst_str);
|
||||
fprintf(stderr, "%s\n", libnet_geterror(netcontext));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (igmp_group_test && !(igmp_group = libnet_name2addr4(netcontext, igmp_group_str, LIBNET_RESOLVE)))
|
||||
if (igmp_group_test
|
||||
&& !(igmp_group =
|
||||
libnet_name2addr4(netcontext, igmp_group_str, LIBNET_RESOLVE)))
|
||||
{
|
||||
fprintf(stderr, "Bad group IP address: %s\n", optarg);
|
||||
fprintf(stderr, "%s\n", libnet_geterror(netcontext));
|
||||
|
@ -295,8 +298,7 @@ int main(int argc, char **argv)
|
|||
}
|
||||
*/
|
||||
|
||||
ptag = libnet_build_igmp(
|
||||
igmp_type, // IGMP type
|
||||
ptag = libnet_build_igmp(igmp_type, // IGMP type
|
||||
igmp_code, // IGMP code or TTL
|
||||
0, // checksum
|
||||
htonl(igmp_group), // ip addr
|
||||
|
@ -304,26 +306,26 @@ int main(int argc, char **argv)
|
|||
0, // Packet payload length
|
||||
netcontext, // Ptr to libnet context
|
||||
0); // Build a new packet header
|
||||
if (ptag < 0)
|
||||
{
|
||||
fprintf(stderr, "Error while building IGMP header data (err %d)\n", ptag);
|
||||
if (ptag < 0) {
|
||||
fprintf(stderr,
|
||||
"Error while building IGMP header data (err %d)\n",
|
||||
ptag);
|
||||
fprintf(stderr, "%s\n", libnet_geterror(netcontext));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
u_int8_t ipopt[2];
|
||||
ipopt[0] = IPOPT_RA;
|
||||
ipopt[1] = 4;
|
||||
ptag = libnet_build_ipv4_options(
|
||||
ipopt, // options
|
||||
ptag = libnet_build_ipv4_options(ipopt, // options
|
||||
2, // options_s (length of option string)
|
||||
netcontext, // libnet context
|
||||
0 // ptag
|
||||
);
|
||||
if (ptag < 0)
|
||||
{
|
||||
fprintf(stderr, "Error while building IPv4 options data (err %d)\n", ptag);
|
||||
if (ptag < 0) {
|
||||
fprintf(stderr,
|
||||
"Error while building IPv4 options data (err %d)\n",
|
||||
ptag);
|
||||
}
|
||||
|
||||
ptag = libnet_build_ipv4(LIBNET_IPV4_H + LIBNET_IGMP_H, // pkg size + data
|
||||
|
@ -340,9 +342,10 @@ int main(int argc, char **argv)
|
|||
netcontext, // libnet context
|
||||
0 // build a new header
|
||||
);
|
||||
if (ptag < 0)
|
||||
{
|
||||
fprintf(stderr, "Error while building IPv4 header data (err %d)\n", ptag);
|
||||
if (ptag < 0) {
|
||||
fprintf(stderr,
|
||||
"Error while building IPv4 header data (err %d)\n",
|
||||
ptag);
|
||||
fprintf(stderr, "%s\n", libnet_geterror(netcontext));
|
||||
exit(1);
|
||||
}
|
||||
|
@ -350,13 +353,12 @@ int main(int argc, char **argv)
|
|||
printf(" done\n"); //IGMP content
|
||||
|
||||
c = libnet_write(netcontext);
|
||||
if (c < 0)
|
||||
{
|
||||
if (c < 0) {
|
||||
fprintf(stderr, "%s\n", libnet_geterror(netcontext));
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("construction and injection completed, wrote all %d bytes\n", c);
|
||||
} else {
|
||||
printf
|
||||
("construction and injection completed, wrote all %d bytes\n",
|
||||
c);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
22
src/usage.c
22
src/usage.c
|
@ -11,20 +11,26 @@ void usage(const char *name)
|
|||
|
||||
fprintf(stderr, "Usage: %s [options]\n", basename(name));
|
||||
fprintf(stderr, "\nOptions:\n");
|
||||
fprintf(stderr, " -i <interface> Specify the network interface (e.g., eth0)\n");
|
||||
fprintf(stderr, " -t <type> Specify the IGMP packet type and version (e.g., 1.query)\n");
|
||||
fprintf(stderr, " -g <group> Specify the destination IGMP group (e.g., 224.0.0.1)\n");
|
||||
fprintf(stderr, " -s <source> Specify the source IP and port (e.g., 192.168.1.1:1234)\n");
|
||||
fprintf(stderr, " -d <destination> Specify the destination IP and port (e.g., 224.0.0.2:5678)\n");
|
||||
fprintf(stderr, " -n <number> Specify delay between packets in seconds (optional)\n");
|
||||
fprintf(stderr,
|
||||
" -i <interface> Specify the network interface (e.g., eth0)\n");
|
||||
fprintf(stderr,
|
||||
" -t <type> Specify the IGMP packet type and version (e.g., 1.query)\n");
|
||||
fprintf(stderr,
|
||||
" -g <group> Specify the destination IGMP group (e.g., 224.0.0.1)\n");
|
||||
fprintf(stderr,
|
||||
" -s <source> Specify the source IP and port (e.g., 192.168.1.1:1234)\n");
|
||||
fprintf(stderr,
|
||||
" -d <destination> Specify the destination IP and port (e.g., 224.0.0.2:5678)\n");
|
||||
fprintf(stderr,
|
||||
" -n <number> Specify delay between packets in seconds (optional)\n");
|
||||
|
||||
fprintf(stderr, "\nAvailable IGMP packet types:\n");
|
||||
|
||||
pkt_ptr = g_igmp_pkts;
|
||||
while (pkt_ptr->igmp_version || pkt_ptr->igmp_tag) {
|
||||
fprintf(stderr," - %d.%s\n", pkt_ptr->igmp_version, pkt_ptr->igmp_tag);
|
||||
fprintf(stderr, " - %d.%s\n", pkt_ptr->igmp_version,
|
||||
pkt_ptr->igmp_tag);
|
||||
pkt_ptr++;
|
||||
}
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue