From 953498a3688a11381e9e3e7af26b7fa3dd533571 Mon Sep 17 00:00:00 2001 From: Martin Schanzenbach Date: Fri, 1 Jun 2012 09:12:04 +0000 Subject: [PATCH] -comments --- src/gns/nss/nss_gns.c | 53 +++++++++++++++++++++++++++++++++++++ src/gns/nss/nss_gns_query.c | 10 +++++++ src/gns/nss/nss_gns_query.h | 17 ++++++++++-- 3 files changed, 78 insertions(+), 2 deletions(-) diff --git a/src/gns/nss/nss_gns.c b/src/gns/nss/nss_gns.c index 8aace9c04..3bb45a153 100644 --- a/src/gns/nss/nss_gns.c +++ b/src/gns/nss/nss_gns.c @@ -34,11 +34,20 @@ #include +/** macro to align idx to 32bit boundary */ #define ALIGN(idx) do { \ if (idx % sizeof(void*)) \ idx += (sizeof(void*) - idx % sizeof(void*)); /* Align on 32 bit boundary */ \ } while(0) + +/** + * function to check if name ends with a specific suffix + * + * @param name the name to check + * @param suffix the suffix to check for + * @return 1 if true + */ static int ends_with(const char *name, const char* suffix) { size_t ln, ls; assert(name); @@ -50,10 +59,29 @@ static int ends_with(const char *name, const char* suffix) { return strcasecmp(name+ln-ls, suffix) == 0; } + +/** + * Check if name is inside .gnunet or .zkey TLD + * + * @param name name to check + * @return 1 if true + */ static int verify_name_allowed(const char *name) { return ends_with(name, ".gnunet") || ends_with(name, ".zkey"); } +/** + * The gethostbyname hook executed by nsswitch + * + * @param name the name to resolve + * @param af the address family to resolve + * @param result the result hostent + * @param buffer the result buffer + * @param buflen length of the buffer + * @param errnop idk + * @param h_errnop idk + * @return a nss_status code + */ enum nss_status _nss_gns_gethostbyname2_r( const char *name, int af, @@ -166,6 +194,17 @@ finish: return status; } +/** + * The gethostbyname hook executed by nsswitch + * + * @param name the name to resolve + * @param result the result hostent + * @param buffer the result buffer + * @param buflen length of the buffer + * @param errnop idk + * @param h_errnop idk + * @return a nss_status code + */ enum nss_status _nss_gns_gethostbyname_r ( const char *name, struct hostent *result, @@ -184,6 +223,20 @@ enum nss_status _nss_gns_gethostbyname_r ( h_errnop); } +/** + * The gethostbyaddr hook executed by nsswitch + * We can't do this so we always return NSS_STATUS_UNAVAIL + * + * @param addr the address to resolve + * @param len the length of the address + * @param af the address family of the address + * @param result the result hostent + * @param buffer the result buffer + * @param buflen length of the buffer + * @param errnop idk + * @param h_errnop idk + * @return NSS_STATUS_UNAVAIL + */ enum nss_status _nss_gns_gethostbyaddr_r( const void* addr, int len, diff --git a/src/gns/nss/nss_gns_query.c b/src/gns/nss/nss_gns_query.c index ba9fa1496..ab88d22cb 100644 --- a/src/gns/nss/nss_gns_query.c +++ b/src/gns/nss/nss_gns_query.c @@ -4,6 +4,16 @@ #include "nss_gns_query.h" #include + +/** + * Wrapper function that uses gnunet-gns cli tool to resolve + * an IPv4/6 address. + * + * @param af address family + * @param name the name to resolve + * @param u the userdata (result struct) + * @return -1 on error else 0 + */ int gns_resolve_name(int af, const char *name, struct userdata *u) { FILE *p; diff --git a/src/gns/nss/nss_gns_query.h b/src/gns/nss/nss_gns_query.h index ab8b6cb43..0b4dae5e7 100644 --- a/src/gns/nss/nss_gns_query.h +++ b/src/gns/nss/nss_gns_query.h @@ -1,5 +1,9 @@ -#ifndef fooqueryhfoo -#define fooqueryhfoo +#ifndef NSS_GNS_QUERY_H +#define NSS_GNS_QUERY_H + +/** + * Parts taken from nss-mdns. Original license statement follows + */ /* $Id$ */ @@ -46,6 +50,15 @@ struct userdata { } data; }; +/** + * Wrapper function that uses gnunet-gns cli tool to resolve + * an IPv4/6 address. + * + * @param af address family + * @param name the name to resolve + * @param u the userdata (result struct) + * @return -1 on error else 0 + */ int gns_resolve_name(int af, const char *name, struct userdata *userdata); -- 2.25.1