diff options
-rw-r--r-- | mcastseed/src/dgrambuf.h | 2 | ||||
-rw-r--r-- | mcastseed/src/mcastleech.c | 30 | ||||
-rw-r--r-- | mcastseed/src/mcastseed.c | 11 | ||||
-rw-r--r-- | mcastseed/src/random_speed_dd.c | 2 | ||||
-rw-r--r-- | mcastseed/src/sockets.c | 22 |
5 files changed, 33 insertions, 34 deletions
diff --git a/mcastseed/src/dgrambuf.h b/mcastseed/src/dgrambuf.h index 8840669..52a6696 100644 --- a/mcastseed/src/dgrambuf.h +++ b/mcastseed/src/dgrambuf.h @@ -2,7 +2,7 @@ #define DGRAMBUF_H /* * dgrambuf.c - C datagrams buffer. - * + * * Copyright 2016 by Ludovic Pouzenc <ludovic@pouzenc.fr> */ #include <stdlib.h> /* size_t */ diff --git a/mcastseed/src/mcastleech.c b/mcastseed/src/mcastleech.c index e07602d..a23e73a 100644 --- a/mcastseed/src/mcastleech.c +++ b/mcastseed/src/mcastleech.c @@ -14,8 +14,8 @@ #include <stdlib.h> /* EXIT_SUCCESS */ #include <string.h> /* strncmp() */ #include <fcntl.h> /* fcntl() */ -#include "sockets.h" -#include "dgrambuf.h" +#include "sockets.h" +#include "dgrambuf.h" #define MTU 1500 #define MULTICAST_RECV_BUF (MTU-20-8) @@ -28,7 +28,7 @@ /* Cmdline Arguments */ char *prog_name = NULL; -char *mcast_ip = NULL; +char *mcast_ip = NULL; char *port = NULL; /* Sockets as global, used everywhere, even in die() */ @@ -132,21 +132,21 @@ int wait_hello_and_connect_back() { mcast_sock = mcast_recv_socket(mcast_ip, port, MULTICAST_SO_RCVBUF_WANTED); if(mcast_sock < 0) { usage("Could not setup multicast socket. Wrong args given ?"); - } + } /* Wait for a single datagram from the server (for sync, no check on contain) */ peer_addr_len = sizeof(struct sockaddr_storage); nread = recvfrom(mcast_sock, recvbuf, MULTICAST_RECV_BUF, 0, (struct sockaddr *) &peer_addr, &peer_addr_len); - if (nread < 0 ) { + if (nread < 0 ) { perror("recvfrom() failed"); - return -1; + return -1; } /* Get peer informations as strings from peer_addr */ res = getnameinfo((struct sockaddr *) &peer_addr, peer_addr_len, hbuf, NI_MAXHOST, sbuf, NI_MAXSERV, NI_NUMERICSERV); if ( res != 0 ) { fprintf(stderr, "getnameinfo: %s\n", gai_strerror(res)); - return -2; + return -2; } /* Connect back to the server, with reliable unicast */ if ( ucast_sock > 0 ) { @@ -156,7 +156,7 @@ int wait_hello_and_connect_back() { ucast_sock = ucast_client_socket(hbuf,port); if(ucast_sock < 0) { fprintf(stderr, "Could not setup unicast socket or connect to %s:%s\n", hbuf, port); - return -3; + return -3; } return 0; @@ -167,9 +167,9 @@ int wait_start_and_start_job() { /* Wait for a "start" datagram from the server */ nread = recvfrom(mcast_sock, recvbuf, MULTICAST_RECV_BUF, 0, NULL, 0); - if (nread < 0 ) { + if (nread < 0 ) { perror("recvfrom() failed"); - return -1; + return -1; } if ( nread >= 5 && strncmp("start", recvbuf, 5) == 0 ) { /* Reply "ready" through unicast stream socket */ @@ -186,7 +186,7 @@ int wait_start_and_start_job() { return 1; } - return 0; + return 0; } /* @@ -219,7 +219,7 @@ int receive_data() { } fprintf(stderr, "receive_data(): nread == %zi, nwrite == %zi\n", nread, nwrite); - + /* XXX Crapy dead state detection */ if ( nread == 0 && nwrite == 0 ) { if ( noop_calls_count > 10 ) { @@ -296,7 +296,7 @@ void usage(char *msg) { void arg_parse(int argc, char* argv[]) { prog_name = argv[0]; if ( argc > 3 ) - usage("Too many arguments"); + usage("Too many arguments"); port = (argc >= 2)?argv[1]:DEFAULT_PORT_STR; mcast_ip = (argc >= 3)?argv[2]:DEFAULT_MCAST_IP_STR; } @@ -306,7 +306,7 @@ void fsm_trace(int state) { if ( state < 0 ) { fprintf(stderr, "Abnormal exit condition %i (from %s)\n", state, state_str[prev_state]); - } else if ( prev_state != state) { + } else if ( prev_state != state) { if ( state == 0 ) { fprintf(stderr, "Normal exit (from %s)\n", state_str[prev_state]); } else { @@ -373,7 +373,7 @@ void dgrambuf_init() { if ( dgrambuf == NULL ) { perror("dgrambuf_new/malloc"); exit(EXIT_FAILURE); - } + } fprintf(stderr, "dgrambuf_get_free_count() => %zu\n", dgrambuf_get_free_count(dgrambuf)); dgrambuf_set_validate_func(dgrambuf, validate_data_dgram); diff --git a/mcastseed/src/mcastseed.c b/mcastseed/src/mcastseed.c index 3e8b50c..48f8869 100644 --- a/mcastseed/src/mcastseed.c +++ b/mcastseed/src/mcastseed.c @@ -29,7 +29,7 @@ /* Cmdline Arguments */ char *prog_name = NULL; -char *mcast_ip = NULL; +char *mcast_ip = NULL; char *port = NULL; int mcast_ttl = 0; @@ -285,10 +285,9 @@ int send_data() { int paylen = MULTICAST_MAX_PAYLOAD_SIZE; int i; - /* XXX Dummy */ memset(buf, '.', MULTICAST_MAX_PAYLOAD_SIZE-1); - buf[MULTICAST_MAX_PAYLOAD_SIZE-1]='\n'; + buf[MULTICAST_MAX_PAYLOAD_SIZE-1]='\n'; strcpy(buf, "dataXXXXJe suis a la plage (XXXXX)"); send_fake(buf, paylen, 5); @@ -317,7 +316,7 @@ int send_data() { fprintf(stderr, "%s", "Short packet sent"); } - return 1; + return 1; } @@ -420,7 +419,7 @@ void usage(char *msg) { void arg_parse(int argc, char* argv[]) { prog_name = argv[0]; if ( argc > 3 ) - usage("Too many arguments"); + usage("Too many arguments"); port = (argc >= 2)?argv[1]:DEFAULT_PORT_STR; mcast_ip = (argc >= 3)?argv[2]:DEFAULT_MCAST_IP_STR; mcast_ttl = (argc >= 4)?atoi(argv[3]):DEFAULT_MCAST_TTL; @@ -433,7 +432,7 @@ void fsm_trace(int state) { if ( state < 0 ) { fprintf(stderr, "Abnormal exit condition %i (from %s)\n", state, state_str[prev_state]); - } else if ( prev_state != state) { + } else if ( prev_state != state) { if ( state == 0 ) { fprintf(stderr, "Normal exit (from %s)\n", state_str[prev_state]); } else { diff --git a/mcastseed/src/random_speed_dd.c b/mcastseed/src/random_speed_dd.c index 1fbc863..4d94bc0 100644 --- a/mcastseed/src/random_speed_dd.c +++ b/mcastseed/src/random_speed_dd.c @@ -33,4 +33,4 @@ int main() { return 0; } - + diff --git a/mcastseed/src/sockets.c b/mcastseed/src/sockets.c index 85abb1f..6aea016 100644 --- a/mcastseed/src/sockets.c +++ b/mcastseed/src/sockets.c @@ -82,9 +82,9 @@ int mcast_recv_socket(char *mcast_ip, char *port, int wanted_so_rcvbuf) { /* Join the multicast group. We do this seperately depending on whether we - * are using IPv4 or IPv6. + * are using IPv4 or IPv6. */ - if ( mcast_ai->ai_family == PF_INET && + if ( mcast_ai->ai_family == PF_INET && mcast_ai->ai_addrlen == sizeof(struct sockaddr_in) ) /* IPv4 */ { struct ip_mreq multicastRequest; /* Multicast address join structure */ @@ -123,7 +123,7 @@ int mcast_recv_socket(char *mcast_ip, char *port, int wanted_so_rcvbuf) { } } else { - perror("Neither IPv4 or IPv6"); + perror("Neither IPv4 or IPv6"); goto error; } @@ -182,10 +182,10 @@ int mcast_send_socket(char* mcast_ip, char* port, int multicastTTL, struct addr /* set the sending interface */ if((*mcast_ai)->ai_family == PF_INET) { in_addr_t iface = INADDR_ANY; /* well, yeah, any */ - if(setsockopt (sock, + if(setsockopt (sock, IPPROTO_IP, IP_MULTICAST_IF, - (char*)&iface, sizeof(iface)) != 0) { + (char*)&iface, sizeof(iface)) != 0) { perror("interface setsockopt() sending interface"); freeaddrinfo(*mcast_ai); return -1; @@ -194,14 +194,14 @@ int mcast_send_socket(char* mcast_ip, char* port, int multicastTTL, struct addr } if((*mcast_ai)->ai_family == PF_INET6) { unsigned int ifindex = 0; /* 0 means 'default interface'*/ - if(setsockopt (sock, + if(setsockopt (sock, IPPROTO_IPV6, IPV6_MULTICAST_IF, - (char*)&ifindex, sizeof(ifindex)) != 0) { + (char*)&ifindex, sizeof(ifindex)) != 0) { perror("interface setsockopt() sending interface"); freeaddrinfo(*mcast_ai); return -1; - } + } } @@ -236,14 +236,14 @@ int ucast_server_socket(char* port, int max_pending_conn) { /* Accepts also IPv4 traffic if the socket is INET6 */ if(serverAddr->ai_family == PF_INET6) { unsigned int no = 0; - if(setsockopt (sock, + if(setsockopt (sock, IPPROTO_IPV6, IPV6_V6ONLY, - (char*)&no, sizeof(no)) != 0) { + (char*)&no, sizeof(no)) != 0) { perror("setsockopt() !IPV6_V6ONLY failed"); freeaddrinfo(serverAddr); return -1; - } + } } /* Bind socket to local address/port */ |