1 /***************************************************************
3 ***************************************************************/
5 //#define _WINSOCK2_C_DEBUG_MAIN_
9 #ifdef _WINSOCK2_C_DEBUG_MAIN_
13 #ifndef _WINSOCK2_C_DEBUG_MAIN_
15 char* s_name
; /* official service name */
16 char** s_aliases
; /* alias list */
17 short s_port
; /* port # */
18 char* s_proto
; /* protocol to use */
21 char* p_name
; /* official protocol name */
22 char** p_aliases
; /* alias list */
23 short p_proto
; /* protocol # */
37 static struct sproto _proto_table
[11]={
51 static struct sserv _serv_table
[142]={
65 20, "tcp", "ftp-data",
77 53, "tcp", "nameserver",
78 53, "udp", "nameserver",
86 101, "tcp", "hostnames",
87 102, "tcp", "iso-tsap",
88 103, "tcp", "dictionary",
90 104, "tcp", "x400-snd",
91 105, "tcp", "csnet-ns",
95 111, "tcp", "portmap",
96 111, "udp", "portmap",
102 117, "tcp", "uucp-path",
105 137, "udp", "nbname",
106 138, "udp", "nbdatagram",
107 139, "tcp", "nbsession",
110 158, "tcp", "tcprepo",
112 162, "tcp", "snmp-trap",
113 170, "tcp", "print-srv",
116 400, "tcp", "vmnet0",
123 514, "udp", "syslog",
124 515, "tcp", "printer",
131 530, "tcp", "courier",
132 531, "tcp", "conference",
133 531, "udp", "rvd-control",
134 532, "tcp", "netnews",
135 533, "udp", "netwall",
137 543, "tcp", "klogin",
138 544, "tcp", "kshell",
139 550, "udp", "new-rwho",
140 556, "tcp", "remotefs",
141 560, "udp", "rmonitor",
142 561, "udp", "monitor",
143 600, "tcp", "garcon",
144 601, "tcp", "maitrd",
145 602, "tcp", "busboy",
146 700, "udp", "acctmaster",
147 701, "udp", "acctslave",
149 703, "udp", "acctlogin",
150 704, "udp", "acctprinter",
152 705, "udp", "acctinfo",
153 706, "udp", "acctslave2",
154 707, "udp", "acctdisk",
155 750, "tcp", "kerberos",
156 750, "udp", "kerberos",
157 751, "tcp", "kerberos_master",
158 751, "udp", "kerberos_master",
159 752, "udp", "passwd_server",
160 753, "udp", "userreg_server",
161 754, "tcp", "krb_prop",
162 888, "tcp", "erlogin",
164 1167, "udp", "phone",
165 1524, "tcp", "ingreslock",
168 2053, "tcp", "knetd",
169 2105, "tcp", "eklogin",
174 9537, "tcp", "mantst",
175 10000, "tcp", "bnews",
176 10000, "udp", "rscs0",
177 10001, "tcp", "queue",
178 10001, "udp", "rscs1",
179 10002, "tcp", "poker",
180 10002, "udp", "rscs2",
181 10003, "tcp", "gateway",
182 10003, "udp", "rscs3",
183 10004, "tcp", "remp",
184 10004, "udp", "rscs4",
185 10005, "udp", "rscs5",
186 10006, "udp", "rscs6",
187 10007, "udp", "rscs7",
188 10008, "udp", "rscs8",
189 10009, "udp", "rscs9",
190 10010, "udp", "rscsa",
191 10011, "udp", "rscsb",
192 10012, "tcp", "qmaster",
193 10012, "udp", "qmaster",
196 /* WinCE doesn't have /etc/protocols. */
197 struct protoent
* getprotobyname(const char* name
)
199 static struct protoent pe
;
201 int len
= strlen(name
);
203 memset( &pe
, 0, sizeof(struct protoent
) );
207 if( 0==strnicmp(_proto_table
[i
].name
, name
, len
) )
209 pe
.p_name
= _proto_table
[i
].name
;
210 pe
.p_proto
= _proto_table
[i
].num
;
218 struct protoent
* getprotobynumber(int proto
)
220 static struct protoent pe
={0};
223 memset( &pe
, 0, sizeof(struct protoent
) );
227 if( proto
== _proto_table
[i
].num
)
229 pe
.p_name
= _proto_table
[i
].name
;
230 pe
.p_proto
= _proto_table
[i
].num
;
238 /* WinCE doesn't have /etc/services. */
239 struct servent
* getservbyname(const char* name
,
242 static struct servent se
;
244 int slen
= strlen(name
), plen
= strlen(proto
);
246 memset( &se
, 0, sizeof(struct servent
) );
248 if( proto
==NULL
) return NULL
;
249 if( 0!=strnicmp( proto
, "tcp", 3 ) &&
250 0!=strnicmp( proto
, "udp", 3 ) )
253 for( i
=0; i
<142; i
++ )
255 if( 0==strnicmp( name
, _serv_table
[i
].servname
, slen
) &&
256 0==strnicmp( proto
, _serv_table
[i
].protoname
, plen
) )
259 se
.s_name
= _serv_table
[i
].servname
;
260 se
.s_proto
= _serv_table
[i
].protoname
;
261 hc
= (_serv_table
[i
].num
&0xFF00)>>8;
262 lc
= _serv_table
[i
].num
&0xFF;
263 se
.s_port
= (lc
<<8) + hc
;
271 struct servent
* getservbyport(int port
, const char* proto
)
273 static struct servent se
;
275 int plen
= strlen(proto
);
279 hc
= (port
&0xFF00)>>8;
282 sport
= (lc
<<8) + hc
;
284 memset( &se
, 0, sizeof(struct servent
) );
286 if( proto
==NULL
) return NULL
;
287 if( 0!=strnicmp( proto
, "tcp", 3 ) &&
288 0!=strnicmp( proto
, "udp", 3 ) )
291 for( i
=0; i
<142; i
++ )
293 if( sport
== _serv_table
[i
].num
&&
294 0==strnicmp( proto
, _serv_table
[i
].protoname
, plen
) )
296 se
.s_name
= _serv_table
[i
].servname
;
297 se
.s_proto
= _serv_table
[i
].protoname
;
307 #ifdef _WINSOCK2_C_DEBUG_MAIN_
311 WORD wVersionRequested
= MAKEWORD(1,1);
314 struct protoent pe1
, pe2
;
315 struct servent se1
, se2
;
317 nErrorStatus
= WSAStartup(wVersionRequested
, &wsaData
);
318 if(nErrorStatus
!= 0)
321 pe1
= *getprotobyname("UDP");
322 pe2
= *_getprotobyname("UDP");
324 // pe1 = *getprotobynumber(17);
325 // pe2 = *_getprotobynumber(17);
327 // se1 = *getservbyname("gateway", "tcp");
328 // se2 = *_getservbyname("gateway", "tcp");
330 se1
= *getservbyport(0x1327, "tcp");
331 se2
= *_getservbyport(0x1327, "tcp");