1/////////////////////////////////////////////////////////////////////////////// 2// Name: src/msw/wince/net.cpp 3// Purpose: 4// Author: 5// Modified by: 6// Created: 7// RCS-ID: $Id: net.cpp 58995 2009-02-18 15:58:25Z JS $ 8// Copyright: Copyright 1998, Ben Goetter. All rights reserved. 9// Licence: wxWindows licence 10/////////////////////////////////////////////////////////////////////////////// 11 12/* 13 patch holes in winsock 14 15 WCE 2.0 lacks many of the 'database' winsock routines. 16 Stub just enough them for ss.dll. 17 18 getprotobynumber 19 getservbyport 20 getservbyname 21 22Subject: Re: Could you provide a license for your wxWidgets v2.6.2 files 23From: Ben Goetter <goetter@mazama.net> 24Date: Wed, 22 Mar 2006 09:58:32 -0800 25To: Julian Smart <julian@anthemion.co.uk> 26Return-Path: <goetter@mazama.net> 27Delivered-To: jsmart@gotadsl.co.uk 28Envelope-To: jsmart@gotadsl.co.uk 29Received: (qmail 6858 invoked from network); 22 Mar 2006 17:58:46 -0000 30Received: from unknown (HELO as004.apm-internet.net) (85.119.248.22) by mail001.apm-internet.net with SMTP; 22 Mar 2006 17:58:46 -0000 31Received: (qmail 47565 invoked from network); 22 Mar 2006 17:58:46 -0000 32X-Spam-Score: 0.1 33X-Spam-Checker-Version: SpamAssassin 3.1.0 (2005-09-13) on as004.apm-internet.net 34X-Spam-Report: * 0.1 AWL AWL: From: address is in the auto white-list 35Received: from unknown (HELO av004.apm-internet.net) (85.119.248.18) by as004.apm-internet.net with SMTP; 22 Mar 2006 17:58:46 -0000 36Received: (qmail 33684 invoked by uid 1013); 22 Mar 2006 17:58:44 -0000 37Received: from unknown (HELO relay002.apm-internet.net) (85.119.248.12) by av004.apm-internet.net with SMTP; 22 Mar 2006 17:58:44 -0000 38Received: (qmail 4919 invoked from network); 22 Mar 2006 17:58:43 -0000 39Received: from unknown (HELO mini-131.dolphin-server.co.uk) (80.87.138.131) by relay002.apm-internet.net with SMTP; 22 Mar 2006 17:58:44 -0000 40Received: (qmail 28982 invoked by uid 64020); 22 Mar 2006 09:59:50 -0000 41Delivered-To: anthemion.co.uk-julian@anthemion.co.uk 42Received: (qmail 28980 invoked from network); 22 Mar 2006 09:59:50 -0000 43Received: from unknown (HELO bgkh-household.seattle.mazama.net) (216.231.59.183) by mini-131.dolphin-server.co.uk with SMTP; 22 Mar 2006 09:59:50 -0000 44Received: from [192.168.0.128] (dhcp128.seattle.mazama.net [192.168.0.128]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by bgkh-household.seattle.mazama.net (Postfix) with ESMTP id 5AE2417020 for <julian@anthemion.co.uk>; Wed, 22 Mar 2006 09:58:42 -0800 (PST) 45Message-ID: <44219048.9020000@mazama.net> 46User-Agent: Thunderbird 1.5 (Windows/20051201) 47MIME-Version: 1.0 48References: <8C8EF65853BB6842809053B779B8CAB70E416E95@emss07m14.us.lmco.com> <4420DD8C.6090405@mazama.net> <6.2.1.2.2.20060322091301.0315cc90@pop3.gotadsl.co.uk> 49In-Reply-To: <6.2.1.2.2.20060322091301.0315cc90@pop3.gotadsl.co.uk> 50Content-Type: text/plain; charset=ISO-8859-1; format=flowed 51Content-Transfer-Encoding: 8bit 52X-Anti-Virus: Kaspersky Anti-Virus for MailServers 5.5.3/RELEASE, bases: 22032006 #172373, status: clean 53 54Certainly. 55 56I hereby release the text of those three functions -- getprotobynumber, getservbyport, and getservbyname, as found in wxWidgets-2.6.2\include\wx\msw\wince\net.h and wxWidgets-2.6.2\src\msw\wince\net.cpp -- under the wxWindows license. Please feel free to replace "All rights reserved." with "Licensed under the wxWindows License" or equivalent boilerplate. 57 58Absolutely no problem, 59Ben 60 61 62Julian Smart wrote: 63> Hi Ben, 64> 65> Thanks a lot for the clarification, and indeed for the code! Apologies if 66> we didn't ask for permission to use those functions. 67> 68> Would it be possible to have these 3 functions licensed under 69> the wxWindows License as well? This would simplify the legal 70> position for us rather than having multiple licenses. The wxWindows 71> License is here: 72> 73> http://www.wxwidgets.org/newlicen.htm 74> 75> Best regards, 76> 77> Julian 78 79 80*/ 81 82// For compilers that support precompilation, includes "wx.h". 83#include "wx/wxprec.h" 84 85#ifdef __BORLANDC__ 86 #pragma hdrstop 87#endif 88 89#ifndef WX_PRECOMP 90 #include "wx/msw/wrapwin.h" 91#endif 92 93#include <tchar.h> 94#include <winsock.h> 95#include <string.h> 96#include "wx/msw/wince/net.h" 97 98 99#define CCH_MAX_PROTO 4 100 101static struct protoent RgProtoEnt[] = 102{ 103 { "tcp", {NULL}, 6 }, 104 { "udp", {NULL}, 17 }, 105 { "icmp", {NULL}, 1 }, 106 { "ip", {NULL}, 0 }, 107 { NULL, {NULL}, 0 } 108}; 109 110 111#define CCH_MAX_SERV 8 112 113// Ordered by most likely to be requested. 114// Assumes that a service available on different protocols 115// will use the same port number on each protocol. 116// Should that be no longer the case, 117// remove the fFoundOnce code from getservbyXxx fcns. 118 119// This table keeps port numbers in host byte order. 120 121static struct servent RgServEnt[] = 122{ 123 { "ftp", {NULL}, 21, "tcp" }, 124 { "ftp-data", {NULL}, 20, "tcp" }, 125 { "telnet", {NULL}, 23, "tcp" }, 126 { "smtp", {NULL}, 25, "tcp" }, 127 { "http", {NULL}, 80, "tcp" }, 128 { "http", {NULL}, 80, "udp" }, 129 { "pop", {NULL}, 109, "tcp" }, 130 { "pop2", {NULL}, 109, "tcp" }, 131 { "pop3", {NULL}, 110, "tcp" }, 132 { "nntp", {NULL}, 119, "tcp" }, 133 { "finger", {NULL}, 79, "tcp" }, 134 /* include most of the simple TCP services for testing */ 135 { "echo", {NULL}, 7, "tcp" }, 136 { "echo", {NULL}, 7, "udp" }, 137 { "discard", {NULL}, 9, "tcp" }, 138 { "discard", {NULL}, 9, "udp" }, 139 { "chargen", {NULL}, 19, "tcp" }, 140 { "chargen", {NULL}, 19, "udp" }, 141 { "systat", {NULL}, 11, "tcp" }, 142 { "systat", {NULL}, 11, "udp" }, 143 { "daytime", {NULL}, 13, "tcp" }, 144 { "daytime", {NULL}, 13, "udp" }, 145 { "netstat", {NULL}, 15, "tcp" }, 146 { "qotd", {NULL}, 17, "tcp" }, 147 { "qotd", {NULL}, 17, "udp" }, 148 { NULL, {NULL}, 0, NULL } 149}; 150 151// Since table kept in host byte order, 152// return this element to callers 153 154static struct servent ServEntReturn = {0}; 155 156// Because CE doesn't have _stricmp - that's why. 157 158static void strcpyLC(char* szDst, const char* szSrc, int cch) 159{ 160 int i; 161 char ch; 162 for (i = 0, ch = szSrc[i]; i < cch && ch != 0; ch = szSrc[++i]) 163 { 164 szDst[i] = (ch >= 'A' && ch <= 'Z') ? (ch + ('a'-'A')) : ch; 165 } szDst[i] = 0; 166} 167 168 169struct servent * WINSOCKAPI getservbyport(int port, const char * proto) 170{ 171 172 port = ntohs((unsigned short)port); // arrives in network byte order 173 struct servent *ps = &RgServEnt[0]; 174 BOOL fFoundOnce = FALSE; // flag to short-circuit search through rest of db 175 176 // Make a lowercase version for comparison 177 // truncate to 1 char longer than any value in table 178 char szProtoLC[CCH_MAX_PROTO+2]; 179 if (NULL != proto) 180 strcpyLC(szProtoLC, proto, CCH_MAX_PROTO+1); 181 182 while (NULL != ps->s_name) 183 { 184 if (port == ps->s_port) 185 { 186 fFoundOnce = TRUE; 187 if (NULL == proto || !strcmp(szProtoLC, ps->s_proto)) 188 { 189 ServEntReturn = *ps; 190 ServEntReturn.s_port = htons(ps->s_port); 191 return &ServEntReturn; 192 } 193 } 194 else if (fFoundOnce) 195 break; 196 ++ps; 197 } return NULL; 198} 199 200 201struct servent * WINSOCKAPI getservbyname(const char * name, 202 const char * proto) 203{ 204 struct servent *ps = &RgServEnt[0]; 205 BOOL fFoundOnce = FALSE; // flag to short-circuit search through rest of db 206 207 // Make lowercase versions for comparisons 208 // truncate to 1 char longer than any value in table 209 char szNameLC[CCH_MAX_SERV+2]; 210 strcpyLC(szNameLC, name, CCH_MAX_SERV+1); 211 char szProtoLC[CCH_MAX_PROTO+2]; 212 if (NULL != proto) 213 strcpyLC(szProtoLC, proto, CCH_MAX_PROTO+1); 214 215 while (NULL != ps->s_name) 216 { 217 if (!strcmp(szNameLC, ps->s_name)) 218 { 219 fFoundOnce = TRUE; 220 if (NULL == proto || !strcmp(szProtoLC, ps->s_proto)) 221 { 222 ServEntReturn = *ps; 223 ServEntReturn.s_port = htons(ps->s_port); 224 return &ServEntReturn; 225 } 226 } 227 else if (fFoundOnce) 228 break; 229 ++ps; 230 } return NULL; 231} 232 233 234struct protoent * WINSOCKAPI getprotobynumber(int proto) 235{ 236 struct protoent *pr = &RgProtoEnt[0]; 237 while (NULL != pr->p_name) 238 { 239 if (proto == pr->p_proto) 240 return pr; 241 ++pr; 242 } return NULL; 243} 244