Merge branch 'pull/liboping-0.3' into liboping-0.3
authorFlorian Forster <octo@verplant.org>
Sat, 26 Jan 2008 12:59:07 +0000 (13:59 +0100)
committerFlorian Forster <octo@verplant.org>
Sat, 26 Jan 2008 12:59:07 +0000 (13:59 +0100)
1  2 
src/liboping.c

diff --combined src/liboping.c
@@@ -288,6 -288,22 +288,22 @@@ static pinghost_t *ping_receive_ipv4 (p
        return (ptr);
  }
  
+ #ifndef ICMP6_ECHO_REQUEST
+ # ifdef ICMP6_ECHO /* AIX netinet/ip6_icmp.h */
+ #  define ICMP6_ECHO_REQUEST ICMP6_ECHO
+ # else
+ #  define ICMP6_ECHO_REQUEST 128
+ # endif
+ #endif
+ #ifndef ICMP6_ECHO_REPLY
+ # ifdef ICMP6_ECHOREPLY /* AIX netinet/ip6_icmp.h */
+ #  define ICMP6_ECHO_REPLY ICMP6_ECHOREPLY
+ # else
+ #  define ICMP6_ECHO_REPLY 129
+ # endif
+ #endif
  static pinghost_t *ping_receive_ipv6 (pinghost_t *ph, char *buffer, size_t buffer_len)
  {
        struct icmp6_hdr *icmp_hdr;
@@@ -778,6 -794,7 +794,7 @@@ static pinghost_t *ping_alloc (void
        ph->addr    = (struct sockaddr_storage *) (ph->timer + 1);
  
        ph->addrlen = sizeof (struct sockaddr_storage);
+       ph->fd      = -1;
        ph->latency = -1.0;
        ph->ident   = ping_get_ident () & 0xFFFF;
  
  
  static void ping_free (pinghost_t *ph)
  {
+       if (ph->fd >= 0)
+               close (ph->fd);
+       
        if (ph->hostname != NULL)
                free (ph->hostname);
  
@@@ -1152,8 -1172,7 +1172,7 @@@ int ping_host_add (pingobj_t *obj, cons
  
        if (ph->fd < 0)
        {
-               free (ph->hostname);
-               free (ph);
+               ping_free (ph);
                return (-1);
        }
  
@@@ -1210,9 -1229,6 +1229,6 @@@ int ping_host_remove (pingobj_t *obj, c
        else
                pre->next = cur->next;
        
-       if (cur->fd >= 0)
-               close (cur->fd);
        ping_free (cur);
  
        return (0);
@@@ -1239,7 -1255,7 +1255,7 @@@ int ping_iterator_get_info (pingobj_ite
        {
                case PING_INFO_HOSTNAME:
                        ret = ENOMEM;
 -                      *buffer_len = strlen (iter->hostname);
 +                      *buffer_len = strlen (iter->hostname) + 1;
                        if (orig_buffer_len <= *buffer_len)
                                break;
                        /* Since (orig_buffer_len > *buffer_len) `strncpy'