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