DataMuseum.dk

Presents historical artifacts from the history of:

DKUUG/EUUG Conference tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about DKUUG/EUUG Conference tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - metrics - download
Index: T n

⟦142a9ad6f⟧ TextFile

    Length: 3153 (0xc51)
    Types: TextFile
    Names: »na2norm.c«

Derivation

└─⟦3d0c2be1b⟧ Bits:30001254 ISODE-5.0 Tape
    └─⟦eba4602b1⟧ »./isode-5.0.tar.Z« 
        └─⟦d3ac74d73⟧ 
            └─⟦this⟧ »isode-5.0/compat/na2norm.c« 

TextFile

/* na2norm.c - normalize NSAPaddr */

#ifndef	lint
static char *rcsid = "$Header: /f/osi/compat/RCS/na2norm.c,v 6.0 89/03/18 23:25:25 mrose Rel $";
#endif

/* 
 * $Header: /f/osi/compat/RCS/na2norm.c,v 6.0 89/03/18 23:25:25 mrose Rel $
 *
 *
 * $Log:	na2norm.c,v $
 * Revision 6.0  89/03/18  23:25:25  mrose
 * Release 5.0
 * 
 */

/*
 *				  NOTICE
 *
 *    Acquisition, use, and distribution of this module and related
 *    materials are subject to the restrictions of a license agreement.
 *    Consult the Preface in the User's Manual for the full terms of
 *    this agreement.
 *
 */


/* LINTLIBRARY */

#include <stdio.h>
#include "general.h"
#include "manifest.h"
#include "isoaddrs.h"
#include "internet.h"
#include "tailor.h"

/* \f

 */

struct NSAPaddr *na2norm (na)
register struct NSAPaddr *na;
{
    int	    ilen;
    register char  *cp,
		   *dp;
    char    nsap[NASIZE * 2 + 1];
    register struct hostent *hp;
    static struct NSAPaddr nas;
    register struct NSAPaddr *ca = &nas;

    if (na -> na_type == NA_NSAP) {
	*ca = *na;	/* struct copy */
	return ca;
    }

    (void) strcpy (cp = nsap, INTERIM_IDP);
    cp += strlen (cp);

    bzero ((char *) ca, sizeof *ca);
    ca -> na_type = NA_NSAP;

    switch (na -> na_type) {
	case NA_TCP:
	    if ((hp = gethostbystring (na -> na_domain)) == NULL) {
		SLOG (addr_log, LLOG_EXCEPTIONS, NULLCP,
		      ("%s: unknown host", na -> na_domain));
		return NULLNA;
	    }
#define	s2a(b)	(((int) (b)) & 0xff)
	    (void) sprintf (cp, "%02d%03d%03d%03d%03d",
			    na -> na_subnet ? na -> na_subnet :SUBNET_INTERNET,
			    s2a (hp -> h_addr[0]),
			    s2a (hp -> h_addr[1]),
			    s2a (hp -> h_addr[2]),
			    s2a (hp -> h_addr[3]));
	    cp += strlen (cp);
#undef	s2a

	    if (na -> na_port) {
		(void) sprintf (cp, "%05d", (int) ntohs (na -> na_port));
		cp += strlen (cp);

		if (na -> na_tset || na -> na_tset != NA_TSET_TCP) {
		    (void) sprintf (cp, "%05d", (int) na -> na_tset);
		    cp += strlen (cp);
		}
	    }
	    break;

	case NA_X25:
	case NA_BRG:
	    if (na -> na_cudflen == 0
		    && na -> na_pidlen == 0
		    && na -> na_dte[0] != '0') {	/* SEK - X121 form */
						/* should be more general */
		(void) sprintf (nsap, "36%014s", na -> na_dte);
		break;
   	    }

	    (void) sprintf (cp, "%02d",
			    na -> na_subnet ? na -> na_subnet
					    : SUBNET_INTL_X25);
	    cp += strlen (cp);
	    if (ilen = na -> na_pidlen & 0xff)
		*cp++ = '1', dp = na -> na_pid;
	    else
		if (ilen = na -> na_cudflen & 0xff)
		    *cp++ = '2', dp = na -> na_cudf;
		else
		    *cp++ = '0';
	    if (ilen) {
		(void) sprintf (cp, "%01d", ilen);
		cp += strlen (cp);

		for (; ilen-- > 0; cp += 3)
		    (void) sprintf (cp, "%03d", *dp++ & 0xff);
	    }
	    (void) strcpy (cp, na -> na_dte);
	    break;

	default:
	    SLOG (addr_log, LLOG_EXCEPTIONS, NULLCP,
		  ("unknown address type 0x%x", na -> na_type));
	    return NULLNA;
    }

    cp = nsap, dp = ca -> na_address;
    while (*cp) {
	*dp = (*cp++ - '0') << 4;
	if (*cp)
	    *dp++ |= (*cp++ - '0') & 0x0f;
	else
	    *dp++ |= 0x0f;
    }
    ca -> na_addrlen = dp - ca -> na_address;

    return ca;    
}