[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [bug-inetutils] regarding ping6 -c Segmentation fault
From: |
Rakesh Pandit |
Subject: |
Re: [bug-inetutils] regarding ping6 -c Segmentation fault |
Date: |
Wed, 20 Aug 2008 10:27:20 +0530 |
2008/8/17 Alfred M. Szmidt <address@hidden>:
> This breaks ping6 for non-root users. ping and ping6 should be using
> the same startup code.
>
Thanks for review.
I had been working on moving common code to ping_common from a while.
I had to do some pre-work to start moving code so that may result in
bigger initial patch :-(
I have working prototype of initial work and want comments to improve
& correct approach in case I am going wrong.
Protype involves three patches
1. It was very much important to use a common PING & move files
(ping.h & libping.c ) from libicmp to ping. First patch & Sencond are
for ping.h & libping.c respectively
2. third patch contains Makefile.am changes in both libicmp & ping
folder. It also contains first set of common functions moved to
ping_common: _ping_setbuf & ping_set_data
Suggestions ? Any suggestions regarding breaking this into smaller parts ?
--
Rakesh Pandit
First patch:
--- libicmp/ping.h.org 2008-08-20 09:33:34.000000000 +0530
+++ ping/ping.h 2008-08-20 09:34:45.000000000 +0530
@@ -17,38 +17,7 @@
to the Free Software Foundation, Inc., 51 Franklin Street,
Fifth Floor, Boston, MA 02110-1301 USA. */
-typedef struct ping_data PING;
-typedef int (*ping_efp) (int code,
- void *closure,
- struct sockaddr_in * dest,
- struct sockaddr_in * from,
- struct ip * ip, icmphdr_t * icmp, int datalen);
-
-
-struct ping_data
-{
- int ping_fd; /* Raw socket descriptor */
- int ping_type; /* Type of packets to send */
- size_t ping_count; /* Number of packets to send */
- size_t ping_interval; /* Number of seconds to wait between
sending pkts */
- struct sockaddr_in ping_dest; /* whom to ping */
- char *ping_hostname; /* Printable hostname */
- size_t ping_datalen; /* Length of data */
- int ping_ident; /* Our identifier */
-
- ping_efp ping_event; /* User-defined handler */
- void *ping_closure; /* User-defined data */
-
- /* Runtime info */
- int ping_cktab_size;
- char *ping_cktab;
-
- u_char *ping_buffer; /* I/O buffer */
- struct sockaddr_in ping_from;
- long ping_num_xmit; /* Number of packets transmitted */
- long ping_num_recv; /* Number of packets received */
- long ping_num_rept; /* Number of duplicates received */
-};
+#include "ping_common.h"
#define PEV_RESPONSE 0
#define PEV_DUPLICATE 1
@@ -62,8 +31,6 @@
(t).tv_usec = ((i)%PING_PRECISION)*(1000000/PING_PRECISION) ;\
} while (0)
-#define _PING_BUFLEN(p) ((p)->ping_datalen + sizeof (icmphdr_t))
-
#define _C_BIT(p,bit) (p)->ping_cktab[(bit)>>3] /* byte in ck array */
#define _C_MASK(bit) (1 << ((bit) & 0x07))
@@ -81,7 +48,6 @@
int ping_set_dest (PING * ping, char *host);
int ping_set_pattern (PING * p, int len, u_char * pat);
void ping_set_event_handler (PING * ping, ping_efp fp, void *closure);
-int ping_set_data (PING * p, void *data, size_t off, size_t len);
void ping_set_datalen (PING * p, size_t len);
void ping_unset_data (PING * p);
int ping_recv (PING * p);
Second patch:
--- libicmp/libping.c.org 2008-08-20 09:33:55.000000000 +0530
+++ ping/libping.c 2008-08-20 09:38:43.000000000 +0530
@@ -27,9 +27,6 @@
#include <sys/time.h>
#include <signal.h>
-#include <netinet/in_systm.h>
-#include <netinet/in.h>
-#include <netinet/ip.h>
/*#include <netinet/ip_icmp.h> -- deliberately not including this */
#include <arpa/inet.h>
#include <netdb.h>
@@ -39,11 +36,9 @@
#include <errno.h>
#include <string.h>
-#include <icmp.h>
#include "ping.h"
static void _ping_freebuf (PING * p);
-static int _ping_setbuf (PING * p);
static size_t _ping_packetsize (PING * p);
size_t
@@ -134,39 +129,6 @@
}
}
-int
-_ping_setbuf (PING * p)
-{
- if (!p->ping_buffer)
- {
- p->ping_buffer = malloc (_PING_BUFLEN (p));
- if (!p->ping_buffer)
- return -1;
- }
- if (!p->ping_cktab)
- {
- p->ping_cktab = malloc (p->ping_cktab_size);
- if (!p->ping_cktab)
- return -1;
- memset (p->ping_cktab, 0, p->ping_cktab_size);
- }
- return 0;
-}
-
-int
-ping_set_data (PING * p, void *data, size_t off, size_t len)
-{
- icmphdr_t *icmp;
-
- if (_ping_setbuf (p))
- return -1;
- if (p->ping_datalen < off + len)
- return -1;
- icmp = (icmphdr_t *) p->ping_buffer;
- memcpy (icmp->icmp_data + off, data, len);
- return 0;
-}
-
void
ping_unset_data (PING * p)
{
@@ -211,7 +173,7 @@
}
i = sendto (p->ping_fd, (char *) p->ping_buffer, buflen, 0,
- (struct sockaddr *) &p->ping_dest, sizeof (struct sockaddr_in));
+ (struct sockaddr *) &p->ping_dest.address, sizeof (struct
sockaddr_in));
if (i < 0)
perror ("ping: sendto");
else
@@ -230,7 +192,7 @@
struct ip *orig_ip = &icmp->icmp_ip;
icmphdr_t *orig_icmp = (icmphdr_t *) (orig_ip + 1);
- return (orig_ip->ip_dst.s_addr == p->ping_dest.sin_addr.s_addr
+ return (orig_ip->ip_dst.s_addr == p->ping_dest.address.sin_addr.s_addr
&& orig_ip->ip_p == IPPROTO_ICMP
&& orig_icmp->icmp_type == ICMP_ECHO
&& orig_icmp->icmp_id == p->ping_ident);
@@ -239,7 +201,7 @@
int
ping_recv (PING * p)
{
- int fromlen = sizeof (p->ping_from);
+ int fromlen = sizeof (p->ping_from.address);
int n, rc;
icmphdr_t *icmp;
struct ip *ip;
@@ -247,7 +209,7 @@
n = recvfrom (p->ping_fd,
(char *) p->ping_buffer, _PING_BUFLEN (p), 0,
- (struct sockaddr *) &p->ping_from, &fromlen);
+ (struct sockaddr *) &p->ping_from.address, &fromlen);
if (n < 0)
return -1;
@@ -256,7 +218,7 @@
{
/*FIXME: conditional */
fprintf (stderr, "packet too short (%d bytes) from %s\n", n,
- inet_ntoa (p->ping_from.sin_addr));
+ inet_ntoa (p->ping_from.address.sin_addr));
return -1;
}
@@ -272,7 +234,7 @@
if (rc)
fprintf (stderr, "checksum mismatch from %s\n",
- inet_ntoa (p->ping_from.sin_addr));
+ inet_ntoa (p->ping_from.address.sin_addr));
p->ping_num_recv++;
if (_PING_TST (p, icmp->icmp_seq % p->ping_cktab_size))
@@ -287,10 +249,10 @@
dupflag = 0;
}
- if (p->ping_event)
- (*p->ping_event) (dupflag ? PEV_DUPLICATE : PEV_RESPONSE,
+ if (p->ping_event.handler)
+ (*p->ping_event.handler) (dupflag ? PEV_DUPLICATE : PEV_RESPONSE,
p->ping_closure,
- &p->ping_dest, &p->ping_from, ip, icmp, n);
+ &p->ping_dest.address, &p->ping_from.address, ip,
icmp, n);
break;
case ICMP_ECHO:
@@ -302,10 +264,10 @@
if (!my_echo_reply (p, icmp))
return -1;
- if (p->ping_event)
- (*p->ping_event) (PEV_NOECHO,
+ if (p->ping_event.handler)
+ (*p->ping_event.handler) (PEV_NOECHO,
p->ping_closure,
- &p->ping_dest, &p->ping_from, ip, icmp, n);
+ &p->ping_dest.address, &p->ping_from.address, ip,
icmp, n);
}
return 0;
}
@@ -313,7 +275,7 @@
void
ping_set_event_handler (PING * ping, ping_efp pf, void *closure)
{
- ping->ping_event = pf;
+ ping->ping_event.handler = pf;
ping->ping_closure = closure;
}
@@ -344,7 +306,7 @@
int
ping_set_dest (PING * ping, char *host)
{
- struct sockaddr_in *s_in = &ping->ping_dest;
+ struct sockaddr_in *s_in = &ping->ping_dest.address;
s_in->sin_family = AF_INET;
if (inet_aton (host, &s_in->sin_addr))
ping->ping_hostname = strdup (host);
Third patch:
Index: libicmp/Makefile.am
===================================================================
RCS file: /sources/inetutils/inetutils/libicmp/Makefile.am,v
retrieving revision 1.6
diff -u -r1.6 Makefile.am
--- libicmp/Makefile.am 29 Jun 2007 16:29:32 -0000 1.6
+++ libicmp/Makefile.am 20 Aug 2008 04:49:37 -0000
@@ -18,10 +18,9 @@
noinst_LIBRARIES = libicmp.a
-libicmp_a_SOURCES = libping.c \
- icmp_echo.c \
+libicmp_a_SOURCES = icmp_echo.c \
icmp_timestamp.c \
icmp_address.c \
icmp_cksum.c
-noinst_HEADERS = icmp.h ping.h
+noinst_HEADERS = icmp.h
Index: ping/Makefile.am
===================================================================
RCS file: /sources/inetutils/inetutils/ping/Makefile.am,v
retrieving revision 1.22
diff -u -r1.22 Makefile.am
--- ping/Makefile.am 29 Jun 2007 16:29:31 -0000 1.22
+++ ping/Makefile.am 20 Aug 2008 04:49:37 -0000
@@ -29,7 +29,7 @@
-I$(top_srcdir)/libinetutils
ping_SOURCES = ping.c ping_common.c ping_echo.c ping_address.c \
- ping_router.c ping_timestamp.c ping_common.h ping_impl.h
+ ping_router.c ping_timestamp.c ping_common.h ping_impl.h ping.h libping.c
ping6_SOURCES = ping6.c ping_common.c ping_common.h ping6.h
SUIDMODE = -o root -m 4775
Index: ping/ping.c
===================================================================
RCS file: /sources/inetutils/inetutils/ping/ping.c,v
retrieving revision 1.35
diff -u -r1.35 ping.c
--- ping/ping.c 6 Jun 2008 16:43:43 -0000 1.35
+++ ping/ping.c 20 Aug 2008 04:49:37 -0000
@@ -28,9 +28,6 @@
#include <sys/time.h>
#include <signal.h>
-#include <netinet/in_systm.h>
-#include <netinet/in.h>
-#include <netinet/ip.h>
/*#include <netinet/ip_icmp.h> -- deliberately not including this */
#ifdef HAVE_NETINET_IP_VAR_H
# include <netinet/ip_var.h>
@@ -48,9 +45,7 @@
#include <limits.h>
#include <argp.h>
-#include <icmp.h>
#include <ping.h>
-#include "ping_common.h"
#include "ping_impl.h"
#include "libinetutils.h"
Index: ping/ping6.c
===================================================================
RCS file: /sources/inetutils/inetutils/ping/ping6.c,v
retrieving revision 1.11
diff -u -r1.11 ping6.c
--- ping/ping6.c 6 Jun 2008 16:43:43 -0000 1.11
+++ ping/ping6.c 20 Aug 2008 04:49:38 -0000
@@ -42,17 +42,19 @@
#include <limits.h>
#include <xalloc.h>
-#include "ping_common.h"
#include "ping6.h"
#include "libinetutils.h"
static PING *ping;
-bool is_root;
+bool is_root = false;
unsigned char *data_buffer;
u_char *patptr;
int one = 1;
int pattern_len = 16;
size_t data_length = PING_DATALEN;
+size_t count = DEFAULT_PING_COUNT;
+size_t interval;
+int socket_type;
static unsigned int options;
static unsigned long preload = 0;
@@ -96,15 +98,16 @@
{
char *endptr;
u_char pattern[16];
+ double v;
switch (key)
{
case 'c':
- ping->ping_count = ping_cvt_number (arg, 0, 0);
+ count = ping_cvt_number (arg, 0, 0);
break;
case 'd':
- setsockopt (ping->ping_fd, SOL_SOCKET, SO_DEBUG, &one, sizeof (one));
+ socket_type = SO_DEBUG;
break;
case 'f':
@@ -117,7 +120,7 @@
case 'i':
options |= OPT_INTERVAL;
- ping->ping_interval = ping_cvt_number (arg, 0, 0);
+ interval = ping_cvt_number (arg, 0, 0);
break;
case 'l':
@@ -144,7 +147,7 @@
break;
case 'r':
- setsockopt (ping->ping_fd, SOL_SOCKET, SO_DONTROUTE, &one, sizeof (one));
+ socket_type = SO_DEBUG;
break;
case 's':
@@ -188,6 +191,15 @@
argc -= index;
argv += index;
+ if (count != 0)
+ ping->ping_count = count;
+
+ if (socket_type != 0)
+ setsockopt (ping->ping_fd, SOL_SOCKET, socket_type, &one, sizeof (one));
+
+ if (options & OPT_INTERVAL)
+ ping->ping_interval = interval;
+
init_data_buffer (patptr, pattern_len);
while (argc--)
@@ -417,8 +429,8 @@
if (ping_set_dest (ping, hostname))
error (EXIT_FAILURE, 0, "unknown host %s", hostname);
- err = getnameinfo ((struct sockaddr *) &ping->ping_dest,
- sizeof (ping->ping_dest), buffer,
+ err = getnameinfo ((struct sockaddr *) &ping->ping_dest.address6,
+ sizeof (ping->ping_dest.address6), buffer,
sizeof (buffer), NULL, 0, NI_NUMERICHOST);
if (err)
{
@@ -729,37 +741,6 @@
}
static int
-_ping_setbuf (PING * p)
-{
- if (!p->ping_buffer)
- {
- p->ping_buffer = malloc (_PING_BUFLEN (p));
- if (!p->ping_buffer)
- return -1;
- }
- if (!p->ping_cktab)
- {
- p->ping_cktab = malloc (p->ping_cktab_size);
- if (!p->ping_cktab)
- return -1;
- memset (p->ping_cktab, 0, p->ping_cktab_size);
- }
- return 0;
-}
-
-static int
-ping_set_data (PING * p, void *data, size_t off, size_t len)
-{
- if (_ping_setbuf (p))
- return -1;
- if (p->ping_datalen < off + len)
- return -1;
- memcpy (p->ping_buffer + sizeof (struct icmp6_hdr) + off, data, len);
-
- return 0;
-}
-
-static int
ping_xmit (PING * p)
{
int i, buflen;
@@ -782,7 +763,7 @@
icmp6->icmp6_seq = htons (p->ping_num_xmit);
i = sendto (p->ping_fd, (char *) p->ping_buffer, buflen, 0,
- (struct sockaddr *) &p->ping_dest, sizeof (p->ping_dest));
+ (struct sockaddr *) &p->ping_dest.address6, sizeof
(p->ping_dest.address6));
if (i < 0)
perror ("ping: sendto");
else
@@ -802,7 +783,7 @@
struct ip6_hdr *orig_ip = (struct ip6_hdr *) (icmp6 + 1);
struct icmp6_hdr *orig_icmp = (struct icmp6_hdr *) (orig_ip + 1);
- return IN6_ARE_ADDR_EQUAL (&orig_ip->ip6_dst, &ping->ping_dest.sin6_addr)
+ return IN6_ARE_ADDR_EQUAL (&orig_ip->ip6_dst,
&ping->ping_dest.address6.sin6_addr)
&& orig_ip->ip6_nxt == IPPROTO_ICMPV6
&& orig_icmp->icmp6_type == ICMP6_ECHO_REQUEST
&& orig_icmp->icmp6_id == htons (p->ping_ident);
@@ -820,9 +801,9 @@
char cmsg_data[1024];
iov.iov_base = p->ping_buffer;
- iov.iov_len = _PING_BUFLEN (p);
- msg.msg_name = &p->ping_from;
- msg.msg_namelen = sizeof (p->ping_from);
+ iov.iov_len = _PING_BUFLEN(p);
+ msg.msg_name = &p->ping_from.address6;
+ msg.msg_namelen = sizeof (p->ping_from.address6);
msg.msg_iov = &iov;
msg.msg_iovlen = 1;
msg.msg_control = cmsg_data;
@@ -863,8 +844,8 @@
dupflag = 0;
}
- print_echo (dupflag, hops, p->ping_closure, &p->ping_dest,
- &p->ping_from, icmp6, n);
+ print_echo (dupflag, hops, p->ping_closure, &p->ping_dest.address6,
+ &p->ping_from.address6, icmp6, n);
}
else
@@ -873,7 +854,7 @@
if (!my_echo_reply (p, icmp6))
return -1; /* It's not for us. */
- print_icmp_error (&p->ping_from, icmp6, n);
+ print_icmp_error (&p->ping_from.address6, icmp6, n);
}
return 0;
@@ -893,7 +874,7 @@
if (err)
return 1;
- memcpy (&ping->ping_dest, result->ai_addr, result->ai_addrlen);
+ memcpy (&ping->ping_dest.address6, result->ai_addr, result->ai_addrlen);
freeaddrinfo (result);
Index: ping/ping6.h
===================================================================
RCS file: /sources/inetutils/inetutils/ping/ping6.h,v
retrieving revision 1.4
diff -u -r1.4 ping6.h
--- ping/ping6.h 29 Jun 2007 16:29:30 -0000 1.4
+++ ping/ping6.h 20 Aug 2008 04:49:38 -0000
@@ -17,39 +17,7 @@
to the Free Software Foundation, Inc., 51 Franklin Street,
Fifth Floor, Boston, MA 02110-1301 USA. */
-#include <netinet/in.h>
-#include <netinet/icmp6.h>
-
-typedef struct ping_data PING;
-typedef int (*ping_efp) (int code, void *closure, struct sockaddr_in6 * dest,
- struct sockaddr_in6 * from, struct icmp6_hdr * icmp,
- int datalen);
-
-
-struct ping_data
-{
- int ping_fd; /* Raw socket descriptor */
- int ping_type; /* Type of packets to send */
- int ping_count; /* Number of packets to send */
- int ping_interval; /* Number of seconds to wait between sending
pkts */
- struct sockaddr_in6 ping_dest; /* whom to ping */
- char *ping_hostname; /* Printable hostname */
- size_t ping_datalen; /* Length of data */
- int ping_ident; /* Our identifier */
-
- ping_efp ping_event; /* User-defined handler */
- void *ping_closure; /* User-defined data */
-
- /* Runtime info */
- int ping_cktab_size;
- char *ping_cktab;
-
- u_char *ping_buffer; /* I/O buffer */
- struct sockaddr_in6 ping_from;
- long ping_num_xmit; /* Number of packets transmitted */
- long ping_num_recv; /* Number of packets received */
- long ping_num_rept; /* Number of duplicates received */
-};
+#include "ping_common.h"
struct ping_stat
{
@@ -80,6 +48,7 @@
#define PING_DATALEN (64 - PING_HEADER_LEN) /* default data length */
#define PING_MAX_DATALEN (65535 - sizeof (struct icmp6_hdr))
+#undef _PING_BUFLEN
#define _PING_BUFLEN(p) ((p)->ping_datalen + sizeof (struct icmp6_hdr))
#define _C_BIT(p,bit) (p)->ping_cktab[(bit)>>3] /* byte in ck array */
@@ -91,7 +60,6 @@
static PING *ping_init (int type, int ident);
static int ping_set_dest (PING * ping, char *host);
-static int ping_set_data (PING * p, void *data, size_t off, size_t len);
static int ping_recv (PING * p);
static int ping_xmit (PING * p);
Index: ping/ping_address.c
===================================================================
RCS file: /sources/inetutils/inetutils/ping/ping_address.c,v
retrieving revision 1.11
diff -u -r1.11 ping_address.c
--- ping/ping_address.c 6 Jun 2008 16:43:43 -0000 1.11
+++ ping/ping_address.c 20 Aug 2008 04:49:40 -0000
@@ -28,9 +28,6 @@
#include <sys/time.h>
#include <signal.h>
-#include <netinet/in_systm.h>
-#include <netinet/in.h>
-#include <netinet/ip.h>
/*#include <netinet/ip_icmp.h> -- deliberately not including this */
#ifdef HAVE_NETINET_IP_VAR_H
# include <netinet/ip_var.h>
@@ -45,12 +42,9 @@
#include <ctype.h>
#include <errno.h>
-#include <icmp.h>
#include <ping.h>
#include <ping_impl.h>
-#include "ping_common.h"
-
static int recv_address (int code, void *closure,
struct sockaddr_in *dest, struct sockaddr_in *from,
struct ip *ip, icmphdr_t * icmp, int datalen);
@@ -74,7 +68,7 @@
error (EXIT_FAILURE, 0, "unknown host");
printf ("PING %s (%s): sending address mask request\n",
- ping->ping_hostname, inet_ntoa (ping->ping_dest.sin_addr));
+ ping->ping_hostname, inet_ntoa (ping->ping_dest.address.sin_addr));
return ping_run (ping, address_finish);
}
Index: ping/ping_common.c
===================================================================
RCS file: /sources/inetutils/inetutils/ping/ping_common.c,v
retrieving revision 1.7
diff -u -r1.7 ping_common.c
--- ping/ping_common.c 29 Jun 2007 16:29:30 -0000 1.7
+++ ping/ping_common.c 20 Aug 2008 04:49:40 -0000
@@ -137,3 +137,34 @@
return x1;
}
+
+int
+_ping_setbuf (PING * p)
+{
+ if (!p->ping_buffer)
+ {
+ p->ping_buffer = malloc (_PING_BUFLEN (p));
+ if (!p->ping_buffer)
+ return -1;
+ }
+ if (!p->ping_cktab)
+ {
+ p->ping_cktab = malloc (p->ping_cktab_size);
+ if (!p->ping_cktab)
+ return -1;
+ memset (p->ping_cktab, 0, p->ping_cktab_size);
+ }
+ return 0;
+}
+
+int
+ping_set_data (PING * p, void *data, size_t off, size_t len)
+{
+ if (_ping_setbuf (p))
+ return -1;
+ if (p->ping_datalen < off + len)
+ return -1;
+ memcpy (p->ping_buffer + sizeof (p->ping_datalen) + off, data, len);
+
+ return 0;
+}
Index: ping/ping_common.h
===================================================================
RCS file: /sources/inetutils/inetutils/ping/ping_common.h,v
retrieving revision 1.8
diff -u -r1.8 ping_common.h
--- ping/ping_common.h 29 Jun 2007 16:29:30 -0000 1.8
+++ ping/ping_common.h 20 Aug 2008 04:49:40 -0000
@@ -17,8 +17,64 @@
to the Free Software Foundation, Inc., 51 Franklin Street,
Fifth Floor, Boston, MA 02110-1301 USA. */
+#include <netinet/in_systm.h>
+#include <netinet/in.h>
+#include <netinet/ip.h>
+#include <netinet/icmp6.h>
+#include <icmp.h>
+
#define DEFAULT_PING_COUNT 4
+/* Not sure about this step*/
+#define _PING_BUFLEN(p) ((p)->ping_datalen + sizeof (icmphdr_t))
+
+typedef int (*ping_efp6) (int code, void *closure, struct sockaddr_in6 * dest,
+ struct sockaddr_in6 * from, struct icmp6_hdr * icmp,
+ int datalen);
+
+typedef int (*ping_efp) (int code,
+ void *closure,
+ struct sockaddr_in * dest,
+ struct sockaddr_in * from,
+ struct ip * ip, icmphdr_t * icmp, int datalen);
+
+union event {
+ ping_efp6 handler6;
+ ping_efp handler;
+};
+
+union ping_address {
+ struct sockaddr_in address;
+ struct sockaddr_in6 address6;
+};
+
+typedef struct ping_data PING;
+
+struct ping_data
+{
+ int ping_fd; /* Raw socket descriptor */
+ int ping_type; /* Type of packets to send */
+ size_t ping_count; /* Number of packets to send */
+ size_t ping_interval; /* Number of seconds to wait between
sending pkts */
+ union ping_address ping_dest; /* whom to ping */
+ char *ping_hostname; /* Printable hostname */
+ size_t ping_datalen; /* Length of data */
+ int ping_ident; /* Our identifier */
+
+ union event ping_event; /* User-defined handler */
+ void *ping_closure; /* User-defined data */
+
+ /* Runtime info */
+ int ping_cktab_size;
+ char *ping_cktab;
+
+ u_char *ping_buffer; /* I/O buffer */
+ union ping_address ping_from;
+ long ping_num_xmit; /* Number of packets transmitted */
+ long ping_num_recv; /* Number of packets received */
+ long ping_num_rept; /* Number of duplicates received */
+};
+
void tvsub (struct timeval *out, struct timeval *in);
double nabs (double a);
double nsqrt (double a, double prec);
@@ -29,3 +85,6 @@
void decode_pattern (const char *text, int *pattern_len,
unsigned char *pattern_data);
+
+int _ping_setbuf (PING * p);
+int ping_set_data (PING *p, void *data, size_t off, size_t len);
Index: ping/ping_echo.c
===================================================================
RCS file: /sources/inetutils/inetutils/ping/ping_echo.c,v
retrieving revision 1.18
diff -u -r1.18 ping_echo.c
--- ping/ping_echo.c 6 Jun 2008 16:43:43 -0000 1.18
+++ ping/ping_echo.c 20 Aug 2008 04:49:40 -0000
@@ -27,9 +27,6 @@
#include <sys/time.h>
#include <signal.h>
-#include <netinet/in_systm.h>
-#include <netinet/in.h>
-#include <netinet/ip.h>
/*#include <netinet/ip_icmp.h> -- deliberately not including this */
#ifdef HAVE_NETINET_IP_VAR_H
# include <netinet/ip_var.h>
@@ -45,9 +42,7 @@
#include <errno.h>
#include <limits.h>
-#include <icmp.h>
#include <ping.h>
-#include "ping_common.h"
#include "ping_impl.h"
#define NROUTES 9 /* number of record route slots */
@@ -109,7 +104,7 @@
printf ("PING %s (%s): %d data bytes\n",
ping->ping_hostname,
- inet_ntoa (ping->ping_dest.sin_addr), data_length);
+ inet_ntoa (ping->ping_dest.address.sin_addr), data_length);
status = ping_run (ping, echo_finish);
free (ping->ping_hostname);
@@ -375,7 +370,7 @@
orig_ip = &icmp->icmp_ip;
if (!(options & OPT_VERBOSE
- || orig_ip->ip_dst.s_addr == ping->ping_dest.sin_addr.s_addr))
+ || orig_ip->ip_dst.s_addr == ping->ping_dest.address.sin_addr.s_addr))
return;
printf ("%d bytes from %s: ", len - hlen, s = ipaddr2str (from->sin_addr));
Index: ping/ping_router.c
===================================================================
RCS file: /sources/inetutils/inetutils/ping/ping_router.c,v
retrieving revision 1.9
diff -u -r1.9 ping_router.c
--- ping/ping_router.c 6 Jun 2008 16:43:43 -0000 1.9
+++ ping/ping_router.c 20 Aug 2008 04:49:40 -0000
@@ -27,9 +27,6 @@
#include <sys/time.h>
#include <signal.h>
-#include <netinet/in_systm.h>
-#include <netinet/in.h>
-#include <netinet/ip.h>
/*#include <netinet/ip_icmp.h> -- deliberately not including this */
#ifdef HAVE_NETINET_IP_VAR_H
# include <netinet/ip_var.h>
@@ -44,7 +41,6 @@
#include <ctype.h>
#include <errno.h>
-#include <icmp.h>
#include <ping.h>
#include <ping_impl.h>
Index: ping/ping_timestamp.c
===================================================================
RCS file: /sources/inetutils/inetutils/ping/ping_timestamp.c,v
retrieving revision 1.11
diff -u -r1.11 ping_timestamp.c
--- ping/ping_timestamp.c 6 Jun 2008 16:43:43 -0000 1.11
+++ ping/ping_timestamp.c 20 Aug 2008 04:49:40 -0000
@@ -27,9 +27,6 @@
#include <sys/time.h>
#include <signal.h>
-#include <netinet/in_systm.h>
-#include <netinet/in.h>
-#include <netinet/ip.h>
/*#include <netinet/ip_icmp.h> -- deliberately not including this */
#ifdef HAVE_NETINET_IP_VAR_H
# include <netinet/ip_var.h>
@@ -44,12 +41,9 @@
#include <ctype.h>
#include <errno.h>
-#include <icmp.h>
#include <ping.h>
#include <ping_impl.h>
-#include "ping_common.h"
-
static int recv_timestamp (int code, void *closure,
struct sockaddr_in *dest, struct sockaddr_in *from,
struct ip *ip, icmphdr_t * icmp, int datalen);
@@ -70,7 +64,7 @@
error (EXIT_FAILURE, 0, "unknown host");
printf ("PING %s (%s): sending timestamp requests\n",
- ping->ping_hostname, inet_ntoa (ping->ping_dest.sin_addr));
+ ping->ping_hostname, inet_ntoa (ping->ping_dest.address.sin_addr));
return ping_run (ping, timestamp_finish);
}