summaryrefslogtreecommitdiff
path: root/do/ghent
blob: db4a570c7347076d483784499eea0d8d12045065 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
int
do_ghent(which,gimme,arglast)
int which;
int gimme;
int *arglast;
{
    register ARRAY *ary = stack;
    register int sp = arglast[0];
    register char **elem;
    register STR *TARG;
    struct hostent *gethostbyname();
    struct hostent *gethostbyaddr();
#ifdef HAS_GETHOSTENT
    struct hostent *gethostent();
#endif
    struct hostent *hent;
    unsigned long len;

    if (which == O_GHBYNAME) {
	char *name = str_get(ary->ary_array[sp+1]);

	hent = gethostbyname(name);
    }
    else if (which == O_GHBYADDR) {
	STR *addrstr = ary->ary_array[sp+1];
	int addrtype = (int)str_gnum(ary->ary_array[sp+2]);
	char *addr = str_get(addrstr);

	hent = gethostbyaddr(addr,addrstr->str_cur,addrtype);
    }
    else
#ifdef HAS_GETHOSTENT
	hent = gethostent();
#else
	fatal("gethostent not implemented");
#endif

#ifdef HOST_NOT_FOUND
    if (!hent)
	statusvalue = (unsigned short)h_errno & 0xffff;
#endif

    if (gimme != G_ARRAY) {
	astore(ary, ++sp, TARG = str_mortal(&str_undef));
	if (hent) {
	    if (which == O_GHBYNAME) {
#ifdef h_addr
		str_nset(TARG, *hent->h_addr, hent->h_length);
#else
		str_nset(TARG, hent->h_addr, hent->h_length);
#endif
	    }
	    else
		str_set(TARG, hent->h_name);
	}
	return sp;
    }

    if (hent) {
#ifndef lint
	(void)astore(ary, ++sp, TARG = str_mortal(&str_no));
	str_set(TARG, hent->h_name);
	(void)astore(ary, ++sp, TARG = str_mortal(&str_no));
	for (elem = hent->h_aliases; *elem; elem++) {
	    str_cat(TARG, *elem);
	    if (elem[1])
		str_ncat(TARG," ",1);
	}
	(void)astore(ary, ++sp, TARG = str_mortal(&str_no));
	str_numset(TARG, (double)hent->h_addrtype);
	(void)astore(ary, ++sp, TARG = str_mortal(&str_no));
	len = hent->h_length;
	str_numset(TARG, (double)len);
#ifdef h_addr
	for (elem = hent->h_addr_list; *elem; elem++) {
	    (void)astore(ary, ++sp, TARG = str_mortal(&str_no));
	    str_nset(TARG, *elem, len);
	}
#else
	(void)astore(ary, ++sp, TARG = str_mortal(&str_no));
	str_nset(TARG, hent->h_addr, len);
#endif /* h_addr */
#else /* lint */
	elem = Nullch;
	elem = elem;
	(void)astore(ary, ++sp, str_mortal(&str_no));
#endif /* lint */
    }

    return sp;
}