]>
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 #include "wx/msw/wrapwin.h" 
  19 #include "wx/msw/wince/net.h" 
  22 #define CCH_MAX_PROTO 4 
  24 static struct protoent RgProtoEnt
[] = 
  27  { "udp", {NULL
}, 17 }, 
  28  { "icmp", {NULL
}, 1 }, 
  34 #define CCH_MAX_SERV 8 
  36 // Ordered by most likely to be requested. 
  37 // Assumes that a service available on different protocols 
  38 // will use the same port number on each protocol. 
  39 // Should that be no longer the case,  
  40 // remove the fFoundOnce code from getservbyXxx fcns. 
  42 // This table keeps port numbers in host byte order. 
  44 static struct servent RgServEnt
[] = 
  46  { "ftp", {NULL
}, 21, "tcp" }, 
  47  { "ftp-data", {NULL
}, 20, "tcp" }, 
  48  { "telnet", {NULL
}, 23, "tcp" }, 
  49  { "smtp", {NULL
}, 25, "tcp" }, 
  50  { "http", {NULL
}, 80, "tcp" }, 
  51  { "http", {NULL
}, 80, "udp" }, 
  52  { "pop", {NULL
}, 109, "tcp" }, 
  53  { "pop2", {NULL
}, 109, "tcp" }, 
  54  { "pop3", {NULL
}, 110, "tcp" }, 
  55  { "nntp", {NULL
}, 119, "tcp" }, 
  56  { "finger", {NULL
}, 79, "tcp" }, 
  57  /* include most of the simple TCP services for testing */ 
  58  { "echo", {NULL
}, 7, "tcp" }, 
  59  { "echo", {NULL
}, 7, "udp" }, 
  60  { "discard", {NULL
}, 9, "tcp" }, 
  61  { "discard", {NULL
}, 9, "udp" }, 
  62  { "chargen", {NULL
}, 19, "tcp" }, 
  63  { "chargen", {NULL
}, 19, "udp" }, 
  64  { "systat", {NULL
}, 11, "tcp" }, 
  65  { "systat", {NULL
}, 11, "udp" }, 
  66  { "daytime", {NULL
}, 13, "tcp" }, 
  67  { "daytime", {NULL
}, 13, "udp" }, 
  68  { "netstat", {NULL
}, 15, "tcp" }, 
  69  { "qotd", {NULL
}, 17, "tcp" }, 
  70  { "qotd", {NULL
}, 17, "udp" }, 
  71  { NULL
, {NULL
}, 0, NULL 
} 
  74 // Since table kept in host byte order, 
  75 // return this element to callers 
  77 static struct servent ServEntReturn 
= {0}; 
  79 // Because CE doesn't have _stricmp - that's why. 
  81 static void strcpyLC(char* szDst
, const char* szSrc
, int cch
) 
  85  for (i 
= 0, ch 
= szSrc
[i
]; i 
< cch 
&& ch 
!= 0; ch 
= szSrc
[++i
]) 
  87   szDst
[i
] = (ch 
>= 'A' && ch 
<= 'Z') ? (ch 
+ ('a'-'A')) : ch
; 
  92 struct servent 
* WINSOCKAPI 
getservbyport(int port
, const char * proto
) 
  95  port 
= ntohs((unsigned short)port
); // arrives in network byte order 
  96  struct servent 
*ps 
= &RgServEnt
[0]; 
  97  BOOL fFoundOnce 
= FALSE
; // flag to short-circuit search through rest of db 
  99  // Make a lowercase version for comparison 
 100  // truncate to 1 char longer than any value in table 
 101  char szProtoLC
[CCH_MAX_PROTO
+2]; 
 103   strcpyLC(szProtoLC
, proto
, CCH_MAX_PROTO
+1); 
 105  while (NULL 
!= ps
->s_name
) 
 107   if (port 
== ps
->s_port
) 
 110    if (NULL 
== proto 
|| !strcmp(szProtoLC
, ps
->s_proto
)) 
 113     ServEntReturn
.s_port 
= htons(ps
->s_port
); 
 114     return &ServEntReturn
; 
 124 struct servent 
* WINSOCKAPI 
getservbyname(const char * name
, 
 127  struct servent 
*ps 
= &RgServEnt
[0]; 
 128  BOOL fFoundOnce 
= FALSE
; // flag to short-circuit search through rest of db 
 130  // Make lowercase versions for comparisons 
 131  // truncate to 1 char longer than any value in table 
 132  char szNameLC
[CCH_MAX_SERV
+2]; 
 133  strcpyLC(szNameLC
, name
, CCH_MAX_SERV
+1); 
 134  char szProtoLC
[CCH_MAX_PROTO
+2]; 
 136   strcpyLC(szProtoLC
, proto
, CCH_MAX_PROTO
+1); 
 138  while (NULL 
!= ps
->s_name
) 
 140   if (!strcmp(szNameLC
, ps
->s_name
)) 
 143    if (NULL 
== proto 
|| !strcmp(szProtoLC
, ps
->s_proto
)) 
 146     ServEntReturn
.s_port 
= htons(ps
->s_port
); 
 147     return &ServEntReturn
; 
 157 struct protoent 
* WINSOCKAPI 
getprotobynumber(int proto
) 
 159  struct protoent 
*pr 
= &RgProtoEnt
[0]; 
 160  while (NULL 
!= pr
->p_name
) 
 162   if (proto 
== pr
->p_proto
)