From 2f4781214b3c0a6d312861848ea6e04ccd82edf8 Mon Sep 17 00:00:00 2001 From: David Schweikert Date: Fri, 24 Jul 2015 22:57:37 +0200 Subject: [PATCH] further unification work --- configure.ac | 2 +- src/fping.c | 4 ++-- src/fping.h | 4 ++-- src/socket.c | 16 ++++++++-------- src/socket4.c | 2 +- src/socket6.c | 4 ---- 6 files changed, 14 insertions(+), 18 deletions(-) diff --git a/configure.ac b/configure.ac index 9e60f88..fdf2808 100644 --- a/configure.ac +++ b/configure.ac @@ -29,7 +29,7 @@ if test x$ipv4 = xfalse && test x$ipv6 = xfalse; then fi AC_CANONICAL_TARGET -AM_INIT_AUTOMAKE([foreign]) +AM_INIT_AUTOMAKE([-Wall -Werror foreign]) AM_MAINTAINER_MODE AC_CONFIG_HEADERS([config.h]) diff --git a/src/fping.c b/src/fping.c index 7f41314..f3bd465 100644 --- a/src/fping.c +++ b/src/fping.c @@ -365,7 +365,7 @@ int main( int argc, char **argv ) int tos = 0; HOST_ENTRY *cursor; - s = open_ping_socket(); + s = open_ping_socket(ping_data_size); if((uid = getuid())) { /* drop privileges */ @@ -1405,7 +1405,7 @@ int send_ping( int s, HOST_ENTRY *h ) printf( "sending [%d] to %s\n", h->num_sent, h->host ); #endif /* DEBUG || _DEBUG */ - n = socket_sendto_ping(s, (struct sockaddr *) &h->saddr, h->saddr_len, ping_pkt_size, myseq, ident); + n = socket_sendto_ping(s, (struct sockaddr *) &h->saddr, h->saddr_len, myseq, ident); if( (n < 0 || n != ping_pkt_size) diff --git a/src/fping.h b/src/fping.h index d42691d..29c183c 100644 --- a/src/fping.h +++ b/src/fping.h @@ -21,8 +21,8 @@ void errno_crash_and_burn( char *message ); int in_cksum( unsigned short *p, int n ); /* socket.c */ -int open_ping_socket(); +int open_ping_socket(size_t ping_data_size); void socket_set_src_addr(int s, FPING_INADDR src_addr); -int socket_sendto_ping(int s, struct sockaddr *saddr, socklen_t saddr_len, size_t ping_pkg_size, uint16_t icmp_seq, uint16_t icmp_id); +int socket_sendto_ping(int s, struct sockaddr *saddr, socklen_t saddr_len, uint16_t icmp_seq, uint16_t icmp_id); #endif diff --git a/src/socket.c b/src/socket.c index 54ee1ec..988afdb 100644 --- a/src/socket.c +++ b/src/socket.c @@ -37,15 +37,15 @@ int open_ping_socket_ipv4(); int open_ping_socket_ipv6(); 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, size_t ping_pkg_size, uint16_t icmp_seq_nr, uint16_t icmp_id_nr); -int socket_sendto_ping_ipv6(int s, struct sockaddr *saddr, socklen_t saddr_len, size_t ping_pkg_size, 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() +int open_ping_socket(size_t ping_data_size) { #ifndef IPV6 - return open_ping_socket_ipv4(); + return open_ping_socket_ipv4(ping_data_size); #else - return open_ping_socket_ipv6(); + return open_ping_socket_ipv6(ping_data_size); #endif } @@ -58,11 +58,11 @@ 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, size_t ping_pkt_size, 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, ping_pkt_size, icmp_seq_nr, icmp_id_nr); + return socket_sendto_ping_ipv4(s, saddr, saddr_len, icmp_seq_nr, icmp_id_nr); #else - return socket_sendto_ping_ipv6(s, saddr, saddr_len, ping_pkt_size, icmp_seq_nr, icmp_id_nr); + return socket_sendto_ping_ipv6(s, saddr, saddr_len, icmp_seq_nr, icmp_id_nr); #endif } diff --git a/src/socket4.c b/src/socket4.c index 51ba9bd..318f7fe 100644 --- a/src/socket4.c +++ b/src/socket4.c @@ -84,7 +84,7 @@ void socket_set_src_addr_ipv4(int s, FPING_INADDR src_addr) errno_crash_and_burn( "cannot bind source address" ); } -int socket_sendto_ping_ipv4(int s, struct sockaddr *saddr, socklen_t saddr_len, size_t ping_pkt_size, 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; int n; diff --git a/src/socket6.c b/src/socket6.c index 361612a..c2147ed 100644 --- a/src/socket6.c +++ b/src/socket6.c @@ -92,10 +92,6 @@ int socket_sendto_ping_ipv6(int s, struct sockaddr *saddr, socklen_t saddr_len, // FIXME: randomization icp = (struct icmp6_hdr *) ping_buffer; - if(!icp) { - crash_and_burn("can't malloc ping packet"); - } - icp->icmp6_type = ICMP6_ECHO_REQUEST; icp->icmp6_code = 0; icp->icmp6_seq = htons(icmp_seq_nr);