2 Proprietary Rand Corporation
, 1981.
3 Further distribution of
this software
4 subject to the terms of the Rand
11 #include "../adrparse.h"
13 extern char *strcpy(), *strncpy();
16 #define HOSTTBL "/dev/null"
22 char *malloc(), *calloc(), *getncpy();
30 static char name
[256];
31 static char *getaddrs
;
37 while(*getaddrs
&& isspace(*getaddrs
))
43 while(*getaddrs
&& *getaddrs
!= ',') {
44 if(isspace(*getaddrs
))
50 if(*getaddrs
) getaddrs
++;
52 while(isspace(tp
[-1]) && tp
> name
)
55 while(*tp
== ' ' || *tp
== '\t')
64 getm(str
, defaulthost
) /* WHY isn't it just taken from HOSTNAME?*/
65 /* Answer: REPLY uses foreign site */
70 register char *mbp
= 0, *mbe
= 0;
71 register char *hp
= 0, *he
= 0;
72 register struct mailname
*mp
;
77 mp
= (struct mailname
*) calloc(1, sizeof *mp
);
79 mp
->m_text
= cp
= getcpy(str
);
87 } while(*cp
&& *cp
!= '"');
91 mbp
= mbe
= hp
= he
= mp
->m_at
= 0;
96 fprintf(stderr
, "adrparse: extraneous '>'\n");
100 fprintf(stderr
, "adrparse: Missing host within <> spec.\n");
105 case ' ': if(!HOSTNUM
) break;
106 if(strncmp(cp
, " at ", 4) == 0 ||
107 strncmp(cp
, " At ", 4) == 0 ||
108 strncmp(cp
, " AT ", 4) == 0) {
110 at
: if (!HOSTNUM
)break; /* Host 0 means no arpanet */
112 fprintf(stderr
, "adrparse: at without mbox\n");
118 if (*mp
->m_at
== '!')
119 mbp
= hp
; /* uusite!person@site */
121 mbe
= cp
- 1; /* [x!]y@q@z */
131 case '!': /* uusite!otherstuff */
132 if (!mbp
&& !hp
) break; /* Ignore leading '!'s */
133 if(mbp
&& !hp
) { /* No other '!'s so far...*/
134 hp
=mbp
; /* Host name */
146 while(*cp
&& *cp
!= ')') cp
++;
149 if(isalnum(*cp
) || *cp
== '-' || *cp
== '.' ||
153 else if(mp
->m_at
&& !hp
)
156 fprintf(stderr
, "adrparse: address err: %s\n", cp
);
170 fprintf(stderr
, "adrparse: HUH? host wo @\n");
174 if(defaulthost
== 0) {
175 fprintf(stderr
, "adrparse: Missing host\n");
178 mp
->m_host
= getcpy(defaulthost
);
180 while(*he
== ' ') --he
;
181 mp
->m_host
= getncpy(hp
, he
-hp
+1);
184 if (*mp
->m_at
== '!') /* It's a uucp addr, not arpa */
185 mp
->m_nohost
++; /* So formatter will glue on local name*/
188 fprintf(stderr
, "adrparse: No mailbox: %s\n", str
);
191 while(*mbe
== ' ') --mbe
;
192 mp
->m_mbox
= getncpy(mbp
, mbe
-mbp
+1);
193 if (*mp
->m_at
== '!') /* Going out over UUCP */
195 mp
->m_hnum
= -1; /* UUCP addresses are basically local*/
202 if((mp
->m_hnum
= gethnum(mp
->m_host
)) == -1) {
203 fprintf(stderr
, "adrparse: Unknown host: %s\n", mp
->m_host
);
205 line
: fprintf(stderr
, "adrparse: In address: %s\n", str
);
209 if(mp
->m_at
&& (mp
->m_hnum
== HOSTNUM
))
210 /* Local! Try to reparse in case of UUCP address */
214 strcpy(localname
, mp
->m_mbox
); /* not same struct */
216 if((mp
= getm(localname
,HOSTNAME
)) == 0) /* Really local */
231 cp
= calloc(1, (unsigned)len
+ 1);
232 strncpy(cp
, str
, len
);
240 register struct hosts
*hp
= &hosts
;
241 char buf
[32], hostname
[16];
244 if((ht
= fopen(HOSTTBL
, "r")) == NULL
) {
245 hte
: perror(HOSTTBL
);
248 while(fgets(buf
, sizeof buf
, ht
)) {
249 if(sscanf(buf
, "%o %s", &hn
, hostname
) != 2)
251 hp
->nh_next
= (struct hosts
*) calloc(1, sizeof *hp
);
253 hp
->nh_name
= getcpy(hostname
);
263 register struct hosts
*hp
;
265 for (hp
= hosts
.nh_next
; hp
; hp
= hp
->nh_next
)
266 if(uleq(host
, hp
->nh_name
))
273 register struct mailname
*mn
;
278 cndfree(mn
->m_headali
);
283 /* Eventually we should do something more like this (from tn.c) */
284 if ((hnum
>>24) == 0) { /* Old format */
285 netparm
.no_imp
= hnum
&077;
286 netparm
.no_host
= hnum
>>6;
288 else { /* New format */
289 netparm
.no_imp
= hnum
&0177777;
290 netparm
.no_host
= hnum
>>16;