[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug-inetutils] moving initial common functions from ping6 and libping t
From: |
Rakesh Pandit |
Subject: |
[bug-inetutils] moving initial common functions from ping6 and libping to ping_common -3 |
Date: |
Wed, 27 Aug 2008 23:23:21 +0530 |
Hello,
I cannot make it smaller then this. It includes some ground work,
+ moving two functions into ping_common.
Subsequent patches could be lot smaller.
--
rakesh
--- inetutils.org/ChangeLog 2008-08-27 21:49:19.000000000 +0530
+++ inetutils/ChangeLog 2008-08-27 22:46:21.000000000 +0530
@@ -1,3 +1,22 @@
+2008-08-28 Rakesh Pandit <address@hidden>
+
+ * ping/ping6.c, ping/libping.c, ping_common.c
+ (_ping_setbuf, ping_set_data): Moved duplicate code for
+ functions _ping_setbuf & ping_set_data to ping_common.c.
+ Added IS_PING6 arguments to both of these functions.
+
+ * ping_comman.h, ping.h, ping6.h: Moved common includes
+ from ping6.c, ping.c, libping.c, etc. Moved ping_data
+ from ping.h & ping6.h to ping_common.h Added union event
+ & union ping_address to struct ping_data.
+
+ * ping.c, ping6.c, libping.c, ping_timestamp.c, ping_echo.c,
ping_router.c:
+ Removed redundant header file includes.
+ (send_echo): Added IS_PING6 argument to ping_set_data.
+ Replaced all ping_dest with ping_address member address6
+ in ping6.c and with ping_address memeber address at all
+ places in ping.c, ping_timestamp.c, ping_echo.c etc.
+
2008-08-27 Rakesh Pandit <address@hidden>
* libicmp/Makefile.am: Removed libping.c and ping.h.
--- inetutils.org/ping/ping.c 2008-08-27 08:01:02.000000000 +0530
+++ inetutils/ping/ping.c 2008-08-27 21:00:21.000000000 +0530
@@ -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"
@@ -412,13 +407,13 @@
{
struct timeval tv;
gettimeofday (&tv, NULL);
- ping_set_data (ping, &tv, 0, sizeof (tv));
+ ping_set_data (ping, &tv, 0, sizeof (tv), IS_PING6);
off += sizeof (tv);
}
if (data_buffer)
ping_set_data (ping, data_buffer, off,
data_length > PING_HEADER_LEN ?
- data_length - PING_HEADER_LEN : data_length);
+ data_length - PING_HEADER_LEN : data_length, IS_PING6);
return ping_xmit (ping);
}
--- inetutils.org/ping/ping6.c 2008-08-27 08:31:12.000000000 +0530
+++ inetutils/ping/ping6.c 2008-08-27 21:08:37.000000000 +0530
@@ -33,7 +33,6 @@
#include <netdb.h>
#include <unistd.h>
#include <stdlib.h>
-#include <stdbool.h>
#include <string.h>
#include <stdio.h>
#include <argp.h>
@@ -42,7 +41,6 @@
#include <limits.h>
#include <xalloc.h>
-#include "ping_common.h"
#include "ping6.h"
#include "libinetutils.h"
@@ -370,13 +368,13 @@
{
struct timeval tv;
gettimeofday (&tv, NULL);
- ping_set_data (ping, &tv, 0, sizeof (tv));
+ ping_set_data (ping, &tv, 0, sizeof (tv), IS_PING6);
off += sizeof (tv);
}
if (data_buffer)
ping_set_data (ping, data_buffer, off,
data_length > PING_HEADER_LEN ?
- data_length - PING_HEADER_LEN : data_length);
+ data_length - PING_HEADER_LEN : data_length, IS_PING6);
return ping_xmit (ping);
}
@@ -431,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)
{
@@ -743,43 +741,12 @@
}
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;
struct icmp6_hdr *icmp6;
- if (_ping_setbuf (p))
+ if (_ping_setbuf (p, IS_PING6))
return -1;
buflen = p->ping_datalen + sizeof (struct icmp6_hdr);
@@ -796,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
@@ -816,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);
@@ -834,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, IS_PING6);
+ 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;
@@ -877,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
@@ -887,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;
@@ -907,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);
--- inetutils.org/ping/ping6.h 2008-08-27 08:01:02.000000000 +0530
+++ inetutils/ping/ping6.h 2008-08-27 21:09:54.000000000 +0530
@@ -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,7 +48,7 @@
#define PING_DATALEN (64 - PING_HEADER_LEN) /* default data length */
#define PING_MAX_DATALEN (65535 - sizeof (struct icmp6_hdr))
-#define _PING_BUFLEN(p) ((p)->ping_datalen + sizeof (struct icmp6_hdr))
+#define IS_PING6 1
#define _C_BIT(p,bit) (p)->ping_cktab[(bit)>>3] /* byte in ck array */
#define _C_MASK(bit) (1 << ((bit) & 0x07))
@@ -91,7 +59,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);
--- inetutils.org/ping/ping_address.c 2008-08-27 08:01:02.000000000 +0530
+++ inetutils/ping/ping_address.c 2008-08-27 21:10:30.000000000 +0530
@@ -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);
}
--- inetutils.org/ping/ping_common.h 2008-08-27 08:01:02.000000000 +0530
+++ inetutils/ping/ping_common.h 2008-08-27 21:10:53.000000000 +0530
@@ -17,8 +17,67 @@
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>
+
+#include <stdbool.h>
+
#define DEFAULT_PING_COUNT 4
+/* Not sure about this step*/
+#define _PING_BUFLEN(p, is_ping6) ((is_ping6)? ((p)->ping_datalen +
sizeof (struct icmp6_hdr)) : \
+ ((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 +88,6 @@
void decode_pattern (const char *text, int *pattern_len,
unsigned char *pattern_data);
+
+int _ping_setbuf (PING * p, bool is_ping6);
+int ping_set_data (PING *p, void *data, size_t off, size_t len, bool is_ping6);
--- inetutils.org/ping/ping_common.c 2008-08-27 08:01:02.000000000 +0530
+++ inetutils/ping/ping_common.c 2008-08-27 21:10:35.000000000 +0530
@@ -137,3 +137,42 @@
return x1;
}
+
+int
+_ping_setbuf (PING * p, bool is_ping6)
+{
+ if (!p->ping_buffer)
+ {
+ p->ping_buffer = malloc (_PING_BUFLEN (p, is_ping6));
+ 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, bool is_ping6)
+{
+ icmphdr_t *icmp;
+
+ if (_ping_setbuf (p, is_ping6))
+ return -1;
+ if (p->ping_datalen < off + len)
+ return -1;
+
+ if(is_ping6) {
+ icmp = (struct icmp6_hdr *) p->ping_buffer;
+ } else {
+ icmp = (icmphdr_t *) p->ping_buffer;
+ }
+ memcpy (icmp->icmp_data + off, data, len);
+
+ return 0;
+}
--- inetutils.org/ping/ping_echo.c 2008-08-27 08:01:02.000000000 +0530
+++ inetutils/ping/ping_echo.c 2008-08-27 21:11:00.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 */
#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));
--- inetutils.org/ping/ping_router.c 2008-08-27 08:01:02.000000000 +0530
+++ inetutils/ping/ping_router.c 2008-08-27 21:11:10.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 */
#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>
--- inetutils.org/ping/ping_timestamp.c 2008-08-27 08:01:02.000000000 +0530
+++ inetutils/ping/ping_timestamp.c 2008-08-27 21:11:25.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 */
#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);
}
--- inetutils.org/ping/libping.c 2008-08-27 08:01:02.000000000 +0530
+++ inetutils/ping/libping.c 2008-08-27 20:57:08.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)
{
@@ -178,7 +140,7 @@
{
int i, buflen;
- if (_ping_setbuf (p))
+ if (_ping_setbuf (p, IS_PING6))
return -1;
buflen = _ping_packetsize (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,15 +201,15 @@
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;
int dupflag;
n = recvfrom (p->ping_fd,
- (char *) p->ping_buffer, _PING_BUFLEN (p), 0,
- (struct sockaddr *) &p->ping_from, &fromlen);
+ (char *) p->ping_buffer, _PING_BUFLEN (p, IS_PING6), 0,
+ (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);
--- inetutils.org/ping/ping.h 2008-08-27 08:01:02.000000000 +0530
+++ inetutils/ping/ping.h 2008-08-27 20:56:48.000000000 +0530
@@ -17,42 +17,12 @@
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
#define PEV_NOECHO 2
+#define IS_PING6 0
#define PING_DEFAULT_INTERVAL 1000 /* Milliseconds */
#define PING_PRECISION 1000 /* Millisecond precision */
@@ -62,8 +32,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 +49,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);
- [bug-inetutils] moving initial common functions from ping6 and libping to ping_common -3,
Rakesh Pandit <=