]>
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 // For compilers that support precompilation, includes "wx.h". 
  16 #include "wx/wxprec.h" 
  22 #include "wx/msw/wrapwin.h" 
  26 #include "wx/msw/wince/net.h" 
  29 #define CCH_MAX_PROTO 4 
  31 static struct protoent RgProtoEnt
[] = 
  34  { "udp", {NULL
}, 17 }, 
  35  { "icmp", {NULL
}, 1 }, 
  41 #define CCH_MAX_SERV 8 
  43 // Ordered by most likely to be requested. 
  44 // Assumes that a service available on different protocols 
  45 // will use the same port number on each protocol. 
  46 // Should that be no longer the case, 
  47 // remove the fFoundOnce code from getservbyXxx fcns. 
  49 // This table keeps port numbers in host byte order. 
  51 static struct servent RgServEnt
[] = 
  53  { "ftp", {NULL
}, 21, "tcp" }, 
  54  { "ftp-data", {NULL
}, 20, "tcp" }, 
  55  { "telnet", {NULL
}, 23, "tcp" }, 
  56  { "smtp", {NULL
}, 25, "tcp" }, 
  57  { "http", {NULL
}, 80, "tcp" }, 
  58  { "http", {NULL
}, 80, "udp" }, 
  59  { "pop", {NULL
}, 109, "tcp" }, 
  60  { "pop2", {NULL
}, 109, "tcp" }, 
  61  { "pop3", {NULL
}, 110, "tcp" }, 
  62  { "nntp", {NULL
}, 119, "tcp" }, 
  63  { "finger", {NULL
}, 79, "tcp" }, 
  64  /* include most of the simple TCP services for testing */ 
  65  { "echo", {NULL
}, 7, "tcp" }, 
  66  { "echo", {NULL
}, 7, "udp" }, 
  67  { "discard", {NULL
}, 9, "tcp" }, 
  68  { "discard", {NULL
}, 9, "udp" }, 
  69  { "chargen", {NULL
}, 19, "tcp" }, 
  70  { "chargen", {NULL
}, 19, "udp" }, 
  71  { "systat", {NULL
}, 11, "tcp" }, 
  72  { "systat", {NULL
}, 11, "udp" }, 
  73  { "daytime", {NULL
}, 13, "tcp" }, 
  74  { "daytime", {NULL
}, 13, "udp" }, 
  75  { "netstat", {NULL
}, 15, "tcp" }, 
  76  { "qotd", {NULL
}, 17, "tcp" }, 
  77  { "qotd", {NULL
}, 17, "udp" }, 
  78  { NULL
, {NULL
}, 0, NULL 
} 
  81 // Since table kept in host byte order, 
  82 // return this element to callers 
  84 static struct servent ServEntReturn 
= {0}; 
  86 // Because CE doesn't have _stricmp - that's why. 
  88 static void strcpyLC(char* szDst
, const char* szSrc
, int cch
) 
  92  for (i 
= 0, ch 
= szSrc
[i
]; i 
< cch 
&& ch 
!= 0; ch 
= szSrc
[++i
]) 
  94   szDst
[i
] = (ch 
>= 'A' && ch 
<= 'Z') ? (ch 
+ ('a'-'A')) : ch
; 
  99 struct servent 
* WINSOCKAPI 
getservbyport(int port
, const char * proto
) 
 102  port 
= ntohs((unsigned short)port
); // arrives in network byte order 
 103  struct servent 
*ps 
= &RgServEnt
[0]; 
 104  BOOL fFoundOnce 
= FALSE
; // flag to short-circuit search through rest of db 
 106  // Make a lowercase version for comparison 
 107  // truncate to 1 char longer than any value in table 
 108  char szProtoLC
[CCH_MAX_PROTO
+2]; 
 110   strcpyLC(szProtoLC
, proto
, CCH_MAX_PROTO
+1); 
 112  while (NULL 
!= ps
->s_name
) 
 114   if (port 
== ps
->s_port
) 
 117    if (NULL 
== proto 
|| !strcmp(szProtoLC
, ps
->s_proto
)) 
 120     ServEntReturn
.s_port 
= htons(ps
->s_port
); 
 121     return &ServEntReturn
; 
 131 struct servent 
* WINSOCKAPI 
getservbyname(const char * name
, 
 134  struct servent 
*ps 
= &RgServEnt
[0]; 
 135  BOOL fFoundOnce 
= FALSE
; // flag to short-circuit search through rest of db 
 137  // Make lowercase versions for comparisons 
 138  // truncate to 1 char longer than any value in table 
 139  char szNameLC
[CCH_MAX_SERV
+2]; 
 140  strcpyLC(szNameLC
, name
, CCH_MAX_SERV
+1); 
 141  char szProtoLC
[CCH_MAX_PROTO
+2]; 
 143   strcpyLC(szProtoLC
, proto
, CCH_MAX_PROTO
+1); 
 145  while (NULL 
!= ps
->s_name
) 
 147   if (!strcmp(szNameLC
, ps
->s_name
)) 
 150    if (NULL 
== proto 
|| !strcmp(szProtoLC
, ps
->s_proto
)) 
 153     ServEntReturn
.s_port 
= htons(ps
->s_port
); 
 154     return &ServEntReturn
; 
 164 struct protoent 
* WINSOCKAPI 
getprotobynumber(int proto
) 
 166  struct protoent 
*pr 
= &RgProtoEnt
[0]; 
 167  while (NULL 
!= pr
->p_name
) 
 169   if (proto 
== pr
->p_proto
)