]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/wince/net.cpp
   1 /////////////////////////////////////////////////////////////////////////////// 
   2 // Name:        src/msw/wince/net.cpp 
   8 // Copyright:   Copyright 1998, Ben Goetter.  All rights reserved. 
   9 // Licence:     wxWindows licence 
  10 /////////////////////////////////////////////////////////////////////////////// 
  13  patch holes in winsock 
  15   WCE 2.0 lacks many of the 'database' winsock routines. 
  16   Stub just enough them for ss.dll. 
  24 // For compilers that support precompilation, includes "wx.h". 
  25 #include "wx/wxprec.h" 
  32     #include "wx/msw/wrapwin.h" 
  38 #include "wx/msw/wince/net.h" 
  41 #define CCH_MAX_PROTO 4 
  43 static struct protoent RgProtoEnt
[] = 
  46  { "udp", {NULL
}, 17 }, 
  47  { "icmp", {NULL
}, 1 }, 
  53 #define CCH_MAX_SERV 8 
  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. 
  58 // Should that be no longer the case, 
  59 // remove the fFoundOnce code from getservbyXxx fcns. 
  61 // This table keeps port numbers in host byte order. 
  63 static struct servent RgServEnt
[] = 
  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 
} 
  93 // Since table kept in host byte order, 
  94 // return this element to callers 
  96 static struct servent ServEntReturn 
= {0}; 
  98 // Because CE doesn't have _stricmp - that's why. 
 100 static void strcpyLC(char* szDst
, const char* szSrc
, int cch
) 
 104  for (i 
= 0, ch 
= szSrc
[i
]; i 
< cch 
&& ch 
!= 0; ch 
= szSrc
[++i
]) 
 106   szDst
[i
] = (ch 
>= 'A' && ch 
<= 'Z') ? (ch 
+ ('a'-'A')) : ch
; 
 111 struct servent 
* WINSOCKAPI 
getservbyport(int port
, const char * proto
) 
 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 
 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]; 
 122   strcpyLC(szProtoLC
, proto
, CCH_MAX_PROTO
+1); 
 124  while (NULL 
!= ps
->s_name
) 
 126   if (port 
== ps
->s_port
) 
 129    if (NULL 
== proto 
|| !strcmp(szProtoLC
, ps
->s_proto
)) 
 132     ServEntReturn
.s_port 
= htons(ps
->s_port
); 
 133     return &ServEntReturn
; 
 143 struct servent 
* WINSOCKAPI 
getservbyname(const char * name
, 
 146  struct servent 
*ps 
= &RgServEnt
[0]; 
 147  BOOL fFoundOnce 
= FALSE
; // flag to short-circuit search through rest of db 
 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]; 
 155   strcpyLC(szProtoLC
, proto
, CCH_MAX_PROTO
+1); 
 157  while (NULL 
!= ps
->s_name
) 
 159   if (!strcmp(szNameLC
, ps
->s_name
)) 
 162    if (NULL 
== proto 
|| !strcmp(szProtoLC
, ps
->s_proto
)) 
 165     ServEntReturn
.s_port 
= htons(ps
->s_port
); 
 166     return &ServEntReturn
; 
 176 struct protoent 
* WINSOCKAPI 
getprotobynumber(int proto
) 
 178  struct protoent 
*pr 
= &RgProtoEnt
[0]; 
 179  while (NULL 
!= pr
->p_name
) 
 181   if (proto 
== pr
->p_proto
)