Implemented the possibility to set the buffer being sent. This allows larger/smaller...
authorocto <octo>
Sun, 14 May 2006 21:11:09 +0000 (21:11 +0000)
committerocto <octo>
Sun, 14 May 2006 21:11:09 +0000 (21:11 +0000)
src/liboping.c
src/mans/ping_setopt.pod
src/oping.h

index de1ff02..3c63521 100644 (file)
@@ -95,8 +95,6 @@
 
 #define PING_ERRMSG_LEN 256
 
-#define PING_DATA "Florian Forster <octo@verplant.org> 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) */
index 7f64b04..9c73929 100644 (file)
@@ -40,6 +40,13 @@ integer and must be either B<AF_UNSPEC>, B<AF_INET>, or B<AF_INET6>. This
 option only effects hosts that are being added B<after> this option has been
 set. Default is B<PING_DEF_AF>.
 
+=item B<PING_OPT_DATA>
+
+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<ping(1)> command.
+
 =back
 
 The I<val> argument is a pointer to the new value. It must not be NULL. It is
index 5214947..7463672 100644 (file)
@@ -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 <octo@verplant.org> http://verplant.org/"
 
 /*
  * Method definitions