|
|
1.1 root 1: /* na2norm.c - normalize NSAPaddr */
2:
3: #ifndef lint
4: static char *rcsid = "$Header: /f/osi/compat/RCS/na2norm.c,v 7.1 90/07/09 14:32:04 mrose Exp $";
5: #endif
6:
7: /*
8: * $Header: /f/osi/compat/RCS/na2norm.c,v 7.1 90/07/09 14:32:04 mrose Exp $
9: *
10: *
11: * $Log: na2norm.c,v $
12: * Revision 7.1 90/07/09 14:32:04 mrose
13: * sync
14: *
15: * Revision 7.0 89/11/23 21:23:18 mrose
16: * Release 6.0
17: *
18: */
19:
20: /*
21: * NOTICE
22: *
23: * Acquisition, use, and distribution of this module and related
24: * materials are subject to the restrictions of a license agreement.
25: * Consult the Preface in the User's Manual for the full terms of
26: * this agreement.
27: *
28: */
29:
30:
31: /* LINTLIBRARY */
32:
33: #include <stdio.h>
34: #include "general.h"
35: #include "manifest.h"
36: #include "isoaddrs.h"
37: #include "internet.h"
38: #include "tailor.h"
39:
40: /* */
41:
42: struct NSAPaddr *na2norm (na)
43: register struct NSAPaddr *na;
44: {
45: int ilen;
46: register char *cp,
47: *dp;
48: char nsap[NASIZE * 2 + 1];
49: register struct hostent *hp;
50: register struct ts_interim *ts;
51: static struct NSAPaddr nas;
52: register struct NSAPaddr *ca = &nas;
53:
54: if (na -> na_stack == NA_NSAP) {
55: *ca = *na; /* struct copy */
56: return ca;
57: }
58:
59: bzero ((char *) ca, sizeof *ca);
60: ca -> na_stack = NA_NSAP;
61:
62: for (ts = ts_interim; ts -> ts_name; ts++)
63: if (ts -> ts_subnet == na -> na_community)
64: break;
65: if (!ts -> ts_name) {
66: SLOG (addr_log, LLOG_EXCEPTIONS, NULLCP,
67: ("unable to find community #%d", na -> na_community));
68: return NULLNA;
69: }
70:
71: cp = nsap;
72: switch (na -> na_stack) {
73: case NA_TCP:
74: if ((hp = gethostbystring (na -> na_domain)) == NULL) {
75: SLOG (addr_log, LLOG_EXCEPTIONS, NULLCP,
76: ("%s: unknown host", na -> na_domain));
77: return NULLNA;
78: }
79: #define s2a(b) (((int) (b)) & 0xff)
80: (void) sprintf (cp, "%03d%03d%03d%03d",
81: s2a (hp -> h_addr[0]),
82: s2a (hp -> h_addr[1]),
83: s2a (hp -> h_addr[2]),
84: s2a (hp -> h_addr[3]));
85: cp += strlen (cp);
86: #undef s2a
87:
88: if (na -> na_port) {
89: (void) sprintf (cp, "%05d", (int) ntohs (na -> na_port));
90: cp += strlen (cp);
91:
92: if (na -> na_tset || na -> na_tset != NA_TSET_TCP) {
93: (void) sprintf (cp, "%05d", (int) na -> na_tset);
94: cp += strlen (cp);
95: }
96: }
97: break;
98:
99: case NA_X25:
100: case NA_BRG:
101: if (na -> na_community == SUBNET_INT_X25
102: && na -> na_cudflen == 0
103: && na -> na_pidlen == 0
104: && na -> na_dte[0] != '0') { /* SEK - X121 form */
105: /* should be more general */
106: (void) sprintf (nsap, "36%014s", na -> na_dte);
107: ts = NULL;
108: break;
109: }
110:
111: if (ilen = na -> na_pidlen & 0xff)
112: *cp++ = '1', dp = na -> na_pid;
113: else
114: if (ilen = na -> na_cudflen & 0xff)
115: *cp++ = '2', dp = na -> na_cudf;
116: else
117: *cp++ = '0';
118: if (ilen) {
119: (void) sprintf (cp, "%01d", ilen);
120: cp += strlen (cp);
121:
122: for (; ilen-- > 0; cp += 3)
123: (void) sprintf (cp, "%03d", *dp++ & 0xff);
124: }
125: (void) strcpy (cp, na -> na_dte);
126: break;
127:
128: default:
129: SLOG (addr_log, LLOG_EXCEPTIONS, NULLCP,
130: ("unknown address type 0x%x", na -> na_stack));
131: return NULLNA;
132: }
133:
134: cp = nsap, dp = ca -> na_address;
135: if (ts) {
136: bcopy (ts -> ts_prefix, dp, ts -> ts_length);
137: dp += ts -> ts_length;
138: }
139: while (*cp) {
140: *dp = (*cp++ - '0') << 4;
141: if (*cp)
142: *dp++ |= (*cp++ - '0') & 0x0f;
143: else
144: *dp++ |= 0x0f;
145: }
146: ca -> na_addrlen = dp - ca -> na_address;
147:
148: return ca;
149: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.