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 d

⟦0bb819aa8⟧ TextFile

    Length: 6692 (0x1a24)
    Types: TextFile
    Names: »dse2psap.c«

Derivation

└─⟦2d1937cfd⟧ Bits:30007241 EUUGD22: P.P 5.0
    └─⟦041b9c0f8⟧ »EurOpenD22/isode/pepsy.system-6.0.Z« 
        └─⟦d49939f05⟧ 
            └─⟦6a28ec38e⟧ »pepsy.tar« 
                └─⟦this⟧ »acsap/dse2psap.c« 

TextFile

/* Copyright 1989 CSIRO Division of Information Technology 
 * May be given away but not sold for profit - See Copyright file for details
 */
/*
 * Routine to convert a type_DSE_PSAPaddr structure into PSAPaddr structure
 * which pepsy generated decoder accepts
 */
#include <stdio.h>
#include "psap.h"
#include "isoaddrs.h"
#include "tailor.h"
#include "DSE-types.h"

#define advise	PY_advise

#define	new(x)		(x *) malloc(sizeof (x))

#define	getstr(ss,sl,ds,dl,dn,w) \
	if (sl > dn) { \
	    advise (NULLCP, "%s too long", w); \
	    return NOTOK; \
	} \
	bcopy (ss, ds, dl = sl);


struct PSAPaddr	*
dse2psap(dse)
struct type_DSE_PSAPaddr *dse;
{
    struct PSAPaddr	*psap;
    struct member_DSE_0 *nDSE;
    struct SSAPaddr *sa;
    struct TSAPaddr *ta;
    char	*p;

    if ((psap = new(struct PSAPaddr)) == NULL) {
	return (NULL);
    }
    bzero(psap, sizeof (struct PSAPaddr));

    sa = &psap -> pa_addr;
    ta = &sa -> sa_addr;

    psap->pa_selectlen = gstring(psap->pa_selector, sizeof (psap->pa_selector),
	dse->pSelector, "psap selector");

    sa->sa_selectlen = gstring(sa->sa_selector, sizeof (sa->sa_selector),
	dse->sSelector, "ssap selector");

    ta->ta_selectlen  = gstring(ta->ta_selector, sizeof (ta->ta_selector),
	dse->tSelector, "tsap selector");

    for (nDSE  = dse->nAddress; nDSE != NULL; nDSE = nDSE->next) {
	if (ta -> ta_naddr >= NTADDR) {
	    advise (NULLCP, "too many network addresses");
	    return (NULL);
	}
	p = qb2str(nDSE->member_DSE_1);
	str2nsap(p, nDSE->member_DSE_1->qb_len, &ta->ta_addrs[ta->ta_naddr++]);

    }

    return (psap);


}
static int
gstring(buf, buflen, qb, mesg)
char	buf[];
int	buflen;
struct qbuf	*qb;
char	*mesg;
{
    char *p;

    if (qb->qb_len > buflen) {
	advise(NULLCP, "%s too long", mesg);
	return (NULL);
    }
    p = qb2str(qb);
    bcopy(p, buf, qb->qb_len);

    return (qb->qb_len);
}

str2nsap(p, len, na)
char	*p;
int	len;
struct NSAPaddr *na;
{

#define	x(a,b)	((char) (((a) << 4) | b))
    static char interim_idp[] = {
	x (5, 4), x (0, 0), x (7, 2), x (8, 7), x (2, 2)
    };
#undef	x

    na -> na_type = NA_NSAP;

    if ((len == 8) && ((p[0] == 0x36) || (p[0] == 0x37))) {
	int	xlen;			/* SEK - X121 form */
	register char   *cp,
			*cp2,
			*dp;
	char	nsap[14];

	dp = nsap;
	for (cp2 = (cp = p + 1) + 7; cp < cp2; cp++) {
	    register int     j;

	    if ((j = ((*cp & 0xf0) >> 4)) > 9)
		goto concrete;
	    *dp++ = j + '0';

	    if ((j = (*cp & 0x0f)) > 9) {
		if (j != 0x0f)
		    goto concrete;
	    }
	    else
		*dp++ = j + '0';
	}

	for (cp = nsap, xlen = 14; *cp == '0'; cp++, xlen--)
	    continue;
	na -> na_dtelen = xlen;
	for (cp2 = na -> na_dte; xlen-- > 0; )
		*cp2++ = *cp++;
	*cp2 = NULL;
#ifdef	BRIDGE_X25
	na -> na_type = bridgediscrim (na) ? NA_BRG : NA_X25;
#else
	na -> na_type = NA_X25;
#endif
	na -> na_subnet = SUBNET_INT_X25;

    } else if (len > sizeof interim_idp
		&& bcmp (p, interim_idp, sizeof interim_idp) == 0) {
	int	    i,
		ilen,
		rlen;
	register char   *cp,
			*dp,
			*ep;
	char    nsap[NASIZE * 2 + 1];

	dp = nsap;
	for (cp = p + sizeof interim_idp, ep = p + len;
		 cp < ep;
		 cp++) {
	    register int     j;

	    if ((j = ((*cp & 0xf0) >> 4)) > 9) {
concrete: ;
		LLOG (addr_log, LLOG_EXCEPTIONS,
		      ("invalid concrete encoding"));
		goto realNS;
	    }
	    *dp++ = j + '0';

	    if ((j = (*cp & 0x0f)) > 9) {
		if (j != 0x0f)
		    goto concrete;
	    }
	    else
		*dp++ = j + '0';
	}
	*dp = NULL;

	cp = nsap;
	if (strlen (cp) < 2) {
	    LLOG (addr_log, LLOG_EXCEPTIONS,
		  ("missing DSP prefix"));
	    goto realNS;
	}

	(void) sscanf (cp, "%2d", &i);
	cp += 2;
	switch (na -> na_subnet = i) {
	    case SUBNET_INT_X25:
	    case SUBNET_JANET:
		if (strlen (cp) < 1) {
		    LLOG (addr_log, LLOG_EXCEPTIONS,
			  ("missing DTE+CUDF indicator: %s",
			   nsap));
		    goto realNS;
		}
		(void) sscanf (cp, "%1d", &i);
		cp += 1;
		switch (i) {
		    case 0:	/* DTE only */
			break;

		    case 1:	/* DTE+PID */
		    case 2:	/* DTE+CUDF */
			if (strlen (cp) < 1) {
			    LLOG (addr_log, LLOG_EXCEPTIONS,
				  ("missing DTE+CUDF indicator: %s",
				   nsap));
			    goto realNS;
			}
			(void) sscanf (cp, "%1d", &ilen);
			cp += 1;
			rlen = ilen * 3;
			if (strlen (cp) < rlen) {
			    LLOG (addr_log, LLOG_EXCEPTIONS,
				  ("bad DTE+CUDF length: %s",
				   nsap));
			    goto realNS;
			}
			if (i == 1) {
			    if (ilen > NPSIZE) {
				LLOG (addr_log,
				      LLOG_EXCEPTIONS,
				      ("PID too long: %s",
				       nsap));
				goto realNS;
			    }
			    dp = na -> na_pid;
			    na -> na_pidlen = ilen;
			}
			else {
			    if (ilen > CUDFSIZE) {
				LLOG (addr_log,
				      LLOG_EXCEPTIONS,
				      ("CUDF too long: %s",
				       nsap));
				goto realNS;
			    }
			    dp = na -> na_cudf;
			    na -> na_cudflen = ilen;
			}
			for (; rlen > 0; rlen -= 3) {
			    (void) sscanf (cp, "%3d", &i);
			    cp += 3;

			    if (i > 255) {
				LLOG (addr_log,
				      LLOG_EXCEPTIONS,
				      ("invalid PID/CUDF: %s",
				       nsap));
				goto realNS;
			    }
			    *dp++ = i & 0xff;
			}
			break;

		    default:
			LLOG (addr_log, LLOG_EXCEPTIONS,
			      ("invalid DTE+CUDF indicator: %s",
			       nsap));
			goto realNS;
		    }
		(void) strcpy (na -> na_dte, cp);
		na -> na_dtelen = strlen (na -> na_dte);

#ifdef	BRIDGE_X25
		na -> na_type = bridgediscrim (na) ? NA_BRG
						   : NA_X25;
#else
		na -> na_type = NA_X25;
#endif
		break;

	    case SUBNET_INTERNET:
		if (strlen (cp) < 12) {
		    LLOG (addr_log, LLOG_EXCEPTIONS,
			  ("missing IP address: %s", nsap));
		    goto realNS;
		}
		{
		    int	    q[4];

		    (void) sscanf (cp, "%3d%3d%3d%3d", q,
				   q + 1, q + 2, q + 3);
		    (void) sprintf (na -> na_domain,
				    "%d.%d.%d.%d",
				    q[0], q[1], q[2], q[3]);
		}
		cp += 12;

		if (*cp) {
		    if (strlen (cp) < 5) {
			LLOG (addr_log, LLOG_EXCEPTIONS,
			      ("missing port: %s", nsap));
			goto realNS;
		    }
		    (void) sscanf (cp, "%5d", &i);
		    cp += 5;
		    na -> na_port = htons ((u_short) i);

		    if (*cp) {
			if (strlen (cp) < 5) {
			    LLOG (addr_log, LLOG_EXCEPTIONS,
				  ("missing tset: %s", nsap));
			    goto realNS;
			}
			(void) sscanf (cp, "%5d", &i);
			cp += 5;
			na -> na_tset = (u_short) i;

			if (*cp)
			    LLOG (addr_log, LLOG_EXCEPTIONS,
				  ("extra TCP information: %s",
				   nsap));
		    }
		}

		na -> na_type = NA_TCP;
		break;

	    default:
		LLOG (addr_log, LLOG_EXCEPTIONS,
		      ("unknown DSP prefix for interim IDP: %s",
		       nsap));
		goto realNS;
	    }
    } else {
    realNS: ;
	getstr (p, len, na -> na_address, na -> na_addrlen,
	    sizeof na -> na_address, "NSAP address");
    }
}