From: Florian Forster Date: Sat, 26 Jan 2008 09:36:20 +0000 (+0100) Subject: Merge branch 'origin' X-Git-Tag: Net-Oping-1.00~4 X-Git-Url: https://git.octo.it/?a=commitdiff_plain;h=fe4f50e98128beffb0e04844b383f804ca3ca13b;hp=-c;p=liboping.git Merge branch 'origin' --- fe4f50e98128beffb0e04844b383f804ca3ca13b diff --combined src/liboping.c index fb7be3c,c521a7d..9d14826 --- a/src/liboping.c +++ b/src/liboping.c @@@ -1,6 -1,6 +1,6 @@@ /** * Object oriented C module to send ICMP and ICMPv6 `echo's. - * Copyright (C) 2006 Florian octo Forster + * Copyright (C) 2006-2008 Florian octo Forster * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@@ -97,9 -97,6 +97,9 @@@ struct pinghost { + /* username: name passed in by the user */ + char *username; + /* hostname: name returned by the reverse lookup */ char *hostname; struct sockaddr_storage *addr; socklen_t addrlen; @@@ -291,6 -288,22 +291,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; @@@ -793,9 -806,6 +809,9 @@@ static void ping_free (pinghost_t *ph if (ph->fd >= 0) close (ph->fd); + if (ph->username != NULL) + free (ph->username); + if (ph->hostname != NULL) free (ph->hostname); @@@ -986,7 -996,7 +1002,7 @@@ static pinghost_t *ping_host_search (pi { while (ph != NULL) { - if (strcasecmp (ph->hostname, host) == 0) + if (strcasecmp (ph->username, host) == 0) break; ph = ph->next; @@@ -1028,14 -1038,6 +1044,14 @@@ int ping_host_add (pingobj_t *obj, cons return (-1); } + if ((ph->username = strdup (host)) == NULL) + { + dprintf ("Out of memory!\n"); + ping_set_error (obj, "strdup", strerror (errno)); + ping_free (ph); + return (-1); + } + if ((ph->hostname = strdup (host)) == NULL) { dprintf ("Out of memory!\n"); @@@ -1209,7 -1211,7 +1225,7 @@@ int ping_host_remove (pingobj_t *obj, c while (cur != NULL) { - if (strcasecmp (host, cur->hostname) == 0) + if (strcasecmp (host, cur->username) == 0) break; pre = cur; @@@ -1251,18 -1253,6 +1267,18 @@@ int ping_iterator_get_info (pingobj_ite switch (info) { + case PING_INFO_USERNAME: + ret = ENOMEM; + *buffer_len = strlen (iter->username); + if (orig_buffer_len <= *buffer_len) + break; + /* Since (orig_buffer_len > *buffer_len) `strncpy' + * will copy `*buffer_len' and pad the rest of + * `buffer' with null-bytes */ + strncpy (buffer, iter->username, orig_buffer_len); + ret = 0; + break; + case PING_INFO_HOSTNAME: ret = ENOMEM; *buffer_len = strlen (iter->hostname); @@@ -1291,6 -1281,7 +1307,6 @@@ ) ret = ENOMEM; else if (ret == EAI_SYSTEM) - /* XXX: Not thread-safe! */ ret = errno; else ret = EINVAL;