[IPv6 IRC-DEV] Modulo Hispano-IPv6 ipv6/ircd res.c,1.4,1.5 support.c,1.5,1.6
Brought to you by:
zolty
From: Zolty <zo...@us...> - 2002-09-16 15:47:32
|
Update of /cvsroot/irc-dev/ipv6/ircd In directory usw-pr-cvs1:/tmp/cvs-serv22700/ircd Modified Files: res.c support.c Log Message: INET6.9 Index: res.c =================================================================== RCS file: /cvsroot/irc-dev/ipv6/ircd/res.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- res.c 14 Sep 2002 22:44:51 -0000 1.4 +++ res.c 16 Sep 2002 15:47:29 -0000 1.5 @@ -160,7 +160,7 @@ static void rem_cache(aCache *); static void rem_request(ResRQ *); -static int do_query_name(Link *, char *, ResRQ *); +static int do_query_name(Link *, char *, ResRQ *, int); static int do_query_number(Link *, struct IN_ADDR *, ResRQ *); static void resend_query(ResRQ *); static int proc_answer(ResRQ *, HEADER *, unsigned char *, unsigned char *); @@ -506,18 +506,34 @@ } } -struct hostent *gethost_byname(char *name, Link *lp) +/* + * Get a host address of type type, by it's name. + * lp contains the client info. + * returns the host info if found in cache, or NULL when it doesn't + * know it yet. + */ +struct hostent *gethost_byname_type(char *name, Link *lp, int type) { aCache *cp; reinfo.re_na_look++; if ((cp = find_cache_name(name))) - return &cp->he.h; - if (lp) - do_query_name(lp, name, NULL); + return (struct hostent *)&(cp->he); + if (!lp) + return NULL; + (void)do_query_name(lp, name, NULL, type); return NULL; } +struct hostent *gethost_byname(char *name, Link *lp) +{ +#ifdef INET6 + return gethost_byname_type(name, lp, T_AAAA); +#else + return gethost_byname_type(name, lp, T_A); +#endif +} + struct hostent *gethost_byaddr(struct IN_ADDR *addr, Link *lp) { aCache *cp; @@ -531,7 +547,7 @@ return NULL; } -static int do_query_name(Link *lp, char *name, ResRQ *rptr) +static int do_query_name(Link *lp, char *name, ResRQ *rptr, int type) { char hname[HOSTLEN + 1]; int len; @@ -555,11 +571,11 @@ { if ((rptr = make_request(lp)) == NULL) return -1; - rptr->type = T_A; + rptr->type = type; rptr->name = (char *)RunMalloc(strlen(name) + 1); strcpy(rptr->name, name); } - return (query_name(hname, C_IN, T_A, rptr)); + return (query_name(hname, C_IN, type, rptr)); } /* @@ -567,12 +583,44 @@ */ static int do_query_number(Link *lp, struct IN_ADDR *numb, ResRQ *rptr) { +#ifdef INET6 + char ipbuf[128]; +#else char ipbuf[32]; +#endif Reg2 unsigned char *cp = (unsigned char *)&numb->S_ADDR; +#ifdef INET6 + cp = (u_char *)numb->S_ADDR; + if (cp[0] == 0 && cp[1] == 0 && cp[2] == 0 && cp[3] == 0 && cp[4] == 0 && + cp[5] == 0 && cp[6] == 0 && cp[7] == 0 && cp[8] == 0 && cp[9] == 0 && + ((cp[10] == 0 && cp[11] == 0) || (cp[10] == 0xff && cp[11] == 0xff))) + { + (void)sprintf(ipbuf, "%u.%u.%u.%u.in-addr.arpa.", + (u_int)(cp[15]), (u_int)(cp[14]), (u_int)(cp[13]), (u_int)(cp[12])); + } + else + { + + (void)sprintf(ipbuf, + "%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.ip6.int.", + (u_int)(cp[15] & 0xf), (u_int)(cp[15] >> 4), (u_int)(cp[14] & 0xf), + (u_int)(cp[14] >> 4), (u_int)(cp[13] & 0xf), (u_int)(cp[13] >> 4), + (u_int)(cp[12] & 0xf), (u_int)(cp[12] >> 4), (u_int)(cp[11] & 0xf), + (u_int)(cp[11] >> 4), (u_int)(cp[10] & 0xf), (u_int)(cp[10] >> 4), + (u_int)(cp[9] & 0xf), (u_int)(cp[9] >> 4), (u_int)(cp[8] & 0xf), + (u_int)(cp[8] >> 4), (u_int)(cp[7] & 0xf), (u_int)(cp[7] >> 4), + (u_int)(cp[6] & 0xf), (u_int)(cp[6] >> 4), (u_int)(cp[5] & 0xf), + (u_int)(cp[5] >> 4), (u_int)(cp[4] & 0xf), (u_int)(cp[4] >> 4), + (u_int)(cp[3] & 0xf), (u_int)(cp[3] >> 4), (u_int)(cp[2] & 0xf), + (u_int)(cp[2] >> 4), (u_int)(cp[1] & 0xf), (u_int)(cp[1] >> 4), + (u_int)(cp[0] & 0xf), (u_int)(cp[0] >> 4)); + } +#else sprintf_irc(ipbuf, "%u.%u.%u.%u.in-addr.arpa.", (unsigned int)(cp[3]), (unsigned int)(cp[2]), (unsigned int)(cp[1]), (unsigned int)(cp[0])); +#endif if (!rptr) { @@ -580,7 +628,7 @@ return -1; rptr->type = T_PTR; #ifdef INET6 - memcpy(rptr->addr.S_ADDR, numb->S_ADDR, IN6ADDRSZ); + memcpy(rptr->addr.S_ADDR, numb->S_ADDR, sizeof(struct IN_ADDR)); #else rptr->addr.S_ADDR = numb->S_ADDR; #endif @@ -642,8 +690,11 @@ case T_PTR: do_query_number(NULL, &rptr->addr, rptr); break; +#ifdef INET6 + case T_AAAA: +#endif case T_A: - do_query_name(NULL, rptr->name, rptr); + do_query_name(NULL, rptr->name, rptr, rptr->type); break; default: break; @@ -793,9 +844,18 @@ switch (type) { +#ifdef INET6 + case T_AAAA: +#endif case T_A: /* check for invalid dlen or too many addresses */ +#ifdef INET6 + if (dlen != ((type == + T_AAAA) ? sizeof(struct in6_addr) : sizeof(struct in_addr))) +// || ++addr_count >= RES_MAXADDRS) +#else if (dlen != sizeof(struct IN_ADDR) || ++addr_count >= RES_MAXADDRS) +#endif break; if (ans == 1) hp->h_addrtype = (addr_class == C_IN) ? AFINET : AF_UNSPEC; @@ -985,6 +1045,7 @@ if (a && rptr->type == T_PTR) { struct hostent *hp2 = NULL; + int type; if (BadPtr(rptr->he.h.h_name)) /* Kludge! 960907/Vesa */ goto getres_err; @@ -997,7 +1058,13 @@ * type we automatically gain the use of the cache with no * extra kludges. */ - if ((hp2 = gethost_byname((char *)rptr->he.h.h_name, &rptr->cinfo))) +#ifdef INET6 + type = T_AAAA; +#else + type = T_A; +#endif + if ((hp2 = + gethost_byname_type((char *)rptr->he.h.h_name, &rptr->cinfo, type))) { if (lp) memcpy(lp, &rptr->cinfo, sizeof(Link)); @@ -1049,9 +1116,35 @@ rptr->sends = 0; rptr->resend = 1; resend_query(rptr); +#ifdef INET6 + /* + * Comment out this ifdef to get names like ::ffff:a.b.c.d + * + * We always want to query for both IN A and IN AAAA + */ + if (rptr->type == T_AAAA) + { + query_name(rptr->name, C_IN, T_A, rptr); + Debug((DEBUG_DNS, + "getres_err: didn't work with T_AAAA, now also trying with T_A for %s", + rptr->name)); + } +#endif } else + { +#ifdef INET6 + /* Comment out this ifdef to get names like ::ffff:a.b.c.d */ + if (rptr->type == T_AAAA) + { + query_name(rptr->name, C_IN, T_A, rptr); + Debug((DEBUG_DNS, + "getres_err: didn't work with T_AAAA, now also trying with T_A for %s", + rptr->name)); + } +#endif resend_query(rptr); + } } else if (lp) memcpy(lp, &rptr->cinfo, sizeof(Link)); @@ -1248,6 +1341,20 @@ hashv += hashv + (int)*ip++; hashv += hashv + (int)*ip++; hashv += hashv + (int)*ip++; +#ifdef INET6 + hashv += hashv + (int)*ip++; + hashv += hashv + (int)*ip++; + hashv += hashv + (int)*ip++; + hashv += hashv + (int)*ip++; + hashv += hashv + (int)*ip++; + hashv += hashv + (int)*ip++; + hashv += hashv + (int)*ip++; + hashv += hashv + (int)*ip++; + hashv += hashv + (int)*ip++; + hashv += hashv + (int)*ip++; + hashv += hashv + (int)*ip++; + hashv += hashv + (int)*ip++; +#endif hashv %= ARES_CACSIZE; return (hashv); } Index: support.c =================================================================== RCS file: /cvsroot/irc-dev/ipv6/ircd/support.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- support.c 16 Sep 2002 14:07:32 -0000 1.5 +++ support.c 16 Sep 2002 15:47:29 -0000 1.6 @@ -128,6 +128,7 @@ return NULL; } + Debug((DEBUG_DNS, "Mirar %s", buf)); /* * quick and dirty hack to give ipv4 just ipv4 instead of * ::ffff:ipv4 - Q |