From: octo Date: Sun, 14 May 2006 21:11:09 +0000 (+0000) Subject: Implemented the possibility to set the buffer being sent. This allows larger/smaller... X-Git-Tag: liboping-0.2.0~7 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=73ce2c0dc06450065945761f79cd4046b2aaa633;p=liboping.git Implemented the possibility to set the buffer being sent. This allows larger/smaller packets to be sent. --- diff --git a/src/liboping.c b/src/liboping.c index de1ff02..3c63521 100644 --- a/src/liboping.c +++ b/src/liboping.c @@ -95,8 +95,6 @@ #define PING_ERRMSG_LEN 256 -#define PING_DATA "Florian Forster http://verplant.org/" - struct pinghost { char *hostname; @@ -119,6 +117,7 @@ struct pingobj double timeout; int ttl; int addrfamily; + char *data; char errmsg[PING_ERRMSG_LEN]; @@ -565,7 +564,11 @@ static int ping_send_one_ipv4 (pingobj_t *obj, pinghost_t *ph) icmp4->icmp_id = htons (ph->ident); icmp4->icmp_seq = htons (ph->sequence); - strcpy (data, PING_DATA); + buflen = 4096 - sizeof (struct icmp); + if (obj->data != NULL) + strncpy (data, obj->data, buflen); + else + strncpy (data, PING_DEF_DATA, buflen); datalen = strlen (data); buflen = datalen + sizeof (struct icmp); @@ -610,7 +613,11 @@ static int ping_send_one_ipv6 (pingobj_t *obj, pinghost_t *ph) icmp6->icmp6_id = htons (ph->ident); icmp6->icmp6_seq = htons (ph->sequence); - strcpy (data, PING_DATA); + buflen = 4096 - sizeof (struct icmp6_hdr); + if (obj->data != NULL) + strncpy (data, obj->data, buflen); + else + strncpy (data, PING_DEF_DATA, buflen); datalen = strlen (data); buflen = datalen + sizeof (struct icmp6_hdr); @@ -854,6 +861,15 @@ int ping_setopt (pingobj_t *obj, int option, void *value) } break; + case PING_OPT_DATA: + if (obj->data != NULL) + { + free (obj->data); + obj->data = NULL; + } + obj->data = strdup ((const char *) value); + break; + default: ret = -2; } /* switch (option) */ diff --git a/src/mans/ping_setopt.pod b/src/mans/ping_setopt.pod index 7f64b04..9c73929 100644 --- a/src/mans/ping_setopt.pod +++ b/src/mans/ping_setopt.pod @@ -40,6 +40,13 @@ integer and must be either B, B, or B. This option only effects hosts that are being added B this option has been set. Default is B. +=item B + +Set the data to send. The value passed must be a char-pointer to a +null-terminated string. By default a 56 byte long string is used so that the +packet size of an ICMPv4 packet is exactly 64 bytes. That's the behavior of the +L command. + =back The I argument is a pointer to the new value. It must not be NULL. It is diff --git a/src/oping.h b/src/oping.h index 5214947..7463672 100644 --- a/src/oping.h +++ b/src/oping.h @@ -48,10 +48,12 @@ typedef struct pingobj pingobj_t; #define PING_OPT_TIMEOUT 0x01 #define PING_OPT_TTL 0x02 #define PING_OPT_AF 0x04 +#define PING_OPT_DATA 0x08 #define PING_DEF_TIMEOUT 1.0 #define PING_DEF_TTL 255 #define PING_DEF_AF AF_UNSPEC +#define PING_DEF_DATA "Florian Forster http://verplant.org/" /* * Method definitions