]> git.saurik.com Git - wxWidgets.git/blame - src/msw/wince/net.cpp
compilation fix for pch-less build
[wxWidgets.git] / src / msw / wince / net.cpp
CommitLineData
57bd4c60
WS
1///////////////////////////////////////////////////////////////////////////////
2// Name: src/msw/wince/net.cpp
3// Purpose:
4// Author:
5// Modified by:
6// Created:
7// RCS-ID: $Id$
8// Copyright: Copyright 1998, Ben Goetter. All rights reserved.
9// Licence: wxWindows licence
10///////////////////////////////////////////////////////////////////////////////
882dfc67
JS
11
12/*
39fc096d 13 patch holes in winsock
882dfc67
JS
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
d5e64615
VS
24// For compilers that support precompilation, includes "wx.h".
25#include "wx/wxprec.h"
26
27#ifdef __BORLANDC__
28 #pragma hdrstop
29#endif
30
57bd4c60
WS
31#ifndef WX_PRECOMP
32 #include "wx/msw/wrapwin.h"
33#endif
34
882dfc67
JS
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
43static 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.
39fc096d 58// Should that be no longer the case,
882dfc67
JS
59// remove the fFoundOnce code from getservbyXxx fcns.
60
61// This table keeps port numbers in host byte order.
62
63static 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
96static struct servent ServEntReturn = {0};
97
98// Because CE doesn't have _stricmp - that's why.
99
100static 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
111struct 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
143struct 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
176struct 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}