Annotation of 43BSDTahoe/etc/named/ns_sort.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copyright (c) 1986 Regents of the University of California.
        !             3:  * All rights reserved.
        !             4:  *
        !             5:  * Redistribution and use in source and binary forms are permitted
        !             6:  * provided that the above copyright notice and this paragraph are
        !             7:  * duplicated in all such forms and that any documentation,
        !             8:  * advertising materials, and other materials related to such
        !             9:  * distribution and use acknowledge that the software was developed
        !            10:  * by the University of California, Berkeley.  The name of the
        !            11:  * University may not be used to endorse or promote products derived
        !            12:  * from this software without specific prior written permission.
        !            13:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
        !            14:  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
        !            15:  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
        !            16:  */
        !            17: 
        !            18: #ifndef lint
        !            19: static char sccsid[] = "@(#)ns_sort.c  4.4 (Berkeley) 6/18/88";
        !            20: #endif /* not lint */
        !            21: 
        !            22: #include <stdio.h>
        !            23: #include <sys/types.h>
        !            24: #include <sys/time.h>
        !            25: #include <sys/socket.h>
        !            26: #include <sys/file.h>
        !            27: #include <netinet/in.h>
        !            28: #include <syslog.h>
        !            29: #include <arpa/nameser.h>
        !            30: #include "ns.h"
        !            31: #include "db.h"
        !            32: 
        !            33: extern char *p_type(), *p_class();
        !            34: 
        !            35: extern int     debug;
        !            36: extern  FILE   *ddt;
        !            37: 
        !            38: struct netinfo* 
        !            39: local(from)
        !            40:        struct sockaddr_in *from;
        !            41: {
        !            42:        extern struct netinfo *nettab, netloop;
        !            43:        struct netinfo *ntp;
        !            44: 
        !            45:        if (from->sin_addr.s_addr == netloop.my_addr.s_addr)
        !            46:                return( &netloop);
        !            47:        for (ntp = nettab; ntp != NULL; ntp = ntp->next) {
        !            48:                if (ntp->net == (from->sin_addr.s_addr & ntp->mask))
        !            49:                        return(ntp);
        !            50:        }
        !            51:        return(NULL);
        !            52: }
        !            53: 
        !            54: 
        !            55: sort_response(cp, ancount, lp, eom)
        !            56:        register char *cp;
        !            57:        register int ancount;
        !            58:        struct netinfo *lp;
        !            59:        u_char *eom;
        !            60: {
        !            61:        register struct netinfo *ntp;
        !            62:        extern struct netinfo *nettab;
        !            63: 
        !            64: #ifdef DEBUG
        !            65:        if (debug > 2)
        !            66:            fprintf(ddt,"sort_response(%d)\n", ancount);
        !            67: #endif DEBUG
        !            68:        if (ancount > 1) {
        !            69:                if (sort_rr(cp, ancount, lp, eom))
        !            70:                        return;
        !            71:                for (ntp = nettab; ntp != NULL; ntp = ntp->next) {
        !            72:                        if ((ntp->net == lp->net) && (ntp->mask == lp->mask))
        !            73:                                continue;
        !            74:                        if (sort_rr(cp, ancount, ntp, eom))
        !            75:                                break;
        !            76:                }
        !            77:        }
        !            78: }
        !            79: 
        !            80: int
        !            81: sort_rr(cp, count, ntp, eom)
        !            82:        register u_char *cp;
        !            83:        int count;
        !            84:        register struct netinfo *ntp;
        !            85:        u_char *eom;
        !            86: {
        !            87:        int type, class, dlen, n, c;
        !            88:        struct in_addr inaddr;
        !            89:        u_char *rr1;
        !            90: 
        !            91: #ifdef DEBUG
        !            92:        if (debug > 2) {
        !            93:            inaddr.s_addr = ntp->net;
        !            94:            fprintf(ddt,"sort_rr( x%x, %d, %s)\n",cp, count,
        !            95:                inet_ntoa(inaddr));
        !            96:        }
        !            97: #endif DEBUG
        !            98:        rr1 = NULL;
        !            99:        for (c = count; c > 0; --c) {
        !           100:            n = dn_skipname(cp, eom);
        !           101:            if (n < 0)
        !           102:                return (1);             /* bogus, stop processing */
        !           103:            cp += n;
        !           104:            if (cp + QFIXEDSZ > eom)
        !           105:                return (1);
        !           106:            GETSHORT(type, cp);
        !           107:            GETSHORT(class, cp);
        !           108:            cp += sizeof(u_long);
        !           109:            GETSHORT(dlen, cp);
        !           110:            if (dlen > eom - cp)
        !           111:                return (1);             /* bogus, stop processing */
        !           112:            switch (type) {
        !           113:            case T_A:
        !           114:                switch (class) {
        !           115:                case C_IN:
        !           116:                        bcopy(cp, (char *)&inaddr, sizeof(inaddr));
        !           117:                        if (rr1 == NULL)
        !           118:                                rr1 = cp;
        !           119:                        if ((ntp->mask & inaddr.s_addr) == ntp->net) {
        !           120: #ifdef DEBUG
        !           121:                            if (debug > 1) {
        !           122:                                fprintf(ddt,"net %s best choice\n",
        !           123:                                        inet_ntoa(inaddr));
        !           124:                            }
        !           125: #endif DEBUG
        !           126:                            if (rr1 != cp) {
        !           127:                                bcopy(rr1, cp, sizeof(inaddr));
        !           128:                                bcopy((char *)&inaddr, rr1, sizeof(inaddr));
        !           129:                            }
        !           130:                            return(1);
        !           131:                        }
        !           132:                        break;
        !           133:                }
        !           134:                break;
        !           135:            }
        !           136:            cp += dlen;
        !           137:        }
        !           138:        return(0);
        !           139: }
        !           140: 
        !           141: #ifdef notdef
        !           142: dump_namebuf(np)
        !           143:        register struct namebuf *np;
        !           144: {
        !           145:        register struct databuf *dp;
        !           146:        long n;
        !           147:        u_long addr;
        !           148:        u_short i;
        !           149:        int j;
        !           150:        char *cp;
        !           151:        char *proto;
        !           152:        FILE *fp;
        !           153:        extern char *inet_ntoa(), *p_protocal(), *p_service();
        !           154:        int found_data;
        !           155: 
        !           156:        gettime(&tt);
        !           157:        if ((fp = fopen("/usr/tmp/namebuf", "a")) == NULL)
        !           158:                return;
        !           159:        found_data = 0;
        !           160:        for (dp = np->n_data; dp != NULL; dp = dp->d_next) {
        !           161:                if (dp->d_ttl <= tt.tv_sec)
        !           162:                        continue;       /* Stale */
        !           163:                if (!found_data) {
        !           164:                    fprintf(fp, "%s\t", np->n_dname);
        !           165:                    if (strlen(np->n_dname) < 8)
        !           166:                        (void) putc('\t', fp);
        !           167:                    found_data++;
        !           168:                } else
        !           169:                        fprintf(fp, "\t\t");
        !           170:                if (dp->d_zone == 0)
        !           171:                        fprintf(fp, "%d\t", dp->d_ttl - tt.tv_sec);
        !           172:                else if (dp->d_ttl > zones[dp->d_zone].z_minimum)
        !           173:                        fprintf(fp, "%d\t", dp->d_ttl);
        !           174:                fprintf(fp, "%s\t%s\t", p_class(dp->d_class),
        !           175:                        p_type(dp->d_type));
        !           176:                cp = dp->d_data;
        !           177:                /*
        !           178:                 * Print type specific data
        !           179:                 */
        !           180:                switch (dp->d_type) {
        !           181:                case T_A:
        !           182:                        switch (dp->d_class) {
        !           183:                        case C_IN:
        !           184:                                n = htonl(_getlong(cp));
        !           185:                                fprintf(fp, "%s\n",
        !           186:                                   inet_ntoa(*(struct in_addr *)&n));
        !           187:                                break;
        !           188:                        }
        !           189:                        break;
        !           190:                case T_CNAME:
        !           191:                case T_MB:
        !           192:                case T_MG:
        !           193:                case T_MR:
        !           194:                case T_PTR:
        !           195:                        if (cp[0] == '\0')
        !           196:                                fprintf(fp, ".\n");
        !           197:                        else
        !           198:                                fprintf(fp, "%s.\n", cp);
        !           199:                        break;
        !           200: 
        !           201:                case T_NS:
        !           202:                        cp = dp->d_data;
        !           203:                        if (cp[0] == '\0')
        !           204:                                fprintf(fp, ".\t");
        !           205:                        else
        !           206:                                fprintf(fp, "%s.", cp);
        !           207:                        if (dp->d_nstime)
        !           208:                                fprintf(fp, "\t; %d", dp->d_nstime);
        !           209:                        fprintf(fp, "\n");
        !           210:                        break;
        !           211: 
        !           212:                case T_HINFO:
        !           213:                        if (n = *cp++) {
        !           214:                                fprintf(fp, "\"%.*s\"", n, cp);
        !           215:                                cp += n;
        !           216:                        } else
        !           217:                                fprintf(fp, "\"\"");
        !           218:                        if (n = *cp++)
        !           219:                                fprintf(fp, " \"%.*s\"", n, cp);
        !           220:                        else
        !           221:                                fprintf(fp, "\"\"");
        !           222:                        (void) putc('\n', fp);
        !           223:                        break;
        !           224: 
        !           225:                case T_SOA:
        !           226:                        fprintf(fp, "%s.", cp);
        !           227:                        cp += strlen(cp) + 1;
        !           228:                        fprintf(fp, " %s. (\n", cp);
        !           229:                        cp += strlen(cp) + 1;
        !           230:                        fprintf(fp, "\t\t%d", _getlong(cp));
        !           231:                        cp += sizeof(u_long);
        !           232:                        fprintf(fp, " %d", _getlong(cp));
        !           233:                        cp += sizeof(u_long);
        !           234:                        fprintf(fp, " %d", _getlong(cp));
        !           235:                        cp += sizeof(u_long);
        !           236:                        fprintf(fp, " %d", _getlong(cp));
        !           237:                        cp += sizeof(u_long);
        !           238:                        fprintf(fp, " %d )\n", _getlong(cp));
        !           239:                        break;
        !           240: 
        !           241:                case T_MX:
        !           242:                        fprintf(fp,"%d", _getshort(cp));
        !           243:                        cp += sizeof(u_short);
        !           244:                        fprintf(fp," %s.\n", cp);
        !           245:                        break;
        !           246: 
        !           247: 
        !           248:                case T_UINFO:
        !           249:                        fprintf(fp, "\"%s\"\n", cp);
        !           250:                        break;
        !           251: 
        !           252:                case T_UID:
        !           253:                case T_GID:
        !           254:                        if (dp->d_size == sizeof(u_long)) {
        !           255:                                fprintf(fp, "%d\n", _getlong(cp));
        !           256:                                cp += sizeof(u_long);
        !           257:                        }
        !           258:                        break;
        !           259: 
        !           260:                case T_WKS:
        !           261:                        addr = htonl(_getlong(cp));     
        !           262:                        fprintf(fp,"%s ",
        !           263:                            inet_ntoa(*(struct in_addr *)&addr));
        !           264:                        cp += sizeof(u_long);
        !           265:                        proto = p_protocal(*cp); /* protocal */
        !           266:                        cp += sizeof(char); 
        !           267:                        fprintf(fp, "%s ", proto);
        !           268:                        i = 0;
        !           269:                        while(cp < dp->d_data + dp->d_size) {
        !           270:                                j = *cp++;
        !           271:                                do {
        !           272:                                        if(j & 0200)
        !           273:                                                fprintf(fp," %s",
        !           274:                                                   p_service(i, proto));
        !           275:                                        j <<= 1;
        !           276:                                } while(++i & 07);
        !           277:                        } 
        !           278:                        fprintf(fp,"\n");
        !           279:                        break;
        !           280: 
        !           281:                default:
        !           282:                        fprintf(fp, "???\n");
        !           283:                }
        !           284:        }
        !           285:        (void) fclose(fp);
        !           286: }
        !           287: #endif notdef

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.