Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/lib/libcs/csport.c
1808 views
1
/***********************************************************************
2
* *
3
* This software is part of the ast package *
4
* Copyright (c) 1990-2011 AT&T Intellectual Property *
5
* and is licensed under the *
6
* Eclipse Public License, Version 1.0 *
7
* by AT&T Intellectual Property *
8
* *
9
* A copy of the License is available at *
10
* http://www.eclipse.org/org/documents/epl-v10.html *
11
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
12
* *
13
* Information and Software Systems Research *
14
* AT&T Research *
15
* Florham Park NJ *
16
* *
17
* Glenn Fowler <[email protected]> *
18
* *
19
***********************************************************************/
20
#pragma prototyped
21
/*
22
* Glenn Fowler
23
* AT&T Research
24
*
25
* return the port number given its name
26
*/
27
28
#include "cslib.h"
29
30
#include <hashkey.h>
31
32
/*
33
* map <type,serv> to port number
34
* e points to chars after service name
35
*/
36
37
unsigned long
38
csport(register Cs_t* state, const char* type, const char* serv)
39
{
40
unsigned long n;
41
char* t;
42
43
if (streq(serv, "reserved"))
44
return CS_PORT_RESERVED;
45
if (streq(serv, "normal"))
46
return CS_PORT_NORMAL;
47
n = strtol(serv, &t, 0);
48
if (t > serv && *t == '.')
49
strtol(t + 1, &t, 0);
50
if (*t)
51
{
52
if (strneq(serv, CS_SVC_INET, sizeof(CS_SVC_INET) - 1))
53
{
54
serv += sizeof(CS_SVC_INET) - 1;
55
#if CS_LIB_SOCKET || CS_LIB_V10
56
{
57
struct servent* sp;
58
59
#if CS_LIB_V10
60
if (sp = in_service(serv, type, 0))
61
return sp->port;
62
#endif
63
#if CS_LIB_SOCKET
64
if (sp = getservbyname(serv, type))
65
return ntohs(sp->s_port);
66
#endif
67
}
68
#endif
69
switch (strkey(serv))
70
{
71
case HASHKEY6('t','c','p','m','u','x'):
72
return 1;
73
case HASHKEY4('e','c','h','o'):
74
return 7;
75
case HASHKEY6('d','i','s','c','a','r'):
76
return 9;
77
case HASHKEY6('s','y','s','t','a','t'):
78
return 11;
79
case HASHKEY6('d','a','y','t','i','m'):
80
return 13;
81
case HASHKEY6('n','e','t','s','t','a'):
82
return 15;
83
case HASHKEY4('q','o','t','d'):
84
return 17;
85
case HASHKEY6('c','h','a','r','g','e'):
86
return 19;
87
case HASHKEY3('f','t','p'):
88
return 21;
89
case HASHKEY6('t','e','l','n','e','t'):
90
return 23;
91
case HASHKEY4('s','m','t','p'):
92
return 25;
93
case HASHKEY4('t','i','m','e'):
94
return 37;
95
case HASHKEY3('r','l','p'):
96
return 39;
97
case HASHKEY4('n','a','m','e'):
98
return 42;
99
case HASHKEY5('w','h','o','i','s'):
100
return 43;
101
case HASHKEY6('d','o','m','a','i','n'):
102
return 53;
103
case HASHKEY3('m','t','p'):
104
return 57;
105
case HASHKEY5('b','o','o','t','p'):
106
return 67;
107
case HASHKEY6('b','o','o','t','p','c'):
108
return 68;
109
case HASHKEY4('t','f','t','p'):
110
return 69;
111
case HASHKEY6('g','o','p','h','e','r'):
112
return 70;
113
case HASHKEY3('r','j','e'):
114
return 77;
115
case HASHKEY6('f','i','n','g','e','r'):
116
return 79;
117
case HASHKEY4('h','t','t','p'):
118
return 80;
119
case HASHKEY4('l','i','n','k'):
120
return 87;
121
case HASHKEY6('s','u','p','d','u','p'):
122
return 95;
123
case HASHKEY6('h','o','s','t','n','a'):
124
return 101;
125
case HASHKEY4('x',HASHKEYN('4'),HASHKEYN('0'),HASHKEYN('0')):
126
return 103;
127
case HASHKEY6('s','u','n','r','p','c'):
128
return 111;
129
case HASHKEY4('a','u','t','h'):
130
return 113;
131
case HASHKEY4('s','f','t','p'):
132
return 115;
133
case HASHKEY4('n','n','t','p'):
134
return 119;
135
case HASHKEY4('e','r','p','c'):
136
return 121;
137
case HASHKEY3('n','t','p'):
138
return 123;
139
case HASHKEY4('i','m','a','p'):
140
return 143;
141
case HASHKEY4('s','n','m','p'):
142
return 161;
143
case HASHKEY5('p','r','o','x','y'):
144
return 402;
145
case HASHKEY3('a','t','x'):
146
if (access("/etc/in.atxd", F_OK))
147
break;
148
return 512;
149
case HASHKEY4('b','i','f','f'):
150
return 512;
151
case HASHKEY4('e','x','e','c'):
152
return 512;
153
case HASHKEY5('l','o','g','i','n'):
154
return 513;
155
case HASHKEY3('w','h','o'):
156
return 513;
157
case HASHKEY5('s','h','e','l','l'):
158
return 514;
159
case HASHKEY6('s','y','s','l','o','g'):
160
return 514;
161
case HASHKEY6('p','r','i','n','t','e'):
162
return 515;
163
case HASHKEY4('t','a','l','k'):
164
return 517;
165
case HASHKEY5('n','t','a','l','k'):
166
return 518;
167
case HASHKEY5('r','o','u','t','e'):
168
return 520;
169
case HASHKEY5('t','i','m','e','d'):
170
return 525;
171
case HASHKEY5('t','e','m','p','o'):
172
return 526;
173
case HASHKEY4('u','u','c','p'):
174
return 540;
175
}
176
}
177
return CS_PORT_INVALID;
178
}
179
return n;
180
}
181
182
unsigned long
183
_cs_port(const char* type, const char* serv)
184
{
185
return csport(&cs, type, serv);
186
}
187
188