From: Julian Smart Date: Sat, 12 Jul 2003 17:58:22 +0000 (+0000) Subject: Added net stuff, some fixes to gsock code for WinCE X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/882dfc675372ec3544e329ad6df8c4cdddbdb52d Added net stuff, some fixes to gsock code for WinCE git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@21923 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/gsocket.h b/include/wx/gsocket.h index 54db19bc4e..5cd91ae001 100644 --- a/include/wx/gsocket.h +++ b/include/wx/gsocket.h @@ -32,10 +32,14 @@ having been defined in sys/types.h" when winsock.h is included later and doesn't seem to be necessary anyhow. It's not needed under Mac neither. */ -#if !defined(__WXMAC__) && !defined(__CYGWIN__) +#if !defined(__WXMAC__) && !defined(__CYGWIN__) && !defined(__WXWINCE__) #include #endif +#ifdef __WXWINCE__ +#include +#endif + #ifdef __cplusplus extern "C" { #endif diff --git a/include/wx/msw/wince/net.h b/include/wx/msw/wince/net.h new file mode 100644 index 0000000000..7476d80463 --- /dev/null +++ b/include/wx/msw/wince/net.h @@ -0,0 +1,20 @@ +// Copyright 1998, Ben Goetter. All rights reserved. + +/* + patch holes in winsock + + WCE 2.0 lacks many of the 'database' winsock routines. + Stub just enough them for ss.dll. + + getprotobynumber + getservbyport + getservbyname + +*/ + +struct servent * WINSOCKAPI getservbyport(int port, const char * proto) ; + +struct servent * WINSOCKAPI getservbyname(const char * name, + const char * proto) ; +struct protoent * WINSOCKAPI getprotobynumber(int proto) ; + diff --git a/src/msw/gsocket.c b/src/msw/gsocket.c index 9ea70c328e..0a5ad3a4ac 100644 --- a/src/msw/gsocket.c +++ b/src/msw/gsocket.c @@ -52,7 +52,16 @@ # define _GSocket_Disable_Events(socket) #endif /* wxUSE_GUI */ +#ifndef __WXWINCE__ #include +#else +#define assert(x) +#ifndef isdigit +#define isdigit(x) (x > 47 && x < 58) +#endif +#include "wx/msw/wince/net.h" +#endif + #include #include #include diff --git a/src/msw/gsockmsw.c b/src/msw/gsockmsw.c index 32131c214a..5016995a45 100644 --- a/src/msw/gsockmsw.c +++ b/src/msw/gsockmsw.c @@ -7,6 +7,14 @@ * ------------------------------------------------------------------------- */ +/* + * TODO: for WinCE we need to replace WSAAsyncSelect + * (Windows message-based notification of network events for a socket) + * with another mechanism. + * We may need to have a separate thread that polls for socket events + * using select() and sends a message to the main thread. + */ + /* * PLEASE don't put C++ comments here - this is a C source file. */ @@ -19,6 +27,14 @@ # pragma warning(disable:4115) /* named type definition in parentheses */ #endif +/* This needs to be before the wx/defs/h inclusion + * for some reason + */ + +#ifdef __WXWINCE__ +#include +#endif + #ifndef __GSOCKET_STANDALONE__ #include "wx/defs.h" #include "wx/setup.h" @@ -46,7 +62,14 @@ #endif /* __GSOCKET_STANDALONE__ */ +#ifndef __WXWINCE__ #include +#else +#define assert(x) +#include +#include "wx/msw/wince/net.h" +#endif + #include #include #include diff --git a/src/msw/utils.cpp b/src/msw/utils.cpp index 35ae44254a..2ce7da1956 100644 --- a/src/msw/utils.cpp +++ b/src/msw/utils.cpp @@ -36,7 +36,7 @@ #include "wx/msw/private.h" // includes #include "wx/msw/missing.h" // CHARSET_HANGUL -#ifdef __GNUWIN32_OLD__ +#if defined(__GNUWIN32_OLD__) || defined(__WXWINCE__) // apparently we need to include winsock.h to get WSADATA and other stuff // used in wxGetFullHostName() with the old mingw32 versions #include @@ -158,7 +158,6 @@ bool wxGetFullHostName(wxChar *buf, int maxSize) // shouldn't use winsock.dll (a.k.a. ws2_32.dll) at all so only use this // code if we link with it anyhow #if wxUSE_SOCKETS - WSADATA wsa; if ( WSAStartup(MAKEWORD(1, 1), &wsa) == 0 ) { diff --git a/src/msw/wince/net.cpp b/src/msw/wince/net.cpp new file mode 100644 index 0000000000..7891b54e4f --- /dev/null +++ b/src/msw/wince/net.cpp @@ -0,0 +1,167 @@ +// Copyright 1998, Ben Goetter. All rights reserved. + +/* + patch holes in winsock + + WCE 2.0 lacks many of the 'database' winsock routines. + Stub just enough them for ss.dll. + + getprotobynumber + getservbyport + getservbyname + +*/ + +#include +#include +#include +#include +#include "wx/msw/wince/net.h" + + +#define CCH_MAX_PROTO 4 + +static struct protoent RgProtoEnt[] = +{ + { "tcp", {NULL}, 6 }, + { "udp", {NULL}, 17 }, + { "icmp", {NULL}, 1 }, + { "ip", {NULL}, 0 }, + { NULL, {NULL}, 0 } +}; + + +#define CCH_MAX_SERV 8 + +// Ordered by most likely to be requested. +// Assumes that a service available on different protocols +// will use the same port number on each protocol. +// Should that be no longer the case, +// remove the fFoundOnce code from getservbyXxx fcns. + +// This table keeps port numbers in host byte order. + +static struct servent RgServEnt[] = +{ + { "ftp", {NULL}, 21, "tcp" }, + { "ftp-data", {NULL}, 20, "tcp" }, + { "telnet", {NULL}, 23, "tcp" }, + { "smtp", {NULL}, 25, "tcp" }, + { "http", {NULL}, 80, "tcp" }, + { "http", {NULL}, 80, "udp" }, + { "pop", {NULL}, 109, "tcp" }, + { "pop2", {NULL}, 109, "tcp" }, + { "pop3", {NULL}, 110, "tcp" }, + { "nntp", {NULL}, 119, "tcp" }, + { "finger", {NULL}, 79, "tcp" }, + /* include most of the simple TCP services for testing */ + { "echo", {NULL}, 7, "tcp" }, + { "echo", {NULL}, 7, "udp" }, + { "discard", {NULL}, 9, "tcp" }, + { "discard", {NULL}, 9, "udp" }, + { "chargen", {NULL}, 19, "tcp" }, + { "chargen", {NULL}, 19, "udp" }, + { "systat", {NULL}, 11, "tcp" }, + { "systat", {NULL}, 11, "udp" }, + { "daytime", {NULL}, 13, "tcp" }, + { "daytime", {NULL}, 13, "udp" }, + { "netstat", {NULL}, 15, "tcp" }, + { "qotd", {NULL}, 17, "tcp" }, + { "qotd", {NULL}, 17, "udp" }, + { NULL, {NULL}, 0, NULL } +}; + +// Since table kept in host byte order, +// return this element to callers + +static struct servent ServEntReturn = {0}; + +// Because CE doesn't have _stricmp - that's why. + +static void strcpyLC(char* szDst, const char* szSrc, int cch) +{ + int i; + char ch; + for (i = 0, ch = szSrc[i]; i < cch && ch != 0; ch = szSrc[++i]) + { + szDst[i] = (ch >= 'A' && ch <= 'Z') ? (ch + ('a'-'A')) : ch; + } szDst[i] = 0; +} + + +struct servent * WINSOCKAPI getservbyport(int port, const char * proto) +{ + + port = ntohs((unsigned short)port); // arrives in network byte order + struct servent *ps = &RgServEnt[0]; + BOOL fFoundOnce = FALSE; // flag to short-circuit search through rest of db + + // Make a lowercase version for comparison + // truncate to 1 char longer than any value in table + char szProtoLC[CCH_MAX_PROTO+2]; + if (NULL != proto) + strcpyLC(szProtoLC, proto, CCH_MAX_PROTO+1); + + while (NULL != ps->s_name) + { + if (port == ps->s_port) + { + fFoundOnce = TRUE; + if (NULL == proto || !strcmp(szProtoLC, ps->s_proto)) + { + ServEntReturn = *ps; + ServEntReturn.s_port = htons(ps->s_port); + return &ServEntReturn; + } + } + else if (fFoundOnce) + break; + ++ps; + } return NULL; +} + + +struct servent * WINSOCKAPI getservbyname(const char * name, + const char * proto) +{ + struct servent *ps = &RgServEnt[0]; + BOOL fFoundOnce = FALSE; // flag to short-circuit search through rest of db + + // Make lowercase versions for comparisons + // truncate to 1 char longer than any value in table + char szNameLC[CCH_MAX_SERV+2]; + strcpyLC(szNameLC, name, CCH_MAX_SERV+1); + char szProtoLC[CCH_MAX_PROTO+2]; + if (NULL != proto) + strcpyLC(szProtoLC, proto, CCH_MAX_PROTO+1); + + while (NULL != ps->s_name) + { + if (!strcmp(szNameLC, ps->s_name)) + { + fFoundOnce = TRUE; + if (NULL == proto || !strcmp(szProtoLC, ps->s_proto)) + { + ServEntReturn = *ps; + ServEntReturn.s_port = htons(ps->s_port); + return &ServEntReturn; + } + } + else if (fFoundOnce) + break; + ++ps; + } return NULL; +} + + +struct protoent * WINSOCKAPI getprotobynumber(int proto) +{ + struct protoent *pr = &RgProtoEnt[0]; + while (NULL != pr->p_name) + { + if (proto == pr->p_proto) + return pr; + ++pr; + } return NULL; +} +