Annotation of 43BSDReno/contrib/isode-beta/compat/isoaddrs.c, revision 1.1

1.1     ! root        1: /* isoaddrs.c - simple parsing of ISODE addresses */
        !             2: 
        !             3: #ifndef        lint
        !             4: static char *rcsid = "$Header: /f/osi/compat/RCS/isoaddrs.c,v 7.2 90/07/09 14:31:51 mrose Exp $";
        !             5: #endif
        !             6: 
        !             7: /* 
        !             8:  * $Header: /f/osi/compat/RCS/isoaddrs.c,v 7.2 90/07/09 14:31:51 mrose Exp $
        !             9:  *
        !            10:  *
        !            11:  * $Log:       isoaddrs.c,v $
        !            12:  * Revision 7.2  90/07/09  14:31:51  mrose
        !            13:  * sync
        !            14:  * 
        !            15:  * Revision 7.1  90/01/11  18:35:10  mrose
        !            16:  * real-sync
        !            17:  * 
        !            18:  * Revision 7.0  89/11/23  21:23:05  mrose
        !            19:  * Release 6.0
        !            20:  * 
        !            21:  */
        !            22: 
        !            23: /*
        !            24:  *                               NOTICE
        !            25:  *
        !            26:  *    Acquisition, use, and distribution of this module and related
        !            27:  *    materials are subject to the restrictions of a license agreement.
        !            28:  *    Consult the Preface in the User's Manual for the full terms of
        !            29:  *    this agreement.
        !            30:  *
        !            31:  */
        !            32: 
        !            33: 
        !            34: /* LINTLIBRARY */
        !            35: 
        !            36: #include <ctype.h>
        !            37: #include <stdio.h>
        !            38: #include "general.h"
        !            39: #include "manifest.h"
        !            40: #include "isoaddrs.h"
        !            41: #include "internet.h"
        !            42: #include "tailor.h"
        !            43: 
        !            44: /*    DATA */
        !            45: 
        !            46: static char *isomacros = "isomacros";
        !            47: 
        !            48: #define        MBUCKETS        128
        !            49: #define        MHASH(nm) \
        !            50:     (((nm)[1]) ? (((chrcnv[((nm)[0])] - chrcnv[((nm)[1])]) & 0x1f) \
        !            51:                        + ((chrcnv[(nm)[2]]) & 0x5f)) \
        !            52:               : (chrcnv[(nm)[0]]) & 0x7f)
        !            53: 
        !            54: struct macro {
        !            55:     char   *m_name;
        !            56:     char   *m_value;
        !            57: 
        !            58:     struct macro *m_chain;
        !            59: };
        !            60: 
        !            61: static int inited = 0;
        !            62: static struct macro *Mbuckets[MBUCKETS];
        !            63: 
        !            64: /*    MACROS */
        !            65: 
        !            66: static struct macro *name2macro (name)
        !            67: char   *name;
        !            68: {
        !            69:     register struct macro *m;
        !            70: 
        !            71:     read_macros ();
        !            72: 
        !            73:     for (m = Mbuckets[MHASH (name)];
        !            74:             m && lexequ (m -> m_name, name);
        !            75:             m = m -> m_chain)
        !            76:        continue;
        !            77: 
        !            78:     if (m)
        !            79:        LLOG (addr_log, LLOG_DEBUG,
        !            80:              ("MACRO \"%s\" VALUE \"%s\"", m -> m_name, m -> m_value));
        !            81:     else
        !            82:        LLOG (addr_log, LLOG_DEBUG,
        !            83:              ("lookup of MACRO \"%s\" failed", name));
        !            84: 
        !            85:     return m;
        !            86: }
        !            87: 
        !            88: /*  */
        !            89: 
        !            90: static struct macro *value2macro (value)
        !            91: char   *value;
        !            92: {
        !            93:     register int   i,
        !            94:                   j,
        !            95:                   k;
        !            96:     register struct macro *m,
        !            97:                          *p,
        !            98:                         **np,
        !            99:                         **pp;
        !           100: 
        !           101:     read_macros ();
        !           102: 
        !           103:     p = NULL, i = 0;
        !           104:     k = strlen (value);
        !           105:     for (pp = (np = Mbuckets) + MBUCKETS; np < pp; np++)
        !           106:        for (m = *np; m; m = m -> m_chain)
        !           107:            if ((j = strlen (m -> m_value)) <= k
        !           108:                    &&  j > i
        !           109:                    && strncmp (value, m -> m_value, j) == 0)
        !           110:                p = m, i = j;
        !           111: 
        !           112:     if (p)
        !           113:        LLOG (addr_log, LLOG_DEBUG,
        !           114:              ("MACRO \"%s\" VALUE \"%s\" differential %d",
        !           115:               p -> m_name, p -> m_value, k - strlen (p -> m_value)));
        !           116:     else
        !           117:        LLOG (addr_log, LLOG_DEBUG,
        !           118:              ("lookup of VALUE \"%s\" failed", value));
        !           119: 
        !           120:     return p;
        !           121: }
        !           122: 
        !           123: /*  */
        !           124: 
        !           125: static int  read_macros ()
        !           126: {
        !           127:     register char *hp;
        !           128:     char    buffer[BUFSIZ];
        !           129: 
        !           130:     if (inited)
        !           131:        return;
        !           132:     inited = 1;
        !           133: 
        !           134:     bzero ((char *) Mbuckets, sizeof Mbuckets);
        !           135: 
        !           136:     read_file (isodefile (isomacros, 0));
        !           137: 
        !           138:     if ((hp = getenv ("HOME")) == NULL)
        !           139:        hp = ".";
        !           140:     (void) sprintf (buffer, "%s/.isode_macros", hp);
        !           141:     read_file (buffer);
        !           142: }
        !           143: 
        !           144: /*  */
        !           145: 
        !           146: static int  read_file (file)
        !           147: char   *file;
        !           148: {
        !           149:     register char *cp;
        !           150:     char    buffer[BUFSIZ + 1],
        !           151:           *vec[NVEC + NSLACK + 1];
        !           152:     register FILE *fp;
        !           153: 
        !           154:     if ((fp = fopen (file, "r")) == NULL)
        !           155:        return;
        !           156: 
        !           157:     while (fgets (buffer, sizeof buffer, fp)) {
        !           158:        if (*buffer == '#')
        !           159:            continue;
        !           160:        if (cp = index (buffer, '\n'))
        !           161:            *cp  = NULL;
        !           162:        if (str2vec (buffer, vec) < 2)
        !           163:            continue;
        !           164: 
        !           165:        if (add_macro (vec[0], vec[1]) == NOTOK)
        !           166:            break;
        !           167:     }
        !           168: 
        !           169:     (void) fclose (fp);
        !           170: }
        !           171: 
        !           172: /*  */
        !           173: 
        !           174: static int  add_macro (name, value)
        !           175: char   *name,
        !           176:        *value;
        !           177: {
        !           178:     int            i;
        !           179:     register char  *cp;
        !           180:     char    buffer[BUFSIZ];
        !           181:     register struct macro *m,
        !           182:                          *p;
        !           183: 
        !           184:     if (cp = index (value, '=')) {
        !           185:        *cp++ = NULL;
        !           186:        if ((p = name2macro (value)) == NULL) {
        !           187:            SLOG (addr_log, LLOG_EXCEPTIONS, NULLCP,
        !           188:                  ("macro \"%s\" references non-existant macro \"%s\"",
        !           189:                   name, value));
        !           190:            return OK;
        !           191:        }
        !           192: 
        !           193:        (void) sprintf (value = buffer, "%s%s", p -> m_value, cp);
        !           194:     }
        !           195: 
        !           196:     if ((m = (struct macro *) calloc (1, sizeof *m)) == NULL) {
        !           197:        SLOG (addr_log, LLOG_EXCEPTIONS, NULLCP,
        !           198:              ("calloc of macro structure failed"));
        !           199:        return NOTOK;
        !           200:     }
        !           201:     if ((m -> m_name = malloc ((unsigned) (strlen (name) + 1))) == NULL
        !           202:                || (m -> m_value = malloc ((unsigned) (strlen (value) + 1)))
        !           203:            == NULL) {
        !           204:        SLOG (addr_log, LLOG_EXCEPTIONS, NULLCP,
        !           205:              ("malloc of alias structure failed"));
        !           206:        if (m -> m_name)
        !           207:            free (m -> m_name);
        !           208:        free ((char *) m);
        !           209:        return NOTOK;
        !           210:     }
        !           211:     (void) strcpy (m -> m_name, name);
        !           212:     (void) strcpy (m -> m_value, value);
        !           213: 
        !           214:     m -> m_chain = Mbuckets[i = MHASH (m -> m_name)];
        !           215:     Mbuckets[i] = m;
        !           216: 
        !           217:     return OK;
        !           218: }
        !           219: 
        !           220: /*  */
        !           221: 
        !           222: char   *macro2str (name)
        !           223: char   *name;
        !           224: {
        !           225:     register struct macro *m = name2macro (name);
        !           226: 
        !           227:     return (m ? m -> m_value : NULLCP);
        !           228: }
        !           229: 
        !           230: /*    STR2PADDR */
        !           231: 
        !           232: #define        PS_INIT 0       /* <selector> or <network-address> */
        !           233: #define        PS_SEL1 1       /*   .. got one selector already */
        !           234: #define        PS_SEL2 2       /*   .. got two selectors already */
        !           235: #define        PS_SEL3 3       /* <network-address> */
        !           236: 
        !           237: 
        !           238: static struct pair {
        !           239:     char   *p_name;
        !           240:     char   *p_value;
        !           241: }      afi_entries[] = {
        !           242:     "X121",  "36",
        !           243:     "DCC",   "38",
        !           244:     "TELEX", "54",
        !           245:     "PSTN",  "56",
        !           246:     "ISDN",  "58",
        !           247:     "ICD",   "46",
        !           248:     "LOCAL", "48",
        !           249: 
        !           250:     NULL
        !           251: };
        !           252: 
        !           253: 
        !           254: static char sel1[TSSIZE];
        !           255: static char sel2[TSSIZE];
        !           256: static char sel3[TSSIZE];
        !           257: static char *sels[3] = {
        !           258:     sel1, sel2, sel3
        !           259: };
        !           260: 
        !           261: 
        !           262: #define        IMPLODE(intres,octres,octval,intval) \
        !           263: { \
        !           264:     register int   z = (intval); \
        !           265:     register char *y = (octval); \
        !           266:     register char *zp = y + z; \
        !           267:  \
        !           268:     while (zp-- > y) \
        !           269:        if (!isxdigit (*zp)) { \
        !           270:            SLOG (addr_log, LLOG_EXCEPTIONS, NULLCP, \
        !           271:                  ("invalid hexstring: \"%*.*s\"", \
        !           272:                   z, z, y)); \
        !           273:        } \
        !           274:     (intres) = implode ((u_char *) (octres), y, z); \
        !           275: }
        !           276: 
        !           277: /*  */
        !           278: 
        !           279: #ifdef notdef
        !           280: /* An interim approach to use of Network Addresses... */
        !           281: 
        !           282: #define        INTERIM_IDP             "5400728722"
        !           283: #endif
        !           284: 
        !           285: 
        !           286: struct PSAPaddr *str2paddr (str)
        !           287: char   *str;
        !           288: {
        !           289:     register int    state,
        !           290:                   *lp;
        !           291:     int            j,
        !           292:            lens[3];
        !           293:     register char  *cp,
        !           294:                   *dp,
        !           295:                   *ep,
        !           296:                   *np,
        !           297:                  **sp;
        !           298:     char    buf1[BUFSIZ],
        !           299:            buf2[BUFSIZ],
        !           300:            nsap[NASIZE * 2 + 1];
        !           301:     register struct macro *m;
        !           302:     register struct pair *pp;
        !           303:     static int i = 0;
        !           304:     static struct PSAPaddr pas[2];
        !           305:     register struct PSAPaddr *pa = &pas[i++];
        !           306:     register struct SSAPaddr *sa = &pa -> pa_addr;
        !           307:     register struct TSAPaddr *ta = &sa -> sa_addr;
        !           308:     register struct NSAPaddr *na = ta -> ta_addrs;
        !           309: 
        !           310:     i = i % 2;
        !           311: 
        !           312:     bzero ((char *) pa, sizeof *pa);
        !           313:     (void) strcpy (buf1, str);
        !           314: 
        !           315:     state = PS_INIT;
        !           316:     sp = sels, lp = lens;
        !           317: 
        !           318:     for (cp = buf1; *cp; )
        !           319:        switch (state) {
        !           320:            case PS_INIT:       
        !           321:            case PS_SEL1:
        !           322:            case PS_SEL2:
        !           323:                switch (*cp) {
        !           324:                    case '"':           /* '"' <otherstring> '"' */
        !           325:                        if ((cp = index (dp = cp + 1, '"')) == NULL) {
        !           326:                            SLOG (addr_log, LLOG_EXCEPTIONS, NULLCP,
        !           327:                                  ("missing double-quote in selector: %s",
        !           328:                                   str));
        !           329:                            return NULLPA;
        !           330:                        }
        !           331:                        *cp++ = NULL;
        !           332:                        (void) strcpy (*sp, dp);
        !           333:                        *lp = strlen (dp);
        !           334:                        break;
        !           335: 
        !           336:                    case '#':           /* '#' <digitstring> */
        !           337:                        j = 0;
        !           338:                        for (cp++; isdigit (*cp); cp++)
        !           339:                            j = j * 10 + *cp - '0';
        !           340:                        if (j > 0xffff) {
        !           341:                            SLOG (addr_log, LLOG_EXCEPTIONS, NULLCP,
        !           342:                                  ("invalid #-style selector: %s", str));
        !           343:                            return NULLPA;
        !           344:                        }
        !           345:                        (*sp)[0] = (j >> 8) & 0xff;
        !           346:                        (*sp)[1] = j & 0xff;
        !           347:                        *lp = 2;
        !           348:                        break;
        !           349: 
        !           350:                    case '\'':          /* "'" <hexstring> "'H" */
        !           351:                        if ((cp = index (dp = cp + 1, '\'')) == NULL) {
        !           352: missing_quoteH: ;
        !           353:                            SLOG (addr_log, LLOG_EXCEPTIONS, NULLCP,
        !           354:                                  ("missing 'H in selector: %s",str));
        !           355:                            return NULLPA;
        !           356:                        }
        !           357:                        *cp++ = NULL;
        !           358:                        if (*cp++ != 'H')
        !           359:                            goto missing_quoteH;
        !           360:                        IMPLODE (*lp, *sp, dp, strlen (dp));
        !           361:                        break;
        !           362: 
        !           363:                    case '/':           /* empty selector */
        !           364:                        *lp = 0;
        !           365:                        break;
        !           366: 
        !           367:                    default:
        !           368:                        goto stuff_selectors;
        !           369:                }
        !           370:                sp++, lp++;
        !           371:                if (*cp++ != '/') {
        !           372:                    SLOG (addr_log, LLOG_EXCEPTIONS, NULLCP,
        !           373:                          ("missing selector seperator at position %d: %s",
        !           374:                           cp - buf1, str));
        !           375:                    return NULLPA;
        !           376:                }
        !           377:                state++;
        !           378:                break;
        !           379: 
        !           380: stuff_selectors: ;
        !           381:                state = PS_SEL3;
        !           382:                /* and fall */
        !           383: 
        !           384:            case PS_SEL3:
        !           385:                if ((cp = index (ep = cp, '|')) == NULL)
        !           386:                    cp = ep + strlen (ep);
        !           387:                else
        !           388:                    *cp++ = NULL;
        !           389: 
        !           390:                if (dp = index (ep, '=')) {
        !           391:                    *dp++ = NULL;
        !           392:                    if ((m = name2macro (ep)) == NULL) {
        !           393:                        SLOG (addr_log, LLOG_EXCEPTIONS, NULLCP,
        !           394:                              ("non-existant macro \"%s\"", ep));
        !           395:                        return NULLPA;
        !           396:                    }
        !           397:                    (void) sprintf (ep = buf2, "%s%s", m -> m_value, dp);
        !           398:                }
        !           399: 
        !           400:                {
        !           401:                    register int    k,
        !           402:                                    l,
        !           403:                                    n;
        !           404:                    register struct ts_interim *ts,
        !           405:                                               *tp;
        !           406: 
        !           407:                    tp = NULL, n = 0;
        !           408:                    k = strlen (ep);
        !           409:                    for (ts = ts_interim; ts -> ts_name; ts++)
        !           410:                        if (ts -> ts_value
        !           411:                                && (l = strlen (ts -> ts_value)) <= k
        !           412:                                && l > n
        !           413:                                && strncmp (ep, ts -> ts_value, l) == 0)
        !           414:                            tp = ts, n = l;
        !           415:                    if (tp)
        !           416:                        na -> na_community = tp -> ts_subnet;
        !           417:                    else
        !           418:                                                        /* XXX: what a hack! */
        !           419:                        if (strncmp (ep, "X121+", sizeof "X121+" - 1) == 0)
        !           420:                            na -> na_community = SUBNET_INT_X25;
        !           421:                        else {
        !           422:                            SLOG (addr_log, LLOG_EXCEPTIONS, NULLCP,
        !           423:                                  ("unable to determine community for %s",ep));
        !           424:                            return NULLPA;
        !           425:                        }
        !           426:                }
        !           427: 
        !           428:                if ((ep = index (dp = ep, '+')) == NULL) {
        !           429: missing_seperator: ;
        !           430:                    SLOG (addr_log, LLOG_EXCEPTIONS, NULLCP,
        !           431:                          ("missing network-address seperator: %s", str));
        !           432:                    return NULLPA;
        !           433:                }
        !           434:                *ep++ = NULL;
        !           435:                if (ta -> ta_naddr >= NTADDR) {
        !           436: #ifdef h_addr
        !           437: too_many: ;
        !           438: #endif
        !           439:                    SLOG (addr_log, LLOG_EXCEPTIONS, NULLCP,
        !           440:                          ("too many network addresses starting at position %d: %s",
        !           441:                           dp - buf1 + 1, str));
        !           442:                    return pa;
        !           443:                }
        !           444: 
        !           445:                na -> na_stack = NA_NSAP;
        !           446:                if (lexequ (dp, "NS") == 0) {
        !           447:                    IMPLODE (na -> na_addrlen, na -> na_address, ep,
        !           448:                             strlen (ep));
        !           449:                }
        !           450:                else {
        !           451:                    for (pp = afi_entries; pp -> p_name; pp++)
        !           452:                        if (lexequ (pp -> p_name, dp) == 0)
        !           453:                            break;
        !           454:                    if (!pp -> p_name) {
        !           455:                        SLOG (addr_log, LLOG_EXCEPTIONS, NULLCP,
        !           456:                              ("unknown AFI \"%s\": %s", dp, str));
        !           457:                        return NULLPA;
        !           458:                    }
        !           459:                    if ((ep = index (dp = ep, '+')) == NULL)
        !           460:                        ep = dp + strlen (dp);
        !           461:                    else
        !           462:                        *ep++ = NULL;
        !           463:                    if (lexequ (pp -> p_name, "X121") == 0) {
        !           464:                        /* X121 form -- should be more general */
        !           465:                        (void) strcpy (nsap, dp);
        !           466:                        if ((na -> na_dtelen = strlen (nsap)) > NSAP_DTELEN) {
        !           467:                            dp = nsap;
        !           468:                            goto invalid_dte;
        !           469:                        }
        !           470:                        (void) strcpy (na -> na_dte, nsap);
        !           471: #ifdef BRIDGE_X25
        !           472:                        na -> na_stack = bridgediscrim (na) ? NA_BRG : NA_X25;
        !           473: #else
        !           474:                        na -> na_stack = NA_X25;
        !           475: #endif
        !           476:                        na -> na_community = SUBNET_INT_X25;
        !           477:                        if (*ep != NULL) {
        !           478:                            SLOG (addr_log, LLOG_EXCEPTIONS, NULLCP,
        !           479:                                  ("bad X121 form \"%s\"", ep));
        !           480:                            return NULLPA;
        !           481:                        }
        !           482:                        goto next;
        !           483:                    }
        !           484:                    else
        !           485:                        (void) sprintf (nsap, "%s%s", pp -> p_value, dp);
        !           486:                    switch (*ep) {
        !           487:                        case 'd':
        !           488:                            (void) strcpy (nsap + strlen (nsap), ep + 1);
        !           489:                            /* and fall */
        !           490:                        case 'x':
        !           491:                        case 'l':
        !           492:                        case NULL:
        !           493:                            np = nsap, dp = na -> na_address;
        !           494:                            while (*np) {
        !           495:                                *dp = (*np++ - '0') << 4;
        !           496:                                if (*np)
        !           497:                                    *dp++ |= (*np++ - '0') & 0x0f;
        !           498:                                else
        !           499:                                    *dp++ |= 0x0f;
        !           500:                            }
        !           501:                            na -> na_addrlen = dp - na -> na_address;
        !           502:                            if (*ep == 'x') {
        !           503:                                IMPLODE (j, dp, ep + 1, strlen (ep + 1));
        !           504:                                na -> na_addrlen += j;
        !           505:                            }
        !           506:                            else
        !           507:                                if (*ep == 'l') {
        !           508:                                    (void) strcpy (dp, ep + 1);
        !           509:                                    na -> na_addrlen += strlen (ep + 1);
        !           510:                                }
        !           511:                            break;
        !           512: 
        !           513:                        default:
        !           514:                            if (strncmp ("RFC-1006+", ep,
        !           515:                                         sizeof "RFC-1006+" - 1) == 0) {
        !           516: #ifdef h_addr
        !           517:                                register char **ap;
        !           518: #endif
        !           519:                                register struct hostent *hp;
        !           520: 
        !           521:                                na -> na_stack = NA_TCP;
        !           522: #ifdef notdef
        !           523:                                if (strcmp (nsap, INTERIM_IDP)) {
        !           524: wrong_idp: ;
        !           525:                                    SLOG (addr_log, LLOG_EXCEPTIONS, NULLCP,
        !           526:                                          ("wrong IDP \"%s\" for DSP \"%s\"",
        !           527:                                           nsap, ep));
        !           528:                                    return NULLPA;
        !           529:                                }
        !           530: #endif
        !           531:                                ep += sizeof "RFC-1006+" - 1;
        !           532:                                if ((ep = index (dp = ep, '+')) == NULL)
        !           533:                                    goto missing_seperator;
        !           534:                                *ep++ = NULL;
        !           535: #ifdef notdef
        !           536:                                na -> na_community = atoi (dp);
        !           537: #endif
        !           538:                                if ((ep = index (dp = ep, '+')) == NULL)
        !           539:                                    ep = dp + strlen (dp);
        !           540:                                else
        !           541:                                    *ep++ = NULL;
        !           542: 
        !           543:                                if ((hp = gethostbystring (dp)) == NULL) {
        !           544:                                    SLOG (addr_log, LLOG_EXCEPTIONS, NULLCP,
        !           545:                                          ("%s: unknown host", dp));
        !           546:                                    return NULLPA;
        !           547:                                }
        !           548:                                (void) strcpy (na -> na_domain,
        !           549:                                               inet_ntoa (*(struct in_addr *)
        !           550:                                                                hp -> h_addr));
        !           551:                                if (*ep) {
        !           552:                                    if ((ep = index (dp = ep, '+')) == NULL)
        !           553:                                        ep = dp + strlen (dp);
        !           554:                                    else
        !           555:                                        *ep++ = NULL;
        !           556:                                    na -> na_port = htons ((u_short) atoi(dp));
        !           557: 
        !           558:                                    if (*ep)
        !           559:                                        na -> na_tset = atoi (ep);
        !           560:                                }
        !           561: #ifdef h_addr
        !           562:                                for (ap = hp -> h_addr_list + 1; *ap; ap++) {
        !           563:                                    ta -> ta_naddr++, na++;
        !           564: 
        !           565:                                    if (ta -> ta_naddr >= NTADDR)
        !           566:                                        goto too_many;
        !           567:                                    bcopy ((char *) (na - 1), (char *) na,
        !           568:                                           sizeof *na);
        !           569:                                    (void) strcpy (na -> na_domain,
        !           570:                                          inet_ntoa (*(struct in_addr *) *ap));
        !           571:                                }
        !           572: #endif
        !           573:                                break;
        !           574:                            }
        !           575:                            if (strncmp ("X.25(80)+", ep,
        !           576:                                         sizeof "X.25(80)+" - 1) == 0) {
        !           577:                                na -> na_stack = NA_X25;
        !           578: #ifdef notdef
        !           579:                                if (strcmp (nsap, INTERIM_IDP))
        !           580:                                    goto wrong_idp;
        !           581: #endif
        !           582:                                ep += sizeof "X.25(80)+" - 1;
        !           583:                                if ((ep = index (dp = ep, '+')) == NULL)
        !           584:                                    goto missing_seperator;
        !           585:                                *ep++ = NULL;
        !           586: #ifdef notdef
        !           587:                                na -> na_community = atoi (dp);
        !           588: #endif
        !           589:                                if ((ep = index (dp = ep, '+')) == NULL)
        !           590:                                    ep = dp + strlen (dp);
        !           591:                                else
        !           592:                                    *ep++ = NULL;
        !           593:                                for (np = dp; *np; np++)
        !           594:                                    if (!isdigit (*np)) {
        !           595: invalid_dte: ;
        !           596:                                        SLOG (addr_log, LLOG_EXCEPTIONS,
        !           597:                                              NULLCP,
        !           598:                                              ("invalid DTE \"%s\": %s",
        !           599:                                               dp, str));
        !           600:                                        return NULLPA;
        !           601:                                    }
        !           602:                                if (np - dp > NSAP_DTELEN + 1)
        !           603:                                    goto invalid_dte;
        !           604:                                (void) strcpy (na -> na_dte, dp);
        !           605:                                na -> na_dtelen = strlen (na -> na_dte);
        !           606:                                if (*ep) {
        !           607:                                    char   *cudf,
        !           608:                                           *clen;
        !           609: 
        !           610:                                    if ((ep = index (dp = ep, '+')) == NULL)
        !           611:                                        goto missing_seperator;
        !           612:                                    *ep++ = NULL;
        !           613:                                    
        !           614:                                    if (lexequ (dp, "CUDF") == 0) {
        !           615:                                        cudf = na -> na_cudf;
        !           616:                                        clen = &na -> na_cudflen;
        !           617:                                        j = sizeof na -> na_cudf;
        !           618:                                    }
        !           619:                                    else
        !           620:                                        if (lexequ (dp, "PID") == 0) {
        !           621:                                            cudf = na -> na_pid;
        !           622:                                            clen = &na -> na_pidlen;
        !           623:                                            j = sizeof na -> na_pid;
        !           624:                                        }
        !           625:                                        else {
        !           626: invalid_field: ;
        !           627:                                            SLOG (addr_log, LLOG_EXCEPTIONS,
        !           628:                                                  NULLCP,
        !           629:                                                  ("invalid field \"%s\": %s",
        !           630:                                                   dp, str));
        !           631:                                            return NULLPA;
        !           632:                                        }
        !           633:                                    if (j * 2 < strlen (ep))
        !           634:                                        goto invalid_field;
        !           635:                                    IMPLODE (j, cudf, ep, strlen (ep));
        !           636:                                    *clen = j & 0xff;
        !           637:                                }
        !           638: #ifdef BRIDGE_X25
        !           639:                                na -> na_stack = bridgediscrim (na) ? NA_BRG
        !           640:                                                                   : NA_X25;
        !           641: #endif
        !           642:                                break;
        !           643:                            }
        !           644: #ifdef notdef
        !           645:                            if (lexequ ("ECMA-117-Binary", ep) == 0) {
        !           646:                                /* some day support this... */
        !           647:                                break;
        !           648:                            }
        !           649:                            if (lexequ ("ECMA-117-Decimal", ep) == 0) {
        !           650:                                /* some day support this... */
        !           651:                                break;
        !           652:                            }
        !           653: #endif
        !           654:                            SLOG (addr_log, LLOG_EXCEPTIONS, NULLCP,
        !           655:                                  ("unknown DSP \"%s\": %s", ep, str));
        !           656:                            return NULLPA;
        !           657:                    }
        !           658:                }
        !           659: next: ;
        !           660:                ta -> ta_naddr++, na++;
        !           661:                break;
        !           662:        }
        !           663:     
        !           664:     switch (sp - sels) {
        !           665:         case 3:        /* PSEL+SSEL+TSEL */
        !           666:            bcopy (*--sp, ta -> ta_selector,
        !           667:                   ta -> ta_selectlen = *--lp);
        !           668:            bcopy (*--sp, sa -> sa_selector,
        !           669:                   sa -> sa_selectlen = *--lp);
        !           670:            bcopy (*--sp, pa -> pa_selector,
        !           671:                   pa -> pa_selectlen = *--lp);
        !           672:            break;
        !           673: 
        !           674:        case 2: /* SSEL+TSEL */
        !           675:            bcopy (*--sp, ta -> ta_selector,
        !           676:                   ta -> ta_selectlen = *--lp);
        !           677:            bcopy (*--sp, sa -> sa_selector,
        !           678:                   sa -> sa_selectlen = *--lp);
        !           679:            break;
        !           680: 
        !           681:        case 1: /* TSEL */
        !           682:            bcopy (*--sp, ta -> ta_selector,
        !           683:                   ta -> ta_selectlen = *--lp);
        !           684:            break;
        !           685: 
        !           686:        default:
        !           687:            break;
        !           688:     }
        !           689:     
        !           690:     return pa;
        !           691: }
        !           692: 
        !           693: /*  */
        !           694: 
        !           695: int    macro2comm (name, ts)
        !           696: char   *name;
        !           697: register struct ts_interim *ts;
        !           698: {
        !           699:     int            j;
        !           700:     register char  *ap,
        !           701:                   *cp,
        !           702:                   *dp,
        !           703:                   *ep,
        !           704:                   *fp,
        !           705:                   *np;
        !           706:     char    addr[NASIZE * 2 + 1],
        !           707:            buffer[BUFSIZ];
        !           708:     register struct pair *pp;
        !           709: 
        !           710:     ts -> ts_length = 0, ts -> ts_syntax = NA_NSAP;
        !           711:     if ((cp = macro2str (name)) == NULLCP)
        !           712:        return NOTOK;
        !           713:     ts -> ts_value = cp;
        !           714:     (void) strcpy (buffer, cp);
        !           715:     ap = addr;
        !           716: 
        !           717:     if ((ep = index (dp = buffer, '+')) == NULL)
        !           718:        ep = dp + strlen (dp);
        !           719:     else
        !           720:        *ep++ = NULL;
        !           721: 
        !           722:     if (lexequ (dp, "NS") == 0) {
        !           723:        IMPLODE (ts -> ts_length, ts -> ts_prefix, ep, strlen (ep));
        !           724: 
        !           725:        return OK;
        !           726:     }
        !           727:     
        !           728:     for (pp = afi_entries; pp -> p_name; pp++)
        !           729:        if (lexequ (pp -> p_name, dp) == 0)
        !           730:            break;
        !           731:     if (!pp -> p_name) {
        !           732:        SLOG (addr_log, LLOG_EXCEPTIONS, NULLCP,
        !           733:              ("unknown AFI \"%s\": %s", dp, cp));
        !           734:        return NOTOK;
        !           735:     }
        !           736: 
        !           737:     (void) strcpy (ap, pp -> p_value);
        !           738:     ap += strlen (ap);
        !           739: 
        !           740:     if (!ep)
        !           741:        goto out;
        !           742: 
        !           743:     if ((ep = index (dp = ep, '+')) == NULL)
        !           744:        ep = dp + strlen (dp);
        !           745:     else
        !           746:        *ep++ = NULL;
        !           747: 
        !           748:     for (fp = dp; *fp; fp++)
        !           749:        if (!isdigit (*fp))
        !           750:            break;
        !           751:     if (*fp) {
        !           752:        SLOG (addr_log, LLOG_EXCEPTIONS, NULLCP,
        !           753:              ("invalid AFI suffix \"%s\": %s", dp, cp));
        !           754:        return NOTOK;
        !           755:     }
        !           756:     (void) strcpy (ap, dp);
        !           757:     ap += strlen (ap);
        !           758: 
        !           759:     if (lexequ (pp -> p_name, "X121") == 0) {
        !           760:        if (*ep) {
        !           761:            SLOG (addr_log, LLOG_EXCEPTIONS, NULLCP,
        !           762:                  ("invalid DTE \"%s\": %s", dp, cp));
        !           763:            return NOTOK;
        !           764:        }
        !           765: 
        !           766:        ts -> ts_syntax = NA_X25;
        !           767:        ts -> ts_subnet = SUBNET_INT_X25;
        !           768:        goto out;
        !           769:     }
        !           770: 
        !           771:     switch (*ep) {
        !           772:        case 'd':
        !           773:            (void) strcpy (ap, ep + 1);
        !           774:            /* and fall */
        !           775:        case 'x':
        !           776:        case 'l':
        !           777:        case NULL:
        !           778:            break;
        !           779: 
        !           780:        default:
        !           781:            if ((ep = index (dp = ep, '+')) == NULL)
        !           782:                ep = dp + strlen (dp);
        !           783:            else
        !           784:                *ep++ = NULL;
        !           785:            if (lexequ (dp, "RFC-1006") == 0)
        !           786:                ts -> ts_syntax = NA_TCP;
        !           787:            else
        !           788:                if (lexequ (dp, "X.25(80)") == 0)
        !           789:                    ts -> ts_syntax = NA_X25;
        !           790:                else {
        !           791:                    SLOG (addr_log, LLOG_EXCEPTIONS, NULLCP,
        !           792:                          ("unknown DSP \"%s\": %s", dp, cp));
        !           793:                    return NOTOK;
        !           794:                }
        !           795:            if ((ep = index (dp = ep, '+')) == NULL)
        !           796:                ep = dp + strlen (dp);
        !           797:            else
        !           798:                *ep++ = NULL;
        !           799: 
        !           800:            (void) strcpy (ap, dp);
        !           801:            ap += strlen (ap);
        !           802: 
        !           803:            if (*ep) {
        !           804:                SLOG (addr_log, LLOG_EXCEPTIONS, NULLCP,
        !           805:                      ("invalid MACRO for community \"%s\": %s", name, cp));
        !           806:                return NOTOK;
        !           807:            }
        !           808:            break;
        !           809:     }
        !           810: 
        !           811: out: ;
        !           812:     ap = addr, np = ts -> ts_prefix;
        !           813:     while (*ap) {
        !           814:        *np = (*ap++ - '0') << 4;
        !           815:        if (*ap)
        !           816:            *np++ |= (*ap++ - '0') & 0x0f;
        !           817:        else
        !           818:            *np++ |= 0x0f;
        !           819:     }
        !           820:     switch (*ep) {
        !           821:        case 'x':
        !           822:            IMPLODE (j, np, ep + 1, strlen (ep + 1));
        !           823:            np += j;
        !           824:            break;
        !           825: 
        !           826:        case 'l':
        !           827:            (void) strcpy (np, ep + 1);
        !           828:            np += strlen (ep + 1);
        !           829:            break;
        !           830: 
        !           831:        default:
        !           832:            break;
        !           833:     }
        !           834:     ts -> ts_length = np - ts -> ts_prefix;
        !           835: 
        !           836:     return OK;
        !           837: }
        !           838: 
        !           839: /*    PADDR2STR */
        !           840: 
        !           841: static char   *SEL2STR (sel, len)
        !           842: char   *sel;
        !           843: int    len;
        !           844: {
        !           845:     register char  *cp,
        !           846:                   *dp,
        !           847:                   *ep;
        !           848:     static char buffer[PSSIZE * 2 + 4];
        !           849: 
        !           850:     if (len <= 0)
        !           851:        return "";
        !           852: 
        !           853:     cp = buffer;
        !           854:     *cp++ = '"';
        !           855:     for (ep = (dp = sel) + len; dp < ep; dp++) {
        !           856:        switch (*dp) {
        !           857:            case '+':
        !           858:            case '-':
        !           859:            case '.':
        !           860:                break;
        !           861: 
        !           862:            default:
        !           863:                if (!isalnum (*dp)) {
        !           864:                    cp = buffer;
        !           865:                    *cp++ = '\'';
        !           866:                    cp += explode (cp, (u_char *) sel, len);
        !           867:                    (void) strcpy (cp, "'H");
        !           868:                    return buffer;
        !           869:                }               
        !           870:                break;
        !           871:        }
        !           872: 
        !           873:        *cp++ = *dp;
        !           874:     }
        !           875:     *cp++ = '"';
        !           876:     *cp = NULL;
        !           877: 
        !           878:     return buffer;
        !           879: }
        !           880: 
        !           881: /*  */
        !           882: 
        !           883: char    *_paddr2str (pa, na, compact)
        !           884: register struct PSAPaddr *pa;
        !           885: register struct NSAPaddr *na;
        !           886: int    compact;
        !           887: {
        !           888:     register int   n;
        !           889:     int            first;
        !           890:     register char *bp,
        !           891:                  *cp,
        !           892:                  *dp;
        !           893:     register struct macro *m;
        !           894:     register struct SSAPaddr *sa;
        !           895:     register struct TSAPaddr *ta;
        !           896:     register struct NSAPaddr *ca;
        !           897:     static int    i = 0;
        !           898:     static char buf1[BUFSIZ],
        !           899:                buf2[BUFSIZ];
        !           900:     static char *bufs[] = { buf1, buf2 };
        !           901: 
        !           902:     bp = cp = bufs[i++];
        !           903:     i = i % 2;
        !           904: 
        !           905:     if (pa == NULLPA) {
        !           906: bad_pa: ;
        !           907:        (void) strcpy (bp, "NULLPA");
        !           908:        return bp;
        !           909:     }
        !           910:     sa = &pa -> pa_addr;
        !           911:     ta = &sa -> sa_addr;
        !           912: 
        !           913:     if (na)
        !           914:        n = 1;
        !           915:     else
        !           916:        if ((n = ta -> ta_naddr) > 0)
        !           917:            na = ta -> ta_addrs;
        !           918: 
        !           919:     if (pa -> pa_selectlen > 0) {
        !           920:        (void) sprintf (cp, "%s/",
        !           921:                        SEL2STR (pa -> pa_selector, pa -> pa_selectlen));
        !           922:        cp += strlen (cp);
        !           923:     }
        !           924:     if (sa -> sa_selectlen > 0 || bp != cp) {
        !           925:        (void) sprintf (cp, "%s/",
        !           926:                        SEL2STR (sa -> sa_selector, sa -> sa_selectlen));
        !           927:        cp += strlen (cp);
        !           928:     }
        !           929:     if (ta -> ta_selectlen > 0 || bp != cp) {
        !           930:        (void) sprintf (cp, "%s/",
        !           931:                        SEL2STR (ta -> ta_selector, ta -> ta_selectlen));
        !           932:        cp += strlen (cp);
        !           933:     }
        !           934: 
        !           935:     for (first = 1; n > 0; na++, n--) {
        !           936:        register struct ts_interim *ts;
        !           937: 
        !           938:        if (first)
        !           939:            first = 0;
        !           940:        else
        !           941:            *cp++ = '|';
        !           942: 
        !           943:        if (compact > 0) {
        !           944:            if ((ca = na2norm (na)) == NULLNA)
        !           945:                goto bad_pa;
        !           946: 
        !           947:            (void) strcpy (cp, "NS+");
        !           948:            cp += strlen (cp);
        !           949: 
        !           950:            cp += explode (cp, (u_char *) ca -> na_address, ca -> na_addrlen);
        !           951:            *cp = NULL;
        !           952:            continue;
        !           953:        }
        !           954:        
        !           955:        for (ts = ts_interim; ts -> ts_name; ts++)
        !           956:            if (ts -> ts_subnet == na -> na_community)
        !           957:                break;
        !           958:        if (!ts -> ts_name) {
        !           959:            SLOG (addr_log, LLOG_EXCEPTIONS, NULLCP,
        !           960:                  ("unable to find community #%d", na -> na_community));
        !           961:            goto bad_pa;
        !           962:        }
        !           963:        if (!ts -> ts_value) {
        !           964:            SLOG (addr_log, LLOG_EXCEPTIONS, NULLCP,
        !           965:                  ("community \"%s\" (subnet #%d) has no corresponding MACRO",
        !           966:                   ts -> ts_name, na -> na_community));
        !           967:            goto bad_pa;
        !           968:        }
        !           969:        (void) strcpy (dp = cp, ts -> ts_value);
        !           970:        cp += strlen (cp) - 1;
        !           971:        if (*cp != '+')
        !           972:            *++cp = '+', *++cp = NULL;
        !           973:        else
        !           974:            cp++;
        !           975: 
        !           976:        switch (na -> na_stack) {
        !           977:            case NA_NSAP:
        !           978:                (void) strcpy (cp = dp, "NS+");
        !           979:                cp += strlen (cp);
        !           980: 
        !           981:                cp += explode (cp, (u_char *) na -> na_address, na -> na_addrlen);
        !           982:                *cp = NULL;
        !           983:                break;
        !           984: 
        !           985:            case NA_TCP:
        !           986:                (void) strcpy (cp, na -> na_domain);
        !           987:                cp += strlen (cp);
        !           988:                if (na -> na_port) {
        !           989:                    (void) sprintf (cp, "+%d", (int) ntohs (na -> na_port));
        !           990:                    cp += strlen (cp);
        !           991: 
        !           992:                    if (na -> na_tset) {
        !           993:                        (void) sprintf (cp, "+%d", (int) na -> na_tset);
        !           994:                        cp += strlen (cp);
        !           995:                    }
        !           996:                }
        !           997:                break;
        !           998: 
        !           999:            case NA_X25:
        !          1000:            case NA_BRG:
        !          1001:                if (na -> na_community == SUBNET_INT_X25
        !          1002:                        && na -> na_cudflen == 0
        !          1003:                        && na -> na_pidlen == 0
        !          1004:                        && na -> na_dte[0] != '0') {
        !          1005:                    (void) sprintf (cp = dp, "X121+%s", na -> na_dte);
        !          1006:                    cp += strlen (cp);
        !          1007:                }
        !          1008:                else {
        !          1009:                    (void) strcpy (cp, na -> na_dte);
        !          1010:                    cp += strlen (cp);
        !          1011:                    if (na -> na_pidlen > 0) {
        !          1012:                        (void) strcpy (cp, "+PID+");
        !          1013:                        cp += strlen (cp);
        !          1014: 
        !          1015:                        cp += explode (cp, (u_char *) na -> na_pid,
        !          1016:                                       (int) na -> na_pidlen);
        !          1017:                    }
        !          1018:                    else
        !          1019:                        if (na -> na_cudflen > 0) {
        !          1020:                            (void) strcpy (cp, "+CUDF+");
        !          1021:                            cp += strlen (cp);
        !          1022: 
        !          1023:                            cp += explode (cp, (u_char *) na -> na_cudf,
        !          1024:                                           (int) na -> na_cudflen);
        !          1025:                        }
        !          1026:                    *cp = NULL;
        !          1027:                }
        !          1028:                break;
        !          1029: 
        !          1030:            default:
        !          1031:                SLOG (addr_log, LLOG_EXCEPTIONS, NULLCP,
        !          1032:                      ("unknown address type 0x%x", na -> na_stack));
        !          1033:                goto bad_pa;
        !          1034:        }
        !          1035: 
        !          1036:        SLOG (addr_log, LLOG_DEBUG, NULLCP, ("dp = %s",dp));
        !          1037: 
        !          1038:        if (!compact && (m = value2macro (dp))) {
        !          1039:            char    buffer[BUFSIZ];
        !          1040: 
        !          1041:            (void) sprintf (buffer, "%s=%s", m -> m_name,
        !          1042:                            dp + strlen (m -> m_value));
        !          1043:            (void) strcpy (dp, buffer);
        !          1044:            cp = dp + strlen (dp);
        !          1045:        }
        !          1046:     }
        !          1047:     *cp = NULL;
        !          1048: 
        !          1049:     return bp;
        !          1050: }

unix.superglobalmegacorp.com

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