2 * Object oriented C module to send ICMP and ICMPv6 `echo's.
3 * Copyright (C) 2006 Florian octo Forster <octo at verplant.org>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
31 # error "You don't have the standard C99 header files installed"
32 #endif /* STDC_HEADERS */
42 # include <sys/types.h>
45 # include <sys/stat.h>
48 #if TIME_WITH_SYS_TIME
49 # include <sys/time.h>
53 # include <sys/time.h>
60 # include <sys/socket.h>
66 #if HAVE_NETINET_IN_SYSTM_H
67 # include <netinet/in_systm.h>
70 # include <netinet/in.h>
73 # include <netinet/ip.h>
75 #if HAVE_NETINET_IP_ICMP_H
76 # include <netinet/ip_icmp.h>
78 #ifdef HAVE_NETINET_IP_VAR_H
79 # include <netinet/ip_var.h>
81 #if HAVE_NETINET_IP6_H
82 # include <netinet/ip6.h>
84 #if HAVE_NETINET_ICMP6_H
85 # include <netinet/icmp6.h>
91 # define dprintf(...) printf ("%s[%4i]: %-20s: ", __FILE__, __LINE__, __FUNCTION__); printf (__VA_ARGS__)
93 # define dprintf(...) /**/
96 #define PING_ERRMSG_LEN 256
101 struct sockaddr_storage *addr;
107 struct timeval *timer;
113 struct pinghost *next;
123 char errmsg[PING_ERRMSG_LEN];
129 * private (static) functions
131 static void ping_set_error (pingobj_t *obj, const char *function,
134 snprintf (obj->errmsg, PING_ERRMSG_LEN, "%s: %s", function, message);
135 obj->errmsg[PING_ERRMSG_LEN - 1] = '\0';
138 static int ping_timeval_add (struct timeval *tv1, struct timeval *tv2,
141 res->tv_sec = tv1->tv_sec + tv2->tv_sec;
142 res->tv_usec = tv1->tv_usec + tv2->tv_usec;
144 while (res->tv_usec > 1000000)
146 res->tv_usec -= 1000000;
153 static int ping_timeval_sub (struct timeval *tv1, struct timeval *tv2,
157 if ((tv1->tv_sec < tv2->tv_sec)
158 || ((tv1->tv_sec == tv2->tv_sec)
159 && (tv1->tv_usec < tv2->tv_usec)))
162 res->tv_sec = tv1->tv_sec - tv2->tv_sec;
163 res->tv_usec = tv1->tv_usec - tv2->tv_usec;
165 assert ((res->tv_sec > 0) || ((res->tv_sec == 0) && (res->tv_usec > 0)));
167 while (res->tv_usec < 0)
169 res->tv_usec += 1000000;
176 static uint16_t ping_icmp4_checksum (char *buf, size_t len)
183 for (ptr = (uint16_t *) buf; len > 1; ptr++, len -= 2)
188 *(char *) &ret = *(char *) ptr;
192 /* Do this twice to get all possible carries.. */
193 sum = (sum >> 16) + (sum & 0xFFFF);
194 sum = (sum >> 16) + (sum & 0xFFFF);
201 static pinghost_t *ping_receive_ipv4 (pinghost_t *ph, char *buffer, size_t buffer_len)
204 struct icmp *icmp_hdr;
208 uint16_t recv_checksum;
209 uint16_t calc_checksum;
216 if (buffer_len < sizeof (struct ip))
219 ip_hdr = (struct ip *) buffer;
220 ip_hdr_len = ip_hdr->ip_hl << 2;
222 if (buffer_len < ip_hdr_len)
225 buffer += ip_hdr_len;
226 buffer_len -= ip_hdr_len;
228 if (buffer_len < sizeof (struct icmp))
231 icmp_hdr = (struct icmp *) buffer;
232 buffer += sizeof (struct icmp);
233 buffer_len -= sizeof (struct icmp);
235 if (icmp_hdr->icmp_type != ICMP_ECHOREPLY)
237 dprintf ("Unexpected ICMP type: %i\n", icmp_hdr->icmp_type);
241 recv_checksum = icmp_hdr->icmp_cksum;
242 icmp_hdr->icmp_cksum = 0;
243 calc_checksum = ping_icmp4_checksum ((char *) icmp_hdr,
244 sizeof (struct icmp) + buffer_len);
246 if (recv_checksum != calc_checksum)
248 dprintf ("Checksum missmatch: Got 0x%04x, calculated 0x%04x\n",
249 recv_checksum, calc_checksum);
253 ident = ntohs (icmp_hdr->icmp_id);
254 seq = ntohs (icmp_hdr->icmp_seq);
256 for (ptr = ph; ptr != NULL; ptr = ptr->next)
258 dprintf ("hostname = %s, ident = 0x%04x, seq = %i\n",
259 ptr->hostname, ptr->ident, ((ptr->sequence - 1) & 0xFFFF));
261 if (ptr->addrfamily != AF_INET)
264 if (!timerisset (ptr->timer))
267 if (ptr->ident != ident)
270 if (((ptr->sequence - 1) & 0xFFFF) != seq)
273 dprintf ("Match found: hostname = %s, ident = 0x%04x, seq = %i\n",
274 ptr->hostname, ident, seq);
281 dprintf ("No match found for ident = 0x%04x, seq = %i\n",
288 static pinghost_t *ping_receive_ipv6 (pinghost_t *ph, char *buffer, size_t buffer_len)
290 struct icmp6_hdr *icmp_hdr;
297 if (buffer_len < sizeof (struct icmp6_hdr))
300 icmp_hdr = (struct icmp6_hdr *) buffer;
301 buffer += sizeof (struct icmp);
302 buffer_len -= sizeof (struct icmp);
304 if (icmp_hdr->icmp6_type != ICMP6_ECHO_REPLY)
306 dprintf ("Unexpected ICMP type: %02x\n", icmp_hdr->icmp6_type);
310 if (icmp_hdr->icmp6_code != 0)
312 dprintf ("Unexpected ICMP code: %02x\n", icmp_hdr->icmp6_code);
316 ident = ntohs (icmp_hdr->icmp6_id);
317 seq = ntohs (icmp_hdr->icmp6_seq);
319 for (ptr = ph; ptr != NULL; ptr = ptr->next)
321 dprintf ("hostname = %s, ident = 0x%04x, seq = %i\n",
322 ptr->hostname, ptr->ident, ((ptr->sequence - 1) & 0xFFFF));
324 if (ptr->addrfamily != AF_INET6)
327 if (!timerisset (ptr->timer))
330 if (ptr->ident != ident)
333 if (((ptr->sequence - 1) & 0xFFFF) != seq)
336 dprintf ("Match found: hostname = %s, ident = 0x%04x, seq = %i\n",
337 ptr->hostname, ident, seq);
344 dprintf ("No match found for ident = 0x%04x, seq = %i\n",
351 static int ping_receive_one (int fd, pinghost_t *ph, struct timeval *now)
358 pinghost_t *host = NULL;
360 struct sockaddr_storage sa;
363 sa_len = sizeof (sa);
365 buffer_len = recvfrom (fd, buffer, sizeof (buffer), 0,
366 (struct sockaddr *) &sa, &sa_len);
367 if (buffer_len == -1)
369 dprintf ("recvfrom: %s\n", strerror (errno));
373 dprintf ("Read %u bytes from fd = %i\n", (unsigned int) buffer_len, fd);
375 if (sa.ss_family == AF_INET)
377 if ((host = ping_receive_ipv4 (ph, buffer, buffer_len)) == NULL)
380 else if (sa.ss_family == AF_INET6)
382 if ((host = ping_receive_ipv6 (ph, buffer, buffer_len)) == NULL)
386 dprintf ("rcvd: %12i.%06i\n",
389 dprintf ("sent: %12i.%06i\n",
390 (int) host->timer->tv_sec,
391 (int) host->timer->tv_usec);
393 if (ping_timeval_sub (now, host->timer, &diff) < 0)
395 timerclear (host->timer);
399 dprintf ("diff: %12i.%06i\n",
403 host->latency = ((double) diff.tv_usec) / 1000.0;
404 host->latency += ((double) diff.tv_sec) * 1000.0;
406 timerclear (host->timer);
411 static int ping_receive_all (pingobj_t *obj)
420 struct timeval endtime;
421 struct timeval nowtime;
422 struct timeval timeout;
430 for (ptr = ph; ptr != NULL; ptr = ptr->next)
433 if (gettimeofday (&nowtime, NULL) == -1)
435 ping_set_error (obj, "gettimeofday", strerror (errno));
440 timeout.tv_sec = (time_t) obj->timeout;
441 timeout.tv_usec = (suseconds_t) (1000000 * (obj->timeout - ((double) timeout.tv_sec)));
443 dprintf ("Set timeout to %i.%06i seconds\n",
444 (int) timeout.tv_sec,
445 (int) timeout.tv_usec);
447 ping_timeval_add (&nowtime, &timeout, &endtime);
455 for (ptr = ph; ptr != NULL; ptr = ptr->next)
457 if (!timerisset (ptr->timer))
460 FD_SET (ptr->fd, &readfds);
463 if (max_readfds < ptr->fd)
464 max_readfds = ptr->fd;
467 if (num_readfds == 0)
470 if (gettimeofday (&nowtime, NULL) == -1)
472 ping_set_error (obj, "gettimeofday", strerror (errno));
476 if (ping_timeval_sub (&endtime, &nowtime, &timeout) == -1)
479 dprintf ("Waiting on %i sockets for %i.%06i seconds\n", num_readfds,
480 (int) timeout.tv_sec,
481 (int) timeout.tv_usec);
483 status = select (max_readfds + 1, &readfds, NULL, NULL, &timeout);
485 if (gettimeofday (&nowtime, NULL) == -1)
487 ping_set_error (obj, "gettimeofday", strerror (errno));
491 if ((status == -1) && (errno == EINTR))
493 dprintf ("select was interrupted by signal..\n");
498 dprintf ("select: %s\n", strerror (errno));
501 else if (status == 0)
503 dprintf ("select timed out\n");
507 for (ptr = ph; ptr != NULL; ptr = ptr->next)
509 if (FD_ISSET (ptr->fd, &readfds))
510 if (ping_receive_one (ptr->fd, ph, &nowtime) == 0)
518 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
519 * Sending functions: *
522 * +-> ping_send_one_ipv4 *
523 * `-> ping_send_one_ipv6 *
524 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
525 static ssize_t ping_sendto (pingobj_t *obj, pinghost_t *ph,
526 const void *buf, size_t buflen)
530 if (gettimeofday (ph->timer, NULL) == -1)
532 timerclear (ph->timer);
536 ret = sendto (ph->fd, buf, buflen, 0,
537 (struct sockaddr *) ph->addr, ph->addrlen);
541 #if defined(EHOSTUNREACH)
542 if (errno == EHOSTUNREACH)
545 #if defined(ENETUNREACH)
546 if (errno == ENETUNREACH)
549 ping_set_error (obj, "sendto", strerror (errno));
555 static int ping_send_one_ipv4 (pingobj_t *obj, pinghost_t *ph)
566 dprintf ("ph->hostname = %s\n", ph->hostname);
568 memset (buf, '\0', sizeof (buf));
569 icmp4 = (struct icmp *) buf;
570 data = (char *) (icmp4 + 1);
572 icmp4->icmp_type = ICMP_ECHO;
573 icmp4->icmp_code = 0;
574 icmp4->icmp_cksum = 0;
575 icmp4->icmp_id = htons (ph->ident);
576 icmp4->icmp_seq = htons (ph->sequence);
578 buflen = 4096 - sizeof (struct icmp);
579 strncpy (data, ph->data, buflen);
580 datalen = strlen (data);
582 buflen = datalen + sizeof (struct icmp);
584 icmp4->icmp_cksum = ping_icmp4_checksum (buf, buflen);
586 dprintf ("Sending ICMPv4 package with ID 0x%04x\n", ph->ident);
588 status = ping_sendto (obj, ph, buf, buflen);
591 perror ("ping_sendto");
595 dprintf ("sendto: status = %i\n", status);
600 static int ping_send_one_ipv6 (pingobj_t *obj, pinghost_t *ph)
602 struct icmp6_hdr *icmp6;
611 dprintf ("ph->hostname = %s\n", ph->hostname);
613 memset (buf, '\0', sizeof (buf));
614 icmp6 = (struct icmp6_hdr *) buf;
615 data = (char *) (icmp6 + 1);
617 icmp6->icmp6_type = ICMP6_ECHO_REQUEST;
618 icmp6->icmp6_code = 0;
619 /* The checksum will be calculated by the TCP/IP stack. */
621 icmp6->icmp6_cksum = 0;
622 icmp6->icmp6_id = htons (ph->ident);
623 icmp6->icmp6_seq = htons (ph->sequence);
625 buflen = 4096 - sizeof (struct icmp6_hdr);
626 strncpy (data, ph->data, buflen);
627 datalen = strlen (data);
629 buflen = datalen + sizeof (struct icmp6_hdr);
631 dprintf ("Sending ICMPv6 package with ID 0x%04x\n", ph->ident);
633 status = ping_sendto (obj, ph, buf, buflen);
636 perror ("ping_sendto");
640 dprintf ("sendto: status = %i\n", status);
645 static int ping_send_all (pingobj_t *obj)
655 for (ptr = ph; ptr != NULL; ptr = ptr->next)
657 /* start timer.. The GNU `ping6' starts the timer before
658 * sending the packet, so I will do that too */
659 if (gettimeofday (ptr->timer, NULL) == -1)
661 dprintf ("gettimeofday: %s\n", strerror (errno));
662 timerclear (ptr->timer);
668 dprintf ("timer set for hostname = %s\n", ptr->hostname);
671 if (ptr->addrfamily == AF_INET6)
673 dprintf ("Sending ICMPv6 echo request to `%s'\n", ptr->hostname);
674 if (ping_send_one_ipv6 (obj, ptr) != 0)
676 timerclear (ptr->timer);
681 else if (ptr->addrfamily == AF_INET)
683 dprintf ("Sending ICMPv4 echo request to `%s'\n", ptr->hostname);
684 if (ping_send_one_ipv4 (obj, ptr) != 0)
686 timerclear (ptr->timer);
691 else /* this should not happen */
693 dprintf ("Unknown address family: %i\n", ptr->addrfamily);
694 timerclear (ptr->timer);
706 * Set the TTL of a socket protocol independently.
708 static int ping_set_ttl (pinghost_t *ph, int ttl)
712 if (ph->addrfamily == AF_INET)
714 ret = setsockopt (ph->fd, IPPROTO_IP, IP_TTL, &ttl, sizeof (ttl));
716 else if (ph->addrfamily == AF_INET6)
718 ret = setsockopt (ph->fd, IPPROTO_IPV6, IPV6_UNICAST_HOPS, &ttl, sizeof (ttl));
724 static int ping_get_ident (void)
727 static int did_seed = 0;
733 if ((fd = open ("/dev/urandom", O_RDONLY)) != -1)
737 if (read (fd, &seed, sizeof (seed)) != -1)
740 dprintf ("Random seed: %i\n", seed);
748 dprintf ("open (/dev/urandom): %s\n", strerror (errno));
752 retval = (int) random ();
754 dprintf ("Random number: %i\n", retval);
759 static pinghost_t *ping_alloc (void)
764 ph_size = sizeof (pinghost_t)
765 + sizeof (struct sockaddr_storage)
766 + sizeof (struct timeval);
768 ph = (pinghost_t *) malloc (ph_size);
772 memset (ph, '\0', ph_size);
774 ph->timer = (struct timeval *) (ph + 1);
775 ph->addr = (struct sockaddr_storage *) (ph->timer + 1);
777 ph->addrlen = sizeof (struct sockaddr_storage);
779 ph->ident = ping_get_ident () & 0xFFFF;
784 static void ping_free (pinghost_t *ph)
786 if (ph->hostname != NULL)
789 if (ph->data != NULL)
798 const char *ping_get_error (pingobj_t *obj)
800 return (obj->errmsg);
803 pingobj_t *ping_construct (void)
807 if ((obj = (pingobj_t *) malloc (sizeof (pingobj_t))) == NULL)
809 memset (obj, '\0', sizeof (pingobj_t));
811 obj->timeout = PING_DEF_TIMEOUT;
812 obj->ttl = PING_DEF_TTL;
813 obj->addrfamily = PING_DEF_AF;
814 obj->data = strdup (PING_DEF_DATA);
819 void ping_destroy (pingobj_t *obj)
827 while (current != NULL)
829 next = current->next;
834 if (obj->data != NULL)
842 int ping_setopt (pingobj_t *obj, int option, void *value)
848 case PING_OPT_TIMEOUT:
849 obj->timeout = *((double *) value);
850 if (obj->timeout < 0.0)
852 obj->timeout = PING_DEF_TIMEOUT;
858 obj->ttl = *((int *) value);
859 if ((obj->ttl < 1) || (obj->ttl > 255))
861 obj->ttl = PING_DEF_TTL;
867 obj->addrfamily = *((int *) value);
868 if ((obj->addrfamily != AF_UNSPEC)
869 && (obj->addrfamily != AF_INET)
870 && (obj->addrfamily != AF_INET6))
872 obj->addrfamily = PING_DEF_AF;
878 if (obj->data != NULL)
883 obj->data = strdup ((const char *) value);
888 } /* switch (option) */
891 } /* int ping_setopt */
894 int ping_send (pingobj_t *obj)
898 if (ping_send_all (obj) < 0)
901 if ((ret = ping_receive_all (obj)) < 0)
907 static pinghost_t *ping_host_search (pinghost_t *ph, const char *host)
911 if (strcasecmp (ph->hostname, host) == 0)
920 int ping_host_add (pingobj_t *obj, const char *host)
924 struct sockaddr_storage sockaddr;
925 socklen_t sockaddr_len;
927 struct addrinfo ai_hints;
928 struct addrinfo *ai_list, *ai_ptr;
931 dprintf ("host = %s\n", host);
933 if (ping_host_search (obj->head, host) != NULL)
936 memset (&ai_hints, '\0', sizeof (ai_hints));
937 ai_hints.ai_flags = 0;
939 ai_hints.ai_flags |= AI_ADDRCONFIG;
941 ai_hints.ai_family = obj->addrfamily;
942 ai_hints.ai_socktype = SOCK_RAW;
944 if ((ph = ping_alloc ()) == NULL)
946 dprintf ("Out of memory!\n");
950 if ((ph->hostname = strdup (host)) == NULL)
952 dprintf ("Out of memory!\n");
953 ping_set_error (obj, "strdup", strerror (errno));
958 /* obj->data is not garuanteed to be != NULL */
959 if ((ph->data = strdup (obj->data == NULL ? PING_DEF_DATA : obj->data)) == NULL)
961 dprintf ("Out of memory!\n");
962 ping_set_error (obj, "strdup", strerror (errno));
967 if ((ai_return = getaddrinfo (host, NULL, &ai_hints, &ai_list)) != 0)
969 dprintf ("getaddrinfo failed\n");
970 ping_set_error (obj, "getaddrinfo",
971 (ai_return == EAI_SYSTEM)
973 : gai_strerror (ai_return));
979 ping_set_error (obj, "getaddrinfo", "No hosts returned");
981 for (ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next)
985 sockaddr_len = sizeof (sockaddr);
986 memset (&sockaddr, '\0', sockaddr_len);
988 if (ai_ptr->ai_family == AF_INET)
990 struct sockaddr_in *si;
992 si = (struct sockaddr_in *) &sockaddr;
993 si->sin_family = AF_INET;
994 si->sin_port = htons (ph->ident);
995 si->sin_addr.s_addr = htonl (INADDR_ANY);
997 ai_ptr->ai_socktype = SOCK_RAW;
998 ai_ptr->ai_protocol = IPPROTO_ICMP;
1000 else if (ai_ptr->ai_family == AF_INET6)
1002 struct sockaddr_in6 *si;
1004 si = (struct sockaddr_in6 *) &sockaddr;
1005 si->sin6_family = AF_INET6;
1006 si->sin6_port = htons (ph->ident);
1007 si->sin6_addr = in6addr_any;
1009 ai_ptr->ai_socktype = SOCK_RAW;
1010 ai_ptr->ai_protocol = IPPROTO_ICMPV6;
1014 char errmsg[PING_ERRMSG_LEN];
1016 snprintf (errmsg, PING_ERRMSG_LEN, "Unknown `ai_family': %i", ai_ptr->ai_family);
1017 errmsg[PING_ERRMSG_LEN - 1] = '\0';
1020 ping_set_error (obj, "getaddrinfo", errmsg);
1024 /* TODO: Move this to a static function `ping_open_socket' and
1025 * call it whenever the socket dies. */
1026 ph->fd = socket (ai_ptr->ai_family, ai_ptr->ai_socktype, ai_ptr->ai_protocol);
1029 dprintf ("socket: %s\n", strerror (errno));
1030 ping_set_error (obj, "socket", strerror (errno));
1035 * The majority vote of operating systems has decided that you don't need to
1036 * bind here. This code should be reactivated to bind to a specific address,
1037 * though. See the `-I' option of `ping(1)' (GNU). -octo
1040 if (bind (ph->fd, (struct sockaddr *) &sockaddr, sockaddr_len) == -1)
1042 dprintf ("bind: %s\n", strerror (errno));
1043 ping_set_error (obj, "bind", strerror (errno));
1050 assert (sizeof (struct sockaddr_storage) >= ai_ptr->ai_addrlen);
1051 memset (ph->addr, '\0', sizeof (struct sockaddr_storage));
1052 memcpy (ph->addr, ai_ptr->ai_addr, ai_ptr->ai_addrlen);
1053 ph->addrlen = ai_ptr->ai_addrlen;
1054 ph->addrfamily = ai_ptr->ai_family;
1059 freeaddrinfo (ai_list);
1063 free (ph->hostname);
1069 * Adding in the front is much easier, but then the iterator will
1070 * return the host that was added last as first host. That's just not
1073 if (obj->head == NULL)
1082 while (hptr->next != NULL)
1085 assert ((hptr != NULL) && (hptr->next == NULL));
1089 ping_set_ttl (ph, obj->ttl);
1094 int ping_host_remove (pingobj_t *obj, const char *host)
1096 pinghost_t *pre, *cur;
1103 if (strcasecmp (host, cur->hostname))
1112 ping_set_error (obj, "ping_host_remove", "Host not found");
1117 obj->head = cur->next;
1119 pre->next = cur->next;
1129 pingobj_iter_t *ping_iterator_get (pingobj_t *obj)
1131 return ((pingobj_iter_t *) obj->head);
1134 pingobj_iter_t *ping_iterator_next (pingobj_iter_t *iter)
1136 return ((pingobj_iter_t *) iter->next);
1139 int ping_iterator_get_info (pingobj_iter_t *iter, int info,
1140 void *buffer, size_t *buffer_len)
1144 size_t orig_buffer_len = *buffer_len;
1148 case PING_INFO_HOSTNAME:
1150 *buffer_len = strlen (iter->hostname);
1151 if (orig_buffer_len <= *buffer_len)
1153 /* Since (orig_buffer_len > *buffer_len) `strncpy'
1154 * will copy `*buffer_len' and pad the rest of
1155 * `buffer' with null-bytes */
1156 strncpy (buffer, iter->hostname, orig_buffer_len);
1160 case PING_INFO_ADDRESS:
1161 ret = getnameinfo ((struct sockaddr *) iter->addr,
1169 if ((ret == EAI_MEMORY)
1171 || (ret == EAI_OVERFLOW)
1175 else if (ret == EAI_SYSTEM)
1176 /* XXX: Not thread-safe! */
1183 case PING_INFO_FAMILY:
1185 *buffer_len = sizeof (int);
1186 if (orig_buffer_len < sizeof (int))
1188 *((int *) buffer) = iter->addrfamily;
1192 case PING_INFO_LATENCY:
1194 *buffer_len = sizeof (double);
1195 if (orig_buffer_len < sizeof (double))
1197 *((double *) buffer) = iter->latency;
1201 case PING_INFO_SEQUENCE:
1203 *buffer_len = sizeof (unsigned int);
1204 if (orig_buffer_len < sizeof (unsigned int))
1206 *((unsigned int *) buffer) = (unsigned int) iter->sequence;
1210 case PING_INFO_IDENT:
1212 *buffer_len = sizeof (uint16_t);
1213 if (orig_buffer_len < sizeof (uint16_t))
1215 *((uint16_t *) buffer) = (uint16_t) iter->ident;
1219 case PING_INFO_DATA:
1221 *buffer_len = strlen (iter->data);
1222 if (orig_buffer_len < *buffer_len)
1224 strncpy ((char *) buffer, iter->data, orig_buffer_len);
1232 void *ping_iterator_get_context (pingobj_iter_t *iter)
1234 return (iter->context);
1237 void ping_iterator_set_context (pingobj_iter_t *iter, void *context)
1239 iter->context = context;