Compare commits

...

7 Commits

Author SHA1 Message Date
David Schweikert a459f2ade5 update changelog 4 years ago
Dirk Meyer 60bd16119d - fix regression introduced in fping 4.3
bind to source only when option was set.
this allows to work in jails and lxc with custom IPs.
this allows IPv4 only and IPv6 only hosts
4 years ago
David Schweikert 5916abe069 change license field in fping.spec to something that seems better matching, fixes #192 4 years ago
David Schweikert 430af7803a prepare v4.4 4 years ago
Steven Noonan 57061af2be only use getsockname() for identity with SOCK_DGRAM sockets
Signed-off-by: Steven Noonan <steven@uplinklabs.net>
4 years ago
David Schweikert 33896ec021 update CHANGELOG 4 years ago
Lars Wendler 9ef7da8c5c Fix build with --disable-ipv6
Otherwise build breaks with:

fping.c:399:14: error: ‘ident6’ undeclared (first use in this function); did you mean ‘ident4’?
  399 |     ident4 = ident6 = getpid() & 0xFFFF;
      |              ^~~~~~
      |              ident4

Signed-off-by: Lars Wendler <polynomial-c@gentoo.org>
4 years ago

@ -1,3 +1,16 @@
fping 4.5 (UNRELEASED)
======================
## Bugfixes and other changes
- Bind to source only when option was set (#198, thanks @dinoex)
fping 4.4 (2020-07-24)
======================
## Bugfixes and other changes
- Fix wrong ident used for normal (non-unprivileged) pings (#191, thanks @tycho)
- Fix build with --disable-ipv6 (#187, thanks Polynomial-C)
fping 4.3 (2020-07-11) fping 4.3 (2020-07-11)
====================== ======================

@ -11,8 +11,8 @@ set -e
#fi #fi
# do this only for the master and version3 branch # do this only for the master and version3 branch
if [ "$TRAVIS_BRANCH" != "master" -a "$TRAVIS_BRANCH" != "version3" ]; then if [ "$TRAVIS_BRANCH" != "master" -a "$TRAVIS_BRANCH" != "v4.x" ]; then
echo "skipped upload branch $TRAVIS_BRANCH isn't master/version3" echo "skipped upload branch $TRAVIS_BRANCH isn't master or v4.x"
exit 0 exit 0
fi fi

@ -3,7 +3,7 @@ dnl Process this file with autoconf to produce a configure script.
dnl Minimum Autoconf version required. dnl Minimum Autoconf version required.
AC_PREREQ(2.59) AC_PREREQ(2.59)
AC_INIT([fping],[4.3]) AC_INIT([fping],[4.4])
AC_GNU_SOURCE AC_GNU_SOURCE
dnl --disable-ipv4 dnl --disable-ipv4

@ -2,7 +2,7 @@ Summary: send ICMP echo probes to multiple hosts
Name: fping Name: fping
Version: 4.2 Version: 4.2
Release: 1 Release: 1
License: BSD with advertising License: Freely redistributable without restriction
Group: Applications/System Group: Applications/System
Source0: http://fping.org/dist/%{name}-%{version}.tar.gz Source0: http://fping.org/dist/%{name}-%{version}.tar.gz
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-buildroot BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-buildroot

@ -242,13 +242,15 @@ HOST_ENTRY* ev_last;
char* prog; char* prog;
int ident4 = 0; /* our icmp identity field */ int ident4 = 0; /* our icmp identity field */
int ident6 = 0;
int socket4 = -1; int socket4 = -1;
int socktype4 = -1;
int using_sock_dgram4 = 0; int using_sock_dgram4 = 0;
#ifndef IPV6 #ifndef IPV6
int hints_ai_family = AF_INET; int hints_ai_family = AF_INET;
#else #else
int ident6 = 0;
int socket6 = -1; int socket6 = -1;
int socktype6 = -1;
int hints_ai_family = AF_UNSPEC; int hints_ai_family = AF_UNSPEC;
#endif #endif
@ -374,9 +376,16 @@ int main(int argc, char** argv)
usage(0); usage(0);
} }
socket4 = open_ping_socket_ipv4(&using_sock_dgram4); socket4 = open_ping_socket_ipv4(&socktype4);
#ifdef __linux__
/* We only treat SOCK_DGRAM differently on Linux, where the IPv4 header
* structure is missing in the message.
*/
using_sock_dgram4 = (socktype4 == SOCK_DGRAM);
#endif
#ifdef IPV6 #ifdef IPV6
socket6 = open_ping_socket_ipv6(); socket6 = open_ping_socket_ipv6(&socktype6);
/* if called (sym-linked) via 'fping6', imply '-6' /* if called (sym-linked) via 'fping6', imply '-6'
* for backward compatibility */ * for backward compatibility */
if (strstr(prog, "fping6")) { if (strstr(prog, "fping6")) {
@ -396,7 +405,7 @@ int main(int argc, char** argv)
} }
optparse_init(&optparse_state, argv); optparse_init(&optparse_state, argv);
ident4 = ident6 = getpid() & 0xFFFF; ident4 = ident6 = htons(getpid() & 0xFFFF);
verbose_flag = 1; verbose_flag = 1;
backoff_flag = 1; backoff_flag = 1;
opterr = 1; opterr = 1;
@ -986,12 +995,12 @@ int main(int argc, char** argv)
exit(num_noaddress ? 2 : 1); exit(num_noaddress ? 2 : 1);
} }
if (socket4 >= 0) { if (src_addr_set && socket4 >= 0) {
socket_set_src_addr_ipv4(socket4, &src_addr, &ident4); socket_set_src_addr_ipv4(socket4, &src_addr, (socktype4 == SOCK_DGRAM) ? &ident4 : NULL);
} }
#ifdef IPV6 #ifdef IPV6
if (socket6 >= 0) { if (src_addr6_set && socket6 >= 0) {
socket_set_src_addr_ipv6(socket6, &src_addr6, &ident6); socket_set_src_addr_ipv6(socket6, &src_addr6, (socktype6 == SOCK_DGRAM) ? &ident6 : NULL);
} }
#endif #endif

@ -14,12 +14,12 @@ int in_cksum( unsigned short *p, int n );
extern int random_data_flag; extern int random_data_flag;
/* socket.c */ /* socket.c */
int open_ping_socket_ipv4(int *using_sock_dgram); int open_ping_socket_ipv4(int *socktype);
void init_ping_buffer_ipv4(size_t ping_data_size); void init_ping_buffer_ipv4(size_t ping_data_size);
void socket_set_src_addr_ipv4(int s, struct in_addr *src_addr, int *ident); void socket_set_src_addr_ipv4(int s, struct in_addr *src_addr, int *ident);
int socket_sendto_ping_ipv4(int s, struct sockaddr *saddr, socklen_t saddr_len, uint16_t icmp_seq, uint16_t icmp_id); int socket_sendto_ping_ipv4(int s, struct sockaddr *saddr, socklen_t saddr_len, uint16_t icmp_seq, uint16_t icmp_id);
#ifdef IPV6 #ifdef IPV6
int open_ping_socket_ipv6(); int open_ping_socket_ipv6(int *socktype);
void init_ping_buffer_ipv6(size_t ping_data_size); void init_ping_buffer_ipv6(size_t ping_data_size);
void socket_set_src_addr_ipv6(int s, struct in6_addr *src_addr, int *ident); void socket_set_src_addr_ipv6(int s, struct in6_addr *src_addr, int *ident);
int socket_sendto_ping_ipv6(int s, struct sockaddr *saddr, socklen_t saddr_len, uint16_t icmp_seq, uint16_t icmp_id); int socket_sendto_ping_ipv6(int s, struct sockaddr *saddr, socklen_t saddr_len, uint16_t icmp_seq, uint16_t icmp_id);

@ -47,7 +47,7 @@
char* ping_buffer_ipv4 = 0; char* ping_buffer_ipv4 = 0;
size_t ping_pkt_size_ipv4; size_t ping_pkt_size_ipv4;
int open_ping_socket_ipv4(int *using_sock_dgram) int open_ping_socket_ipv4(int *socktype)
{ {
struct protoent* proto; struct protoent* proto;
int s; int s;
@ -56,23 +56,16 @@ int open_ping_socket_ipv4(int *using_sock_dgram)
if ((proto = getprotobyname("icmp")) == NULL) if ((proto = getprotobyname("icmp")) == NULL)
crash_and_burn("icmp: unknown protocol"); crash_and_burn("icmp: unknown protocol");
*using_sock_dgram = 0;
/* create raw socket for ICMP calls (ping) */ /* create raw socket for ICMP calls (ping) */
s = socket(AF_INET, SOCK_RAW, proto->p_proto); *socktype = SOCK_RAW;
s = socket(AF_INET, *socktype, proto->p_proto);
if (s < 0) { if (s < 0) {
/* try non-privileged icmp (works on Mac OSX without privileges, for example) */ /* try non-privileged icmp (works on Mac OSX without privileges, for example) */
s = socket(AF_INET, SOCK_DGRAM, proto->p_proto); *socktype = SOCK_DGRAM;
s = socket(AF_INET, *socktype, proto->p_proto);
if (s < 0) { if (s < 0) {
return -1; return -1;
} }
#ifdef __linux__
/* We only treat SOCK_DGRAM differently on Linux, where the IPv4 header
* structure is missing in the message.
*/
*using_sock_dgram = 1;
#endif
} }
/* Make sure that we use non-blocking IO */ /* Make sure that we use non-blocking IO */
@ -109,12 +102,14 @@ void socket_set_src_addr_ipv4(int s, struct in_addr* src_addr, int *ident)
if (bind(s, (struct sockaddr*)&sa, len) < 0) if (bind(s, (struct sockaddr*)&sa, len) < 0)
errno_crash_and_burn("cannot bind source address"); errno_crash_and_burn("cannot bind source address");
memset(&sa, 0, len); if (ident) {
if (getsockname(s, (struct sockaddr *)&sa, &len) < 0) memset(&sa, 0, len);
errno_crash_and_burn("can't get ICMP socket identity"); if (getsockname(s, (struct sockaddr *)&sa, &len) < 0)
errno_crash_and_burn("can't get ICMP socket identity");
if (sa.sin_port) if (sa.sin_port)
*ident = sa.sin_port; *ident = sa.sin_port;
}
} }
unsigned short calcsum(unsigned short* buffer, int length) unsigned short calcsum(unsigned short* buffer, int length)

@ -46,7 +46,7 @@
char* ping_buffer_ipv6 = 0; char* ping_buffer_ipv6 = 0;
size_t ping_pkt_size_ipv6; size_t ping_pkt_size_ipv6;
int open_ping_socket_ipv6() int open_ping_socket_ipv6(int *socktype)
{ {
struct protoent* proto; struct protoent* proto;
int s; int s;
@ -56,10 +56,12 @@ int open_ping_socket_ipv6()
crash_and_burn("icmp: unknown protocol"); crash_and_burn("icmp: unknown protocol");
/* create raw socket for ICMP calls (ping) */ /* create raw socket for ICMP calls (ping) */
s = socket(AF_INET6, SOCK_RAW, proto->p_proto); *socktype = SOCK_RAW;
s = socket(AF_INET6, *socktype, proto->p_proto);
if (s < 0) { if (s < 0) {
/* try non-privileged icmp (works on Mac OSX without privileges, for example) */ /* try non-privileged icmp (works on Mac OSX without privileges, for example) */
s = socket(AF_INET6, SOCK_DGRAM, proto->p_proto); *socktype = SOCK_DGRAM;
s = socket(AF_INET6, *socktype, proto->p_proto);
if (s < 0) { if (s < 0) {
return -1; return -1;
} }
@ -99,12 +101,14 @@ void socket_set_src_addr_ipv6(int s, struct in6_addr* src_addr, int *ident)
if (bind(s, (struct sockaddr*)&sa, sizeof(sa)) < 0) if (bind(s, (struct sockaddr*)&sa, sizeof(sa)) < 0)
errno_crash_and_burn("cannot bind source address"); errno_crash_and_burn("cannot bind source address");
memset(&sa, 0, len); if (ident) {
if (getsockname(s, (struct sockaddr *)&sa, &len) < 0) memset(&sa, 0, len);
errno_crash_and_burn("can't get ICMP socket identity"); if (getsockname(s, (struct sockaddr *)&sa, &len) < 0)
errno_crash_and_burn("can't get ICMP socket identity");
if (sa.sin6_port) if (sa.sin6_port)
*ident = sa.sin6_port; *ident = sa.sin6_port;
}
} }
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)

Loading…
Cancel
Save