Author: biurrun Date: Thu Nov 26 17:41:43 2009 New Revision: 1830 Log: Move identical_hits() to the only place it is used and mark as static. Modified: trunk/pairing/common.c trunk/pairing/common.h trunk/pairing/send.c Modified: trunk/pairing/common.c ============================================================================== --- trunk/pairing/common.c Thu Nov 26 17:37:31 2009 (r1829) +++ trunk/pairing/common.c Thu Nov 26 17:41:43 2009 (r1830) @@ -16,7 +16,6 @@ #include <time.h> #include "common.h" -#include "libpisa/global.h" #include "libpisa/cfg.h" #include "libconfig_wrapper.h" #include "common_headers.h" @@ -52,58 +51,6 @@ return !(strspn(nickname, "abcdefghijklmnopqrstuvwxyz0123456789") < strlen(nickname)); } -/** This function receives two HITs (as strings) and checks to see if they are equal. - * It accounts for differences in writing style (e.g. inclusion or exclusion of zeros). - * - * @param hit1 Pointer to the string containing the human-readable representation of the first HIT. - * @param hit2 Pointer to the string containing the human-readable representation of the second HIT. - * - * @return 1 if they are identical; 0 if not identical; -1 on error - */ -int identical_hits(char *hit1, char *hit2) -{ - struct sockaddr_in6 hit1_addr; - struct sockaddr_in6 hit2_addr; - int err; - - // Convert the first HIT to a sockaddr structure - if ((err = inet_pton(PF_INET6, hit1, &(hit1_addr.sin6_addr))) <= 0) - { - if (err == 0) - USER_MSG("Error: Invalid network address given.\n"); - else - perror("invalid address family"); - - return -1; - } - - if (!pisa_ipv6_addr_is_hit(&hit1_addr.sin6_addr)) - { - DEBUG_MED("First \"HIT\" was not actually a HIT."); - return -1; - } - - // Convert the second HIT to a sockaddr structure - if ((err = inet_pton(PF_INET6, hit2, &(hit2_addr.sin6_addr))) <= 0) - { - if (err == 0) - USER_MSG("Error: Invalid network address given.\n"); - else - perror("invalid address family"); - - return -1; - } - - if (!pisa_ipv6_addr_is_hit(&hit2_addr.sin6_addr)) - { - DEBUG_MED("Second \"HIT\" was not actually a HIT."); - return -1; - } - - return !memcmp(hit1_addr.sin6_addr.s6_addr, hit2_addr.sin6_addr.s6_addr, sizeof(hit1_addr.sin6_addr.s6_addr)); -} - - /* Stolen from http://en.wikipedia.org/wiki/Itoa */ /** Convert an integer to a string Modified: trunk/pairing/common.h ============================================================================== --- trunk/pairing/common.h Thu Nov 26 17:37:31 2009 (r1829) +++ trunk/pairing/common.h Thu Nov 26 17:41:43 2009 (r1830) @@ -26,7 +26,6 @@ // Function prototypes int valid_addr(char *addr); int valid_nickname(char *nickname); -int identical_hits(char *hit1, char *hit2); void itoa(int n, char s[]); int get_default_expiration(char *buffer); int get_default_expiration_from_config(char *buffer,const char *filename); Modified: trunk/pairing/send.c ============================================================================== --- trunk/pairing/send.c Thu Nov 26 17:37:31 2009 (r1829) +++ trunk/pairing/send.c Thu Nov 26 17:41:43 2009 (r1830) @@ -19,6 +19,7 @@ #include <sys/socket.h> #include <arpa/inet.h> #include <netinet/in.h> +#include "libpisa/global.h" #include "common_headers.h" #include "common.h" #include "packet_handler.h" @@ -37,6 +38,58 @@ int request_type; }; +/** This function receives two HITs (as strings) and checks to see if they are equal. + * It accounts for differences in writing style (e.g. inclusion or exclusion of zeros). + * + * @param hit1 Pointer to the string containing the human-readable representation of the first HIT. + * @param hit2 Pointer to the string containing the human-readable representation of the second HIT. + * + * @return 1 if they are identical; 0 if not identical; -1 on error + */ +static int identical_hits(char *hit1, char *hit2) +{ + struct sockaddr_in6 hit1_addr; + struct sockaddr_in6 hit2_addr; + int err; + + // Convert the first HIT to a sockaddr structure + if ((err = inet_pton(PF_INET6, hit1, &(hit1_addr.sin6_addr))) <= 0) + { + if (err == 0) + USER_MSG("Error: Invalid network address given.\n"); + else + perror("invalid address family"); + + return -1; + } + + if (!pisa_ipv6_addr_is_hit(&hit1_addr.sin6_addr)) + { + DEBUG_MED("First \"HIT\" was not actually a HIT."); + return -1; + } + + // Convert the second HIT to a sockaddr structure + if ((err = inet_pton(PF_INET6, hit2, &(hit2_addr.sin6_addr))) <= 0) + { + if (err == 0) + USER_MSG("Error: Invalid network address given.\n"); + else + perror("invalid address family"); + + return -1; + } + + if (!pisa_ipv6_addr_is_hit(&hit2_addr.sin6_addr)) + { + DEBUG_MED("Second \"HIT\" was not actually a HIT."); + return -1; + } + + return !memcmp(hit1_addr.sin6_addr.s6_addr, hit2_addr.sin6_addr.s6_addr, sizeof(hit1_addr.sin6_addr.s6_addr)); +} + + /** @todo Make sure that the address we're sending from is a HIT **/ /** Sends the message given in gen_hdr and waits for a reply (quits after receiving