reformat with clang-format

version3
David Schweikert 8 years ago
parent ecb1146fe5
commit 39acd8937f

@ -0,0 +1 @@
BasedOnStyle: WebKit

File diff suppressed because it is too large Load Diff

@ -1,4 +1,4 @@
/*
/*
* fping: fast-ping, file-ping, favorite-ping, funky-ping
*
* Ping a list of target hosts in a round robin fashion.
@ -22,8 +22,8 @@
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by Stanford University. The name of the University may not be used
* to endorse or promote products derived from this software without
* by Stanford University. The name of the University may not be used
* to endorse or promote products derived from this software without
* specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
@ -36,11 +36,11 @@
*/
#include "seqmap.h"
#include "options.h"
#include "limits.h"
#include "options.h"
#include <stdlib.h>
#include <stdio.h>
#include <stdlib.h>
/* description of the data structure used:
*
@ -51,26 +51,26 @@
* - when entering a value, we check that the current entry is expired
*/
static SEQMAP_VALUE *seqmap_map = NULL;
static SEQMAP_VALUE* seqmap_map = NULL;
static unsigned int seqmap_next_id = 0;
#define SEQMAP_TIMEOUT_IN_S 10
#define SEQMAP_TIMEOUT_IN_S 10
#define SEQMAP_UNASSIGNED_HOST_NR UINT_MAX
void seqmap_init()
{
seqmap_map = calloc(SEQMAP_MAXSEQ, sizeof(SEQMAP_VALUE));
if(seqmap_map == NULL) {
if (seqmap_map == NULL) {
perror("malloc error (can't allocate seqmap_map)");
}
}
unsigned int seqmap_add(unsigned int host_nr, unsigned int ping_count, struct timeval *now)
unsigned int seqmap_add(unsigned int host_nr, unsigned int ping_count, struct timeval* now)
{
unsigned int current_id;
SEQMAP_VALUE *next_value;
SEQMAP_VALUE* next_value;
if(!seqmap_map) {
if (!seqmap_map) {
fprintf(stderr, "fping internal error: seqmap not initialized.\n");
exit(4);
}
@ -78,7 +78,7 @@ unsigned int seqmap_add(unsigned int host_nr, unsigned int ping_count, struct ti
/* check if expired (note that unused seqmap values will have fields set to
* 0, so will be seen as expired */
next_value = &seqmap_map[seqmap_next_id];
if(next_value->ping_ts.tv_sec != 0 && (now->tv_sec - next_value->ping_ts.tv_sec) < SEQMAP_TIMEOUT_IN_S) {
if (next_value->ping_ts.tv_sec != 0 && (now->tv_sec - next_value->ping_ts.tv_sec) < SEQMAP_TIMEOUT_IN_S) {
fprintf(stderr, "fping error: not enough sequence numbers available! (expire_timeout=%d, host_nr=%d, ping_count=%d, seqmap_next_id=%d)\n",
SEQMAP_TIMEOUT_IN_S, host_nr, ping_count, seqmap_next_id);
exit(4);
@ -97,18 +97,18 @@ unsigned int seqmap_add(unsigned int host_nr, unsigned int ping_count, struct ti
return current_id;
}
SEQMAP_VALUE *seqmap_fetch(unsigned int id, struct timeval *now)
SEQMAP_VALUE* seqmap_fetch(unsigned int id, struct timeval* now)
{
SEQMAP_VALUE *value;
SEQMAP_VALUE* value;
if(id > SEQMAP_MAXSEQ) {
if (id > SEQMAP_MAXSEQ) {
return NULL;
}
value = &seqmap_map[id];
/* verify that value is not expired */
if(now->tv_sec - value->ping_ts.tv_sec >= SEQMAP_TIMEOUT_IN_S) {
if (now->tv_sec - value->ping_ts.tv_sec >= SEQMAP_TIMEOUT_IN_S) {
return NULL;
}

@ -30,8 +30,8 @@
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
#include "fping.h"
#include "config.h"
#include "fping.h"
int open_ping_socket_ipv4();
int open_ping_socket_ipv6();
@ -39,8 +39,8 @@ void init_ping_buffer_ipv4(size_t ping_data_size);
void init_ping_buffer_ipv6(size_t ping_data_size);
void socket_set_src_addr_ipv4(int s, FPING_INADDR src_addr);
void socket_set_src_addr_ipv6(int s, FPING_INADDR src_addr);
int socket_sendto_ping_ipv4(int s, struct sockaddr *saddr, socklen_t saddr_len, uint16_t icmp_seq_nr, uint16_t icmp_id_nr);
int socket_sendto_ping_ipv6(int s, struct sockaddr *saddr, socklen_t saddr_len, uint16_t icmp_seq_nr, uint16_t icmp_id_nr);
int socket_sendto_ping_ipv4(int s, struct sockaddr* saddr, socklen_t saddr_len, uint16_t icmp_seq_nr, uint16_t icmp_id_nr);
int socket_sendto_ping_ipv6(int s, struct sockaddr* saddr, socklen_t saddr_len, uint16_t icmp_seq_nr, uint16_t icmp_id_nr);
int open_ping_socket()
{
@ -69,7 +69,7 @@ void socket_set_src_addr(int s, FPING_INADDR src_addr)
#endif
}
int socket_sendto_ping(int s, struct sockaddr *saddr, socklen_t saddr_len, uint16_t icmp_seq_nr, uint16_t icmp_id_nr)
int socket_sendto_ping(int s, struct sockaddr* saddr, socklen_t saddr_len, uint16_t icmp_seq_nr, uint16_t icmp_id_nr)
{
#ifndef IPV6
return socket_sendto_ping_ipv4(s, saddr, saddr_len, icmp_seq_nr, icmp_id_nr);

@ -1,4 +1,4 @@
/*
/*
* fping: fast-ping, file-ping, favorite-ping, funky-ping
*
* Ping a list of target hosts in a round robin fashion.
@ -22,47 +22,47 @@
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by Stanford University. The name of the University may not be used
* to endorse or promote products derived from this software without
* by Stanford University. The name of the University may not be used
* to endorse or promote products derived from this software without
* specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
#include "fping.h"
#include "config.h"
#include "fping.h"
#include <sys/socket.h>
#include <fcntl.h>
#include <netdb.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <netinet/in_systm.h>
#include <netinet/ip.h>
#include <netinet/ip_icmp.h>
#include <netdb.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <fcntl.h>
#include <string.h>
#include <sys/socket.h>
char *ping_buffer = 0;
char* ping_buffer = 0;
size_t ping_pkt_size;
int open_ping_socket_ipv4()
{
struct protoent *proto;
struct protoent* proto;
int s;
/* confirm that ICMP is available on this machine */
if( ( proto = getprotobyname( "icmp" ) ) == NULL )
crash_and_burn( "icmp: unknown protocol" );
if ((proto = getprotobyname("icmp")) == NULL)
crash_and_burn("icmp: unknown protocol");
/* create raw socket for ICMP calls (ping) */
s = socket( AF_INET, SOCK_RAW, proto->p_proto );
if( s < 0 ) {
s = socket(AF_INET, SOCK_RAW, proto->p_proto);
if (s < 0) {
/* try non-privileged icmp (works on Mac OSX without privileges, for example) */
s = socket( AF_INET, SOCK_DGRAM, proto->p_proto );
if( s < 0 ) {
errno_crash_and_burn( "can't create socket (must run as root?)" );
s = socket(AF_INET, SOCK_DGRAM, proto->p_proto);
if (s < 0) {
errno_crash_and_burn("can't create socket (must run as root?)");
}
}
@ -70,10 +70,10 @@ int open_ping_socket_ipv4()
{
int flags;
if((flags = fcntl(s, F_GETFL, 0)) < 0)
if ((flags = fcntl(s, F_GETFL, 0)) < 0)
perror("fcntl");
if(fcntl(s, F_SETFL, flags | O_NONBLOCK) < 0)
if (fcntl(s, F_SETFL, flags | O_NONBLOCK) < 0)
perror("fcntl");
}
@ -84,45 +84,45 @@ void init_ping_buffer_ipv4(size_t ping_data_size)
{
/* allocate ping buffer */
ping_pkt_size = ping_data_size + ICMP_MINLEN;
ping_buffer = (char *) calloc(1, ping_pkt_size);
if(!ping_buffer)
crash_and_burn( "can't malloc ping packet" );
ping_buffer = (char*)calloc(1, ping_pkt_size);
if (!ping_buffer)
crash_and_burn("can't malloc ping packet");
}
void socket_set_src_addr_ipv4(int s, FPING_INADDR src_addr)
{
struct sockaddr_in sa;
memset( &sa, 0, sizeof( sa ) );
memset(&sa, 0, sizeof(sa));
sa.sin_family = AF_INET;
sa.sin_addr = src_addr;
if ( bind( s, (struct sockaddr *)&sa, sizeof( sa ) ) < 0 )
errno_crash_and_burn( "cannot bind source address" );
if (bind(s, (struct sockaddr*)&sa, sizeof(sa)) < 0)
errno_crash_and_burn("cannot bind source address");
}
unsigned short calcsum(unsigned short *buffer, int length)
unsigned short calcsum(unsigned short* buffer, int length)
{
unsigned long sum;
// initialize sum to zero and loop until length (in words) is 0
for (sum=0; length>1; length-=2) // sizeof() returns number of bytes, we're interested in number of words
sum += *buffer++; // add 1 word of buffer to sum and proceed to the next
/* initialize sum to zero and loop until length (in words) is 0 */
for (sum = 0; length > 1; length -= 2) /* sizeof() returns number of bytes, we're interested in number of words */
sum += *buffer++; /* add 1 word of buffer to sum and proceed to the next */
// we may have an extra byte
if (length==1)
sum += (char)*buffer;
/* we may have an extra byte */
if (length == 1)
sum += (char)*buffer;
sum = (sum >> 16) + (sum & 0xFFFF); // add high 16 to low 16
sum += (sum >> 16); // add carry
sum = (sum >> 16) + (sum & 0xFFFF); /* add high 16 to low 16 */
sum += (sum >> 16); /* add carry */
return ~sum;
}
int socket_sendto_ping_ipv4(int s, struct sockaddr *saddr, socklen_t saddr_len, uint16_t icmp_seq_nr, uint16_t icmp_id_nr)
int socket_sendto_ping_ipv4(int s, struct sockaddr* saddr, socklen_t saddr_len, uint16_t icmp_seq_nr, uint16_t icmp_id_nr)
{
struct icmp *icp;
struct icmp* icp;
int n;
icp = (struct icmp *) ping_buffer;
icp = (struct icmp*)ping_buffer;
icp->icmp_type = ICMP_ECHO;
icp->icmp_code = 0;
@ -131,12 +131,12 @@ int socket_sendto_ping_ipv4(int s, struct sockaddr *saddr, socklen_t saddr_len,
icp->icmp_id = htons(icmp_id_nr);
if (random_data_flag) {
for (n = ((void*)&icp->icmp_data - (void *)icp); n < ping_pkt_size; ++n) {
for (n = ((void*)&icp->icmp_data - (void*)icp); n < ping_pkt_size; ++n) {
ping_buffer[n] = random() & 0xFF;
}
}
icp->icmp_cksum = calcsum((unsigned short *) icp, ping_pkt_size);
icp->icmp_cksum = calcsum((unsigned short*)icp, ping_pkt_size);
n = sendto(s, icp, ping_pkt_size, 0, saddr, saddr_len);

@ -1,4 +1,4 @@
/*
/*
* fping: fast-ping, file-ping, favorite-ping, funky-ping
*
* Ping a list of target hosts in a round robin fashion.
@ -22,46 +22,46 @@
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by Stanford University. The name of the University may not be used
* to endorse or promote products derived from this software without
* by Stanford University. The name of the University may not be used
* to endorse or promote products derived from this software without
* specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
#include "fping.h"
#include "config.h"
#include "fping.h"
#include <sys/socket.h>
#include <netinet/in.h>
#include <fcntl.h>
#include <netdb.h>
#include <netinet/in.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <fcntl.h>
#include <string.h>
#include <sys/socket.h>
#include <netinet/icmp6.h>
#include <netinet/icmp6.h>
char *ping_buffer = 0;
char* ping_buffer = 0;
size_t ping_pkt_size;
int open_ping_socket_ipv6()
{
struct protoent *proto;
struct protoent* proto;
int s;
/* confirm that ICMP is available on this machine */
if( ( proto = getprotobyname( "ipv6-icmp" ) ) == NULL )
crash_and_burn( "icmp: unknown protocol" );
if ((proto = getprotobyname("ipv6-icmp")) == NULL)
crash_and_burn("icmp: unknown protocol");
/* create raw socket for ICMP calls (ping) */
s = socket( AF_INET6, SOCK_RAW, proto->p_proto );
if( s < 0 ) {
s = socket(AF_INET6, SOCK_RAW, proto->p_proto);
if (s < 0) {
/* try non-privileged icmp (works on Mac OSX without privileges, for example) */
s = socket( AF_INET6, SOCK_DGRAM, proto->p_proto );
if( s < 0 ) {
errno_crash_and_burn( "can't create raw socket (must run as root?)" );
s = socket(AF_INET6, SOCK_DGRAM, proto->p_proto);
if (s < 0) {
errno_crash_and_burn("can't create raw socket (must run as root?)");
}
}
@ -69,10 +69,10 @@ int open_ping_socket_ipv6()
{
int flags;
if((flags = fcntl(s, F_GETFL, 0)) < 0)
if ((flags = fcntl(s, F_GETFL, 0)) < 0)
perror("fcntl");
if(fcntl(s, F_SETFL, flags | O_NONBLOCK) < 0)
if (fcntl(s, F_SETFL, flags | O_NONBLOCK) < 0)
perror("fcntl");
}
@ -83,32 +83,32 @@ void init_ping_buffer_ipv6(size_t ping_data_size)
{
/* allocate ping buffer */
ping_pkt_size = ping_data_size + sizeof(struct icmp6_hdr);
ping_buffer = (char *) calloc(1, ping_pkt_size);
if(!ping_buffer)
crash_and_burn( "can't malloc ping packet" );
ping_buffer = (char*)calloc(1, ping_pkt_size);
if (!ping_buffer)
crash_and_burn("can't malloc ping packet");
}
void socket_set_src_addr_ipv6(int s, FPING_INADDR src_addr)
{
struct sockaddr_in6 sa;
memset( &sa, 0, sizeof( sa ) );
memset(&sa, 0, sizeof(sa));
sa.sin6_family = AF_INET6;
sa.sin6_addr = src_addr;
if ( bind( s, (struct sockaddr *)&sa, sizeof( sa ) ) < 0 )
errno_crash_and_burn( "cannot bind source address" );
if (bind(s, (struct sockaddr*)&sa, sizeof(sa)) < 0)
errno_crash_and_burn("cannot bind source address");
}
int socket_sendto_ping_ipv6(int s, struct sockaddr *saddr, socklen_t saddr_len, uint16_t icmp_seq_nr, uint16_t icmp_id_nr)
int socket_sendto_ping_ipv6(int s, struct sockaddr* saddr, socklen_t saddr_len, uint16_t icmp_seq_nr, uint16_t icmp_id_nr)
{
struct icmp6_hdr *icp;
struct icmp6_hdr* icp;
int n;
icp = (struct icmp6_hdr *) ping_buffer;
icp->icmp6_type = ICMP6_ECHO_REQUEST;
icp->icmp6_code = 0;
icp->icmp6_seq = htons(icmp_seq_nr);
icp->icmp6_id = htons(icmp_id_nr);
icp = (struct icmp6_hdr*)ping_buffer;
icp->icmp6_type = ICMP6_ECHO_REQUEST;
icp->icmp6_code = 0;
icp->icmp6_seq = htons(icmp_seq_nr);
icp->icmp6_id = htons(icmp_id_nr);
if (random_data_flag) {
for (n = sizeof(struct icmp6_hdr); n < ping_pkt_size; ++n) {
@ -116,7 +116,7 @@ int socket_sendto_ping_ipv6(int s, struct sockaddr *saddr, socklen_t saddr_len,
}
}
icp->icmp6_cksum = 0; // The IPv6 stack calculates the checksum for us...
icp->icmp6_cksum = 0; /* The IPv6 stack calculates the checksum for us... */
n = sendto(s, icp, ping_pkt_size, 0, saddr, saddr_len);

Loading…
Cancel
Save