perl 5.0 alpha 3
[p5sagit/p5-mst-13.2.git] / do / gsent
CommitLineData
79072805 1int
2do_gsent(which,gimme,arglast)
3int which;
4int gimme;
5int *arglast;
6{
7 register ARRAY *ary = stack;
8 register int sp = arglast[0];
9 register char **elem;
10 register STR *TARG;
11 struct servent *getservbyname();
12 struct servent *getservbynumber();
13 struct servent *getservent();
14 struct servent *sent;
15
16 if (which == O_GSBYNAME) {
17 char *name = str_get(ary->ary_array[sp+1]);
18 char *proto = str_get(ary->ary_array[sp+2]);
19
20 if (proto && !*proto)
21 proto = Nullch;
22
23 sent = getservbyname(name,proto);
24 }
25 else if (which == O_GSBYPORT) {
26 int port = (int)str_gnum(ary->ary_array[sp+1]);
27 char *proto = str_get(ary->ary_array[sp+2]);
28
29 sent = getservbyport(port,proto);
30 }
31 else
32 sent = getservent();
33
34 if (gimme != G_ARRAY) {
35 astore(ary, ++sp, TARG = str_mortal(&str_undef));
36 if (sent) {
37 if (which == O_GSBYNAME) {
38#ifdef HAS_NTOHS
39 str_numset(TARG, (double)ntohs(sent->s_port));
40#else
41 str_numset(TARG, (double)(sent->s_port));
42#endif
43 }
44 else
45 str_set(TARG, sent->s_name);
46 }
47 return sp;
48 }
49
50 if (sent) {
51#ifndef lint
52 (void)astore(ary, ++sp, TARG = str_mortal(&str_no));
53 str_set(TARG, sent->s_name);
54 (void)astore(ary, ++sp, TARG = str_mortal(&str_no));
55 for (elem = sent->s_aliases; *elem; elem++) {
56 str_cat(TARG, *elem);
57 if (elem[1])
58 str_ncat(TARG," ",1);
59 }
60 (void)astore(ary, ++sp, TARG = str_mortal(&str_no));
61#ifdef HAS_NTOHS
62 str_numset(TARG, (double)ntohs(sent->s_port));
63#else
64 str_numset(TARG, (double)(sent->s_port));
65#endif
66 (void)astore(ary, ++sp, TARG = str_mortal(&str_no));
67 str_set(TARG, sent->s_proto);
68#else /* lint */
69 elem = Nullch;
70 elem = elem;
71 (void)astore(ary, ++sp, str_mortal(&str_no));
72#endif /* lint */
73 }
74
75 return sp;
76}
77