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
This commit is contained in:
@@ -32,10 +32,14 @@
|
|||||||
having been defined in sys/types.h" when winsock.h is included later and
|
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.
|
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 <sys/types.h>
|
#include <sys/types.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef __WXWINCE__
|
||||||
|
#include <stdlib.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
20
include/wx/msw/wince/net.h
Normal file
20
include/wx/msw/wince/net.h
Normal file
@@ -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) ;
|
||||||
|
|
@@ -52,7 +52,16 @@
|
|||||||
# define _GSocket_Disable_Events(socket)
|
# define _GSocket_Disable_Events(socket)
|
||||||
#endif /* wxUSE_GUI */
|
#endif /* wxUSE_GUI */
|
||||||
|
|
||||||
|
#ifndef __WXWINCE__
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#else
|
||||||
|
#define assert(x)
|
||||||
|
#ifndef isdigit
|
||||||
|
#define isdigit(x) (x > 47 && x < 58)
|
||||||
|
#endif
|
||||||
|
#include "wx/msw/wince/net.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@@ -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.
|
* 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 */
|
# pragma warning(disable:4115) /* named type definition in parentheses */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* This needs to be before the wx/defs/h inclusion
|
||||||
|
* for some reason
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef __WXWINCE__
|
||||||
|
#include <windows.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef __GSOCKET_STANDALONE__
|
#ifndef __GSOCKET_STANDALONE__
|
||||||
#include "wx/defs.h"
|
#include "wx/defs.h"
|
||||||
#include "wx/setup.h"
|
#include "wx/setup.h"
|
||||||
@@ -46,7 +62,14 @@
|
|||||||
|
|
||||||
#endif /* __GSOCKET_STANDALONE__ */
|
#endif /* __GSOCKET_STANDALONE__ */
|
||||||
|
|
||||||
|
#ifndef __WXWINCE__
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#else
|
||||||
|
#define assert(x)
|
||||||
|
#include <winsock.h>
|
||||||
|
#include "wx/msw/wince/net.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@@ -36,7 +36,7 @@
|
|||||||
#include "wx/msw/private.h" // includes <windows.h>
|
#include "wx/msw/private.h" // includes <windows.h>
|
||||||
#include "wx/msw/missing.h" // CHARSET_HANGUL
|
#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
|
// apparently we need to include winsock.h to get WSADATA and other stuff
|
||||||
// used in wxGetFullHostName() with the old mingw32 versions
|
// used in wxGetFullHostName() with the old mingw32 versions
|
||||||
#include <winsock.h>
|
#include <winsock.h>
|
||||||
@@ -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
|
// shouldn't use winsock.dll (a.k.a. ws2_32.dll) at all so only use this
|
||||||
// code if we link with it anyhow
|
// code if we link with it anyhow
|
||||||
#if wxUSE_SOCKETS
|
#if wxUSE_SOCKETS
|
||||||
|
|
||||||
WSADATA wsa;
|
WSADATA wsa;
|
||||||
if ( WSAStartup(MAKEWORD(1, 1), &wsa) == 0 )
|
if ( WSAStartup(MAKEWORD(1, 1), &wsa) == 0 )
|
||||||
{
|
{
|
||||||
|
167
src/msw/wince/net.cpp
Normal file
167
src/msw/wince/net.cpp
Normal file
@@ -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 <windows.h>
|
||||||
|
#include <tchar.h>
|
||||||
|
#include <winsock.h>
|
||||||
|
#include <string.h>
|
||||||
|
#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;
|
||||||
|
}
|
||||||
|
|
Reference in New Issue
Block a user