fix variable name.
[ruby-svn.git] / wince / winsock2.c
blob9b2a5be6005fc3b0e5b2a3a4dffdd75c19c2ecda
1 /***************************************************************
2 winsock2.c
3 ***************************************************************/
5 //#define _WINSOCK2_C_DEBUG_MAIN_
7 #include <windows.h>
8 #include "wince.h"
9 #ifdef _WINSOCK2_C_DEBUG_MAIN_
10 #include <winsock.h>
11 #endif
13 #ifndef _WINSOCK2_C_DEBUG_MAIN_
14 struct servent{
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 */
20 struct protoent{
21 char* p_name; /* official protocol name */
22 char** p_aliases; /* alias list */
23 short p_proto; /* protocol # */
25 #endif
27 struct sproto{
28 short num;
29 char name[10];
31 struct sserv{
32 short num;
33 char protoname[10];
34 char servname[20];
37 static struct sproto _proto_table[11]={
38 0, "ip",
39 1, "icmp",
40 3, "ggp",
41 6, "tcp",
42 8, "egp",
43 12, "pup",
44 17, "udp",
45 20, "hmp",
46 22, "xns-idp",
47 27, "rdp",
48 66, "rvd",
51 static struct sserv _serv_table[142]={
52 7, "tcp", "echo",
53 7, "udp", "echo",
54 9, "tcp", "discard",
55 9, "udp", "discard",
56 11, "tcp", "systat",
57 11, "udp", "systat",
58 13, "tcp", "daytime",
59 13, "udp", "daytime",
60 15, "tcp", "netstat",
61 17, "tcp", "qotd",
62 17, "udp", "qotd",
63 19, "tcp", "chargen",
64 19, "udp", "chargen",
65 20, "tcp", "ftp-data",
66 21, "tcp", "ftp",
67 23, "tcp", "telnet",
68 25, "tcp", "smtp",
69 37, "tcp", "time",
70 37, "udp", "time",
71 39, "udp", "rlp",
72 42, "tcp", "name",
73 42, "udp", "name",
74 43, "tcp", "whois",
75 53, "tcp", "domain",
76 53, "udp", "domain",
77 53, "tcp", "nameserver",
78 53, "udp", "nameserver",
79 57, "tcp", "mtp",
80 67, "udp", "bootp",
81 69, "udp", "tftp",
82 77, "tcp", "rje",
83 79, "tcp", "finger",
84 87, "tcp", "link",
85 95, "tcp", "supdup",
86 101, "tcp", "hostnames",
87 102, "tcp", "iso-tsap",
88 103, "tcp", "dictionary",
89 103, "tcp", "x400",
90 104, "tcp", "x400-snd",
91 105, "tcp", "csnet-ns",
92 109, "tcp", "pop",
93 109, "tcp", "pop2",
94 110, "tcp", "pop3",
95 111, "tcp", "portmap",
96 111, "udp", "portmap",
97 111, "tcp", "sunrpc",
98 111, "udp", "sunrpc",
99 113, "tcp", "auth",
100 115, "tcp", "sftp",
101 117, "tcp", "path",
102 117, "tcp", "uucp-path",
103 119, "tcp", "nntp",
104 123, "udp", "ntp",
105 137, "udp", "nbname",
106 138, "udp", "nbdatagram",
107 139, "tcp", "nbsession",
108 144, "tcp", "NeWS",
109 153, "tcp", "sgmp",
110 158, "tcp", "tcprepo",
111 161, "tcp", "snmp",
112 162, "tcp", "snmp-trap",
113 170, "tcp", "print-srv",
114 175, "tcp", "vmnet",
115 315, "udp", "load",
116 400, "tcp", "vmnet0",
117 500, "udp", "sytek",
118 512, "udp", "biff",
119 512, "tcp", "exec",
120 513, "tcp", "login",
121 513, "udp", "who",
122 514, "tcp", "shell",
123 514, "udp", "syslog",
124 515, "tcp", "printer",
125 517, "udp", "talk",
126 518, "udp", "ntalk",
127 520, "tcp", "efs",
128 520, "udp", "route",
129 525, "udp", "timed",
130 526, "tcp", "tempo",
131 530, "tcp", "courier",
132 531, "tcp", "conference",
133 531, "udp", "rvd-control",
134 532, "tcp", "netnews",
135 533, "udp", "netwall",
136 540, "tcp", "uucp",
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",
148 702, "udp", "acct",
149 703, "udp", "acctlogin",
150 704, "udp", "acctprinter",
151 704, "udp", "elcsd",
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",
163 1109, "tcp", "kpop",
164 1167, "udp", "phone",
165 1524, "tcp", "ingreslock",
166 1666, "udp", "maze",
167 2049, "udp", "nfs",
168 2053, "tcp", "knetd",
169 2105, "tcp", "eklogin",
170 5555, "tcp", "rmt",
171 5556, "tcp", "mtb",
172 9535, "tcp", "man",
173 9536, "tcp", "w",
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;
200 int i;
201 int len = strlen(name);
203 memset( &pe, 0, sizeof(struct protoent) );
205 for(i=0; i<9; i++)
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;
211 break;
215 return &pe;
218 struct protoent* getprotobynumber(int proto)
220 static struct protoent pe={0};
221 int i;
223 memset( &pe, 0, sizeof(struct protoent) );
225 for(i=0; i<9; i++)
227 if( proto == _proto_table[i].num )
229 pe.p_name = _proto_table[i].name;
230 pe.p_proto= _proto_table[i].num;
231 break;
235 return &pe;
238 /* WinCE doesn't have /etc/services. */
239 struct servent* getservbyname(const char* name,
240 const char* proto)
242 static struct servent se;
243 int i;
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 ) )
251 return NULL;
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 ) )
258 char hc, lc;
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;
264 break;
268 return &se;
271 struct servent* getservbyport(int port, const char* proto)
273 static struct servent se;
274 int i;
275 int plen = strlen(proto);
276 short sport;
277 char lc, hc;
279 hc = (port&0xFF00)>>8;
280 lc = port&0xFF;
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 ) )
289 return NULL;
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;
298 se.s_port = port;
299 break;
303 return &se;
307 #ifdef _WINSOCK2_C_DEBUG_MAIN_
309 int main()
311 WORD wVersionRequested = MAKEWORD(1,1);
312 WSADATA wsaData;
313 int nErrorStatus;
314 struct protoent pe1, pe2;
315 struct servent se1, se2;
317 nErrorStatus = WSAStartup(wVersionRequested, &wsaData);
318 if(nErrorStatus != 0)
319 return -1;
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");
333 WSACleanup();
335 return 0;
338 #endif