X-Git-Url: http://git.dolda2000.com/gitweb/?a=blobdiff_plain;f=nss-icmp.c;h=9c32c1c8d2bedf0bb706da481e9dc42dac08f3bf;hb=732b835938a7a80fe3c5ef71b84fa2ce0090bd01;hp=803acbcc8c07e6cc87d052bdd2cafa252f3dcbe5;hpb=f0df8f66ac34f08e871eaf4bd1e04303d97df032;p=icmp-dn.git diff --git a/nss-icmp.c b/nss-icmp.c index 803acbc..9c32c1c 100644 --- a/nss-icmp.c +++ b/nss-icmp.c @@ -1,3 +1,24 @@ +/* + * nss-icmp or libnss_icmp - GNU C Library NSS module to query host + * names by ICMP. + * Copyright (C) 2005 Fredrik Tolf + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + * MA 02111-1307, USA + */ + #include #include #include @@ -13,6 +34,11 @@ #include #define CONFIGFILE "/etc/nss-icmp.conf" +#if 0 +#define DEBUGP(format...) fprintf(stderr, "nss-icmp: " format); +#else +#define DEBUGP(format...) +#endif struct cache { struct cache *next, *prev; @@ -205,6 +231,8 @@ enum nss_status _nss_icmp_gethostbyaddr_r(const void *addr, socklen_t len, int a return(NSS_STATUS_UNAVAIL); } + DEBUGP("starting lookup\n"); + if(usecache) { expirecache(); for(cc = cache; cc != NULL; cc = cc->next) { @@ -216,12 +244,14 @@ enum nss_status _nss_icmp_gethostbyaddr_r(const void *addr, socklen_t len, int a } if(cc == NULL) { + DEBUGP("address not in cache, looking up for real\n"); ap = (u_int8_t *)addr; if(inet_ntop(af, addr, addrbuf, sizeof(addrbuf)) == NULL) { *errnop = errno; *h_errnop = NETDB_INTERNAL; return(NSS_STATUS_UNAVAIL); } + DEBUGP("address is %s\n", addrbuf); if(pipe(pfd)) { *errnop = errno; @@ -322,6 +352,7 @@ enum nss_status _nss_icmp_gethostbyaddr_r(const void *addr, socklen_t len, int a if(usecache) updatecache(addr, len, af, retbuf->aliaslist, ttl); } else { + DEBUGP("address found in cache\n"); if(cc->notfound) { *h_errnop = TRY_AGAIN; /* XXX: Is this correct? */ return(NSS_STATUS_NOTFOUND); @@ -330,22 +361,20 @@ enum nss_status _nss_icmp_gethostbyaddr_r(const void *addr, socklen_t len, int a p3 = buffer + sizeof(*retbuf); for(i = 0; cc->names[i] != NULL; i++) { thislen = strlen(cc->names[i]); + DEBUGP("filling in address %s, length %i\n", cc->names[i], thislen); if((p3 - buffer) + thislen + 1 > buflen) { *errnop = ENOMEM; *h_errnop = NETDB_INTERNAL; return(NSS_STATUS_UNAVAIL); } memcpy(p3, cc->names[i], thislen + 1); - retbuf->aliaslist[an] = p3; + retbuf->aliaslist[i] = p3; p3 += thislen + 1; - if(++an == 16) { - *errnop = ENOMEM; - *h_errnop = NETDB_INTERNAL; - return(NSS_STATUS_UNAVAIL); - } } + retbuf->aliaslist[i] = NULL; } + DEBUGP("returning hostent\n"); memcpy(retbuf->retaddr, addr, len); retbuf->addrlist[0] = retbuf->retaddr; retbuf->addrlist[1] = NULL; @@ -356,5 +385,12 @@ enum nss_status _nss_icmp_gethostbyaddr_r(const void *addr, socklen_t len, int a result->h_length = len; *h_errnop = NETDB_SUCCESS; + DEBUGP("returning\n"); return(NSS_STATUS_SUCCESS); } + +/* + * Local Variables: + * compile-command: "gcc -shared -Wall -g -o libnss_icmp.so.2 nss-icmp.c" + * End: + */