/[pcsx2_0.9.7]/trunk/3rdparty/wxWidgets/src/msw/wince/net.cpp
ViewVC logotype

Contents of /trunk/3rdparty/wxWidgets/src/msw/wince/net.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 10 - (show annotations) (download)
Mon Sep 6 11:40:06 2010 UTC (9 years, 9 months ago) by william
File size: 4710 byte(s)
exported r3113 from ./upstream/trunk
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/wince/net.cpp
3 // Purpose:
4 // Author:
5 // Modified by:
6 // Created:
7 // RCS-ID: $Id: net.cpp 41054 2006-09-07 19:01:45Z ABX $
8 // Copyright: Copyright 1998, Ben Goetter. All rights reserved.
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 /*
13 patch holes in winsock
14
15 WCE 2.0 lacks many of the 'database' winsock routines.
16 Stub just enough them for ss.dll.
17
18 getprotobynumber
19 getservbyport
20 getservbyname
21
22 */
23
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
26
27 #ifdef __BORLANDC__
28 #pragma hdrstop
29 #endif
30
31 #ifndef WX_PRECOMP
32 #include "wx/msw/wrapwin.h"
33 #endif
34
35 #include <tchar.h>
36 #include <winsock.h>
37 #include <string.h>
38 #include "wx/msw/wince/net.h"
39
40
41 #define CCH_MAX_PROTO 4
42
43 static struct protoent RgProtoEnt[] =
44 {
45 { "tcp", {NULL}, 6 },
46 { "udp", {NULL}, 17 },
47 { "icmp", {NULL}, 1 },
48 { "ip", {NULL}, 0 },
49 { NULL, {NULL}, 0 }
50 };
51
52
53 #define CCH_MAX_SERV 8
54
55 // Ordered by most likely to be requested.
56 // Assumes that a service available on different protocols
57 // will use the same port number on each protocol.
58 // Should that be no longer the case,
59 // remove the fFoundOnce code from getservbyXxx fcns.
60
61 // This table keeps port numbers in host byte order.
62
63 static struct servent RgServEnt[] =
64 {
65 { "ftp", {NULL}, 21, "tcp" },
66 { "ftp-data", {NULL}, 20, "tcp" },
67 { "telnet", {NULL}, 23, "tcp" },
68 { "smtp", {NULL}, 25, "tcp" },
69 { "http", {NULL}, 80, "tcp" },
70 { "http", {NULL}, 80, "udp" },
71 { "pop", {NULL}, 109, "tcp" },
72 { "pop2", {NULL}, 109, "tcp" },
73 { "pop3", {NULL}, 110, "tcp" },
74 { "nntp", {NULL}, 119, "tcp" },
75 { "finger", {NULL}, 79, "tcp" },
76 /* include most of the simple TCP services for testing */
77 { "echo", {NULL}, 7, "tcp" },
78 { "echo", {NULL}, 7, "udp" },
79 { "discard", {NULL}, 9, "tcp" },
80 { "discard", {NULL}, 9, "udp" },
81 { "chargen", {NULL}, 19, "tcp" },
82 { "chargen", {NULL}, 19, "udp" },
83 { "systat", {NULL}, 11, "tcp" },
84 { "systat", {NULL}, 11, "udp" },
85 { "daytime", {NULL}, 13, "tcp" },
86 { "daytime", {NULL}, 13, "udp" },
87 { "netstat", {NULL}, 15, "tcp" },
88 { "qotd", {NULL}, 17, "tcp" },
89 { "qotd", {NULL}, 17, "udp" },
90 { NULL, {NULL}, 0, NULL }
91 };
92
93 // Since table kept in host byte order,
94 // return this element to callers
95
96 static struct servent ServEntReturn = {0};
97
98 // Because CE doesn't have _stricmp - that's why.
99
100 static void strcpyLC(char* szDst, const char* szSrc, int cch)
101 {
102 int i;
103 char ch;
104 for (i = 0, ch = szSrc[i]; i < cch && ch != 0; ch = szSrc[++i])
105 {
106 szDst[i] = (ch >= 'A' && ch <= 'Z') ? (ch + ('a'-'A')) : ch;
107 } szDst[i] = 0;
108 }
109
110
111 struct servent * WINSOCKAPI getservbyport(int port, const char * proto)
112 {
113
114 port = ntohs((unsigned short)port); // arrives in network byte order
115 struct servent *ps = &RgServEnt[0];
116 BOOL fFoundOnce = FALSE; // flag to short-circuit search through rest of db
117
118 // Make a lowercase version for comparison
119 // truncate to 1 char longer than any value in table
120 char szProtoLC[CCH_MAX_PROTO+2];
121 if (NULL != proto)
122 strcpyLC(szProtoLC, proto, CCH_MAX_PROTO+1);
123
124 while (NULL != ps->s_name)
125 {
126 if (port == ps->s_port)
127 {
128 fFoundOnce = TRUE;
129 if (NULL == proto || !strcmp(szProtoLC, ps->s_proto))
130 {
131 ServEntReturn = *ps;
132 ServEntReturn.s_port = htons(ps->s_port);
133 return &ServEntReturn;
134 }
135 }
136 else if (fFoundOnce)
137 break;
138 ++ps;
139 } return NULL;
140 }
141
142
143 struct servent * WINSOCKAPI getservbyname(const char * name,
144 const char * proto)
145 {
146 struct servent *ps = &RgServEnt[0];
147 BOOL fFoundOnce = FALSE; // flag to short-circuit search through rest of db
148
149 // Make lowercase versions for comparisons
150 // truncate to 1 char longer than any value in table
151 char szNameLC[CCH_MAX_SERV+2];
152 strcpyLC(szNameLC, name, CCH_MAX_SERV+1);
153 char szProtoLC[CCH_MAX_PROTO+2];
154 if (NULL != proto)
155 strcpyLC(szProtoLC, proto, CCH_MAX_PROTO+1);
156
157 while (NULL != ps->s_name)
158 {
159 if (!strcmp(szNameLC, ps->s_name))
160 {
161 fFoundOnce = TRUE;
162 if (NULL == proto || !strcmp(szProtoLC, ps->s_proto))
163 {
164 ServEntReturn = *ps;
165 ServEntReturn.s_port = htons(ps->s_port);
166 return &ServEntReturn;
167 }
168 }
169 else if (fFoundOnce)
170 break;
171 ++ps;
172 } return NULL;
173 }
174
175
176 struct protoent * WINSOCKAPI getprotobynumber(int proto)
177 {
178 struct protoent *pr = &RgProtoEnt[0];
179 while (NULL != pr->p_name)
180 {
181 if (proto == pr->p_proto)
182 return pr;
183 ++pr;
184 } return NULL;
185 }

  ViewVC Help
Powered by ViewVC 1.1.22