]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/wince/net.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/wince/net.cpp
7 // Copyright: Copyright 1998, Ben Goetter. All rights reserved.
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
12 patch holes in winsock
14 WCE 2.0 lacks many of the 'database' winsock routines.
15 Stub just enough them for ss.dll.
23 // For compilers that support precompilation, includes "wx.h".
24 #include "wx/wxprec.h"
31 #include "wx/msw/wrapwin.h"
37 #include "wx/msw/wince/net.h"
40 #define CCH_MAX_PROTO 4
42 static struct protoent RgProtoEnt
[] =
45 { "udp", {NULL
}, 17 },
46 { "icmp", {NULL
}, 1 },
52 #define CCH_MAX_SERV 8
54 // Ordered by most likely to be requested.
55 // Assumes that a service available on different protocols
56 // will use the same port number on each protocol.
57 // Should that be no longer the case,
58 // remove the fFoundOnce code from getservbyXxx fcns.
60 // This table keeps port numbers in host byte order.
62 static struct servent RgServEnt
[] =
64 { "ftp", {NULL
}, 21, "tcp" },
65 { "ftp-data", {NULL
}, 20, "tcp" },
66 { "telnet", {NULL
}, 23, "tcp" },
67 { "smtp", {NULL
}, 25, "tcp" },
68 { "http", {NULL
}, 80, "tcp" },
69 { "http", {NULL
}, 80, "udp" },
70 { "pop", {NULL
}, 109, "tcp" },
71 { "pop2", {NULL
}, 109, "tcp" },
72 { "pop3", {NULL
}, 110, "tcp" },
73 { "nntp", {NULL
}, 119, "tcp" },
74 { "finger", {NULL
}, 79, "tcp" },
75 /* include most of the simple TCP services for testing */
76 { "echo", {NULL
}, 7, "tcp" },
77 { "echo", {NULL
}, 7, "udp" },
78 { "discard", {NULL
}, 9, "tcp" },
79 { "discard", {NULL
}, 9, "udp" },
80 { "chargen", {NULL
}, 19, "tcp" },
81 { "chargen", {NULL
}, 19, "udp" },
82 { "systat", {NULL
}, 11, "tcp" },
83 { "systat", {NULL
}, 11, "udp" },
84 { "daytime", {NULL
}, 13, "tcp" },
85 { "daytime", {NULL
}, 13, "udp" },
86 { "netstat", {NULL
}, 15, "tcp" },
87 { "qotd", {NULL
}, 17, "tcp" },
88 { "qotd", {NULL
}, 17, "udp" },
89 { NULL
, {NULL
}, 0, NULL
}
92 // Since table kept in host byte order,
93 // return this element to callers
95 static struct servent ServEntReturn
= {0};
97 // Because CE doesn't have _stricmp - that's why.
99 static void strcpyLC(char* szDst
, const char* szSrc
, int cch
)
103 for (i
= 0, ch
= szSrc
[i
]; i
< cch
&& ch
!= 0; ch
= szSrc
[++i
])
105 szDst
[i
] = (ch
>= 'A' && ch
<= 'Z') ? (ch
+ ('a'-'A')) : ch
;
110 struct servent
* WINSOCKAPI
getservbyport(int port
, const char * proto
)
113 port
= ntohs((unsigned short)port
); // arrives in network byte order
114 struct servent
*ps
= &RgServEnt
[0];
115 BOOL fFoundOnce
= FALSE
; // flag to short-circuit search through rest of db
117 // Make a lowercase version for comparison
118 // truncate to 1 char longer than any value in table
119 char szProtoLC
[CCH_MAX_PROTO
+2];
121 strcpyLC(szProtoLC
, proto
, CCH_MAX_PROTO
+1);
123 while (NULL
!= ps
->s_name
)
125 if (port
== ps
->s_port
)
128 if (NULL
== proto
|| !strcmp(szProtoLC
, ps
->s_proto
))
131 ServEntReturn
.s_port
= htons(ps
->s_port
);
132 return &ServEntReturn
;
142 struct servent
* WINSOCKAPI
getservbyname(const char * name
,
145 struct servent
*ps
= &RgServEnt
[0];
146 BOOL fFoundOnce
= FALSE
; // flag to short-circuit search through rest of db
148 // Make lowercase versions for comparisons
149 // truncate to 1 char longer than any value in table
150 char szNameLC
[CCH_MAX_SERV
+2];
151 strcpyLC(szNameLC
, name
, CCH_MAX_SERV
+1);
152 char szProtoLC
[CCH_MAX_PROTO
+2];
154 strcpyLC(szProtoLC
, proto
, CCH_MAX_PROTO
+1);
156 while (NULL
!= ps
->s_name
)
158 if (!strcmp(szNameLC
, ps
->s_name
))
161 if (NULL
== proto
|| !strcmp(szProtoLC
, ps
->s_proto
))
164 ServEntReturn
.s_port
= htons(ps
->s_port
);
165 return &ServEntReturn
;
175 struct protoent
* WINSOCKAPI
getprotobynumber(int proto
)
177 struct protoent
*pr
= &RgProtoEnt
[0];
178 while (NULL
!= pr
->p_name
)
180 if (proto
== pr
->p_proto
)