]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/wince/net.cpp
1 // Copyright 1998, Ben Goetter. All rights reserved.
6 WCE 2.0 lacks many of the 'database' winsock routines.
7 Stub just enough them for ss.dll.
15 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
16 #pragma implementation "net.h"
19 // For compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
26 #include "wx/msw/wrapwin.h"
30 #include "wx/msw/wince/net.h"
33 #define CCH_MAX_PROTO 4
35 static struct protoent RgProtoEnt
[] =
38 { "udp", {NULL
}, 17 },
39 { "icmp", {NULL
}, 1 },
45 #define CCH_MAX_SERV 8
47 // Ordered by most likely to be requested.
48 // Assumes that a service available on different protocols
49 // will use the same port number on each protocol.
50 // Should that be no longer the case,
51 // remove the fFoundOnce code from getservbyXxx fcns.
53 // This table keeps port numbers in host byte order.
55 static struct servent RgServEnt
[] =
57 { "ftp", {NULL
}, 21, "tcp" },
58 { "ftp-data", {NULL
}, 20, "tcp" },
59 { "telnet", {NULL
}, 23, "tcp" },
60 { "smtp", {NULL
}, 25, "tcp" },
61 { "http", {NULL
}, 80, "tcp" },
62 { "http", {NULL
}, 80, "udp" },
63 { "pop", {NULL
}, 109, "tcp" },
64 { "pop2", {NULL
}, 109, "tcp" },
65 { "pop3", {NULL
}, 110, "tcp" },
66 { "nntp", {NULL
}, 119, "tcp" },
67 { "finger", {NULL
}, 79, "tcp" },
68 /* include most of the simple TCP services for testing */
69 { "echo", {NULL
}, 7, "tcp" },
70 { "echo", {NULL
}, 7, "udp" },
71 { "discard", {NULL
}, 9, "tcp" },
72 { "discard", {NULL
}, 9, "udp" },
73 { "chargen", {NULL
}, 19, "tcp" },
74 { "chargen", {NULL
}, 19, "udp" },
75 { "systat", {NULL
}, 11, "tcp" },
76 { "systat", {NULL
}, 11, "udp" },
77 { "daytime", {NULL
}, 13, "tcp" },
78 { "daytime", {NULL
}, 13, "udp" },
79 { "netstat", {NULL
}, 15, "tcp" },
80 { "qotd", {NULL
}, 17, "tcp" },
81 { "qotd", {NULL
}, 17, "udp" },
82 { NULL
, {NULL
}, 0, NULL
}
85 // Since table kept in host byte order,
86 // return this element to callers
88 static struct servent ServEntReturn
= {0};
90 // Because CE doesn't have _stricmp - that's why.
92 static void strcpyLC(char* szDst
, const char* szSrc
, int cch
)
96 for (i
= 0, ch
= szSrc
[i
]; i
< cch
&& ch
!= 0; ch
= szSrc
[++i
])
98 szDst
[i
] = (ch
>= 'A' && ch
<= 'Z') ? (ch
+ ('a'-'A')) : ch
;
103 struct servent
* WINSOCKAPI
getservbyport(int port
, const char * proto
)
106 port
= ntohs((unsigned short)port
); // arrives in network byte order
107 struct servent
*ps
= &RgServEnt
[0];
108 BOOL fFoundOnce
= FALSE
; // flag to short-circuit search through rest of db
110 // Make a lowercase version for comparison
111 // truncate to 1 char longer than any value in table
112 char szProtoLC
[CCH_MAX_PROTO
+2];
114 strcpyLC(szProtoLC
, proto
, CCH_MAX_PROTO
+1);
116 while (NULL
!= ps
->s_name
)
118 if (port
== ps
->s_port
)
121 if (NULL
== proto
|| !strcmp(szProtoLC
, ps
->s_proto
))
124 ServEntReturn
.s_port
= htons(ps
->s_port
);
125 return &ServEntReturn
;
135 struct servent
* WINSOCKAPI
getservbyname(const char * name
,
138 struct servent
*ps
= &RgServEnt
[0];
139 BOOL fFoundOnce
= FALSE
; // flag to short-circuit search through rest of db
141 // Make lowercase versions for comparisons
142 // truncate to 1 char longer than any value in table
143 char szNameLC
[CCH_MAX_SERV
+2];
144 strcpyLC(szNameLC
, name
, CCH_MAX_SERV
+1);
145 char szProtoLC
[CCH_MAX_PROTO
+2];
147 strcpyLC(szProtoLC
, proto
, CCH_MAX_PROTO
+1);
149 while (NULL
!= ps
->s_name
)
151 if (!strcmp(szNameLC
, ps
->s_name
))
154 if (NULL
== proto
|| !strcmp(szProtoLC
, ps
->s_proto
))
157 ServEntReturn
.s_port
= htons(ps
->s_port
);
158 return &ServEntReturn
;
168 struct protoent
* WINSOCKAPI
getprotobynumber(int proto
)
170 struct protoent
*pr
= &RgProtoEnt
[0];
171 while (NULL
!= pr
->p_name
)
173 if (proto
== pr
->p_proto
)