From c84cc55299b07c36cf78a6aa9b14410aeea2a4ef Mon Sep 17 00:00:00 2001 From: proff_fs Date: Wed, 29 Jan 2003 16:30:47 +0000 Subject: [PATCH] Moved msvc6 project files to contrib module. --- ports/msvc6/include/arch/cc.h | 1 + ports/msvc6/include/arch/lib.h | 7 +- ports/msvc6/lwip4.dsp | 232 +++++++++++++++ ports/msvc6/lwipopts.h | 168 +++++++++++ ports/msvc6/pktif.c | 524 +++++++++++++++++++++++++++++++++ ports/msvc6/pktif.dsp | 104 +++++++ ports/msvc6/readme.txt | 29 ++ ports/msvc6/test.c | 216 ++++++++++++++ ports/msvc6/test.dsp | 8 +- ports/msvc6/test.dsw | 4 +- 10 files changed, 1281 insertions(+), 12 deletions(-) create mode 100644 ports/msvc6/lwip4.dsp create mode 100644 ports/msvc6/lwipopts.h create mode 100644 ports/msvc6/pktif.c create mode 100644 ports/msvc6/pktif.dsp create mode 100644 ports/msvc6/readme.txt create mode 100644 ports/msvc6/test.c diff --git a/ports/msvc6/include/arch/cc.h b/ports/msvc6/include/arch/cc.h index feca930..87fb3ba 100644 --- a/ports/msvc6/include/arch/cc.h +++ b/ports/msvc6/include/arch/cc.h @@ -46,5 +46,6 @@ typedef u32_t mem_ptr_t; #define PACK_STRUCT_FIELD(x) x #define PACK_STRUCT_STRUCT #pragma warning(disable: 4103) +#define PACK_STRUCT_USE_INCLUDES #endif /* __ARCH_CC_H__ */ diff --git a/ports/msvc6/include/arch/lib.h b/ports/msvc6/include/arch/lib.h index 081796e..f84de67 100644 --- a/ports/msvc6/include/arch/lib.h +++ b/ports/msvc6/include/arch/lib.h @@ -32,11 +32,6 @@ #ifndef __ARCH_LIB_H__ #define __ARCH_LIB_H__ -#ifndef _STRING_H_ -#ifndef _STRING_H -int strlen(const char *str); -int strncmp(const char *str1, const char *str2, int len); -#endif /* _STRING_H */ -#endif /* _STRING_H_ */ +#include #endif /* __ARCH_LIB_H__ */ diff --git a/ports/msvc6/lwip4.dsp b/ports/msvc6/lwip4.dsp new file mode 100644 index 0000000..acd379a --- /dev/null +++ b/ports/msvc6/lwip4.dsp @@ -0,0 +1,232 @@ +# Microsoft Developer Studio Project File - Name="lwip4" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** NICHT BEARBEITEN ** + +# TARGTYPE "Win32 (x86) Static Library" 0x0104 + +CFG=lwip4 - Win32 Debug +!MESSAGE Dies ist kein gültiges Makefile. Zum Erstellen dieses Projekts mit NMAKE +!MESSAGE verwenden Sie den Befehl "Makefile exportieren" und führen Sie den Befehl +!MESSAGE +!MESSAGE NMAKE /f "lwip4.mak". +!MESSAGE +!MESSAGE Sie können beim Ausführen von NMAKE eine Konfiguration angeben +!MESSAGE durch Definieren des Makros CFG in der Befehlszeile. Zum Beispiel: +!MESSAGE +!MESSAGE NMAKE /f "lwip4.mak" CFG="lwip4 - Win32 Debug" +!MESSAGE +!MESSAGE Für die Konfiguration stehen zur Auswahl: +!MESSAGE +!MESSAGE "lwip4 - Win32 Release" (basierend auf "Win32 (x86) Static Library") +!MESSAGE "lwip4 - Win32 Debug" (basierend auf "Win32 (x86) Static Library") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +RSC=rc.exe + +!IF "$(CFG)" == "lwip4 - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release" +# PROP Intermediate_Dir "Release" +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c +# ADD CPP /nologo /W3 /GX /O2 /I "$(LWIP_SRC)\include" /I "$(LWIP_SRC)\include\ipv4" /I ".\include" /I ".\\" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c +# ADD BASE RSC /l 0x407 /d "NDEBUG" +# ADD RSC /l 0x407 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LIB32=link.exe -lib +# ADD BASE LIB32 /nologo +# ADD LIB32 /nologo + +!ELSEIF "$(CFG)" == "lwip4 - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Debug" +# PROP Intermediate_Dir "Debug" +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c +# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "$(LWIP_SRC)\include" /I "$(LWIP_SRC)\include\ipv4" /I ".\include" /I ".\\" /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c +# ADD BASE RSC /l 0x407 /d "_DEBUG" +# ADD RSC /l 0x407 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LIB32=link.exe -lib +# ADD BASE LIB32 /nologo +# ADD LIB32 /nologo /out:"Debug\lwip4_d.lib" + +!ENDIF + +# Begin Target + +# Name "lwip4 - Win32 Release" +# Name "lwip4 - Win32 Debug" +# Begin Group "Quellcodedateien" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE="$(LWIP_SRC)\core\ipv4\icmp.c" +# End Source File +# Begin Source File + +SOURCE="$(LWIP_SRC)\core\inet.c" +# End Source File +# Begin Source File + +SOURCE="$(LWIP_SRC)\core\ipv4\ip.c" +# End Source File +# Begin Source File + +SOURCE="$(LWIP_SRC)\core\ipv4\ip_addr.c" +# End Source File +# Begin Source File + +SOURCE="$(LWIP_SRC)\core\mem.c" +# End Source File +# Begin Source File + +SOURCE="$(LWIP_SRC)\core\memp.c" +# End Source File +# Begin Source File + +SOURCE="$(LWIP_SRC)\core\netif.c" +# End Source File +# Begin Source File + +SOURCE="$(LWIP_SRC)\core\pbuf.c" +# End Source File +# Begin Source File + +SOURCE="$(LWIP_SRC)\core\stats.c" +# End Source File +# Begin Source File + +SOURCE="$(LWIP_SRC)\core\sys.c" +# End Source File +# Begin Source File + +SOURCE="$(LWIP_SRC)\core\tcp.c" +# End Source File +# Begin Source File + +SOURCE="$(LWIP_SRC)\core\tcp_in.c" +# End Source File +# Begin Source File + +SOURCE="$(LWIP_SRC)\core\tcp_out.c" +# End Source File +# Begin Source File + +SOURCE="$(LWIP_SRC)\core\udp.c" +# End Source File +# End Group +# Begin Group "Header-Dateien" + +# PROP Default_Filter "h;hpp;hxx;hm;inl" +# Begin Source File + +SOURCE="$(LWIP_SRC)\include\lwip\api.h" +# End Source File +# Begin Source File + +SOURCE="$(LWIP_SRC)\include\lwip\api_msg.h" +# End Source File +# Begin Source File + +SOURCE="$(LWIP_SRC)\include\lwip\arch.h" +# End Source File +# Begin Source File + +SOURCE="$(LWIP_SRC)\include\lwip\debug.h" +# End Source File +# Begin Source File + +SOURCE="$(LWIP_SRC)\include\lwip\def.h" +# End Source File +# Begin Source File + +SOURCE="$(LWIP_SRC)\include\lwip\err.h" +# End Source File +# Begin Source File + +SOURCE="$(LWIP_SRC)\include\lwip\event.h" +# End Source File +# Begin Source File + +SOURCE="$(LWIP_SRC)\include\ipv4\lwip\icmp.h" +# End Source File +# Begin Source File + +SOURCE="$(LWIP_SRC)\include\ipv4\lwip\inet.h" +# End Source File +# Begin Source File + +SOURCE="$(LWIP_SRC)\include\ipv4\lwip\ip.h" +# End Source File +# Begin Source File + +SOURCE="$(LWIP_SRC)\include\ipv4\lwip\ip_addr.h" +# End Source File +# Begin Source File + +SOURCE=..\lwipopts.h +# End Source File +# Begin Source File + +SOURCE="$(LWIP_SRC)\include\lwip\mem.h" +# End Source File +# Begin Source File + +SOURCE="$(LWIP_SRC)\include\lwip\memp.h" +# End Source File +# Begin Source File + +SOURCE="$(LWIP_SRC)\include\lwip\netif.h" +# End Source File +# Begin Source File + +SOURCE="$(LWIP_SRC)\include\lwip\opt.h" +# End Source File +# Begin Source File + +SOURCE="$(LWIP_SRC)\include\lwip\pbuf.h" +# End Source File +# Begin Source File + +SOURCE="$(LWIP_SRC)\include\lwip\sys.h" +# End Source File +# Begin Source File + +SOURCE="$(LWIP_SRC)\include\lwip\tcp.h" +# End Source File +# Begin Source File + +SOURCE="$(LWIP_SRC)\include\lwip\tcpip.h" +# End Source File +# Begin Source File + +SOURCE="$(LWIP_SRC)\include\lwip\udp.h" +# End Source File +# End Group +# End Target +# End Project diff --git a/ports/msvc6/lwipopts.h b/ports/msvc6/lwipopts.h new file mode 100644 index 0000000..3fabbc5 --- /dev/null +++ b/ports/msvc6/lwipopts.h @@ -0,0 +1,168 @@ +/* + * Copyright (c) 2001-2003 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + */ +#ifndef __LWIPOPTS_H__ +#define __LWIPOPTS_H__ + +#define NO_SYS 1 +//#define LWIP_EVENT_API 1 + +/* ---------- Memory options ---------- */ +/* MEM_ALIGNMENT: should be set to the alignment of the CPU for which + lwIP is compiled. 4 byte alignment -> define MEM_ALIGNMENT to 4, 2 + byte alignment -> define MEM_ALIGNMENT to 2. */ +#define MEM_ALIGNMENT 2 + +/* MEM_SIZE: the size of the heap memory. If the application will send +a lot of data that needs to be copied, this should be set high. */ +#define MEM_SIZE 1000 + +/* MEMP_NUM_PBUF: the number of memp struct pbufs. If the application + sends a lot of data out of ROM (or other static memory), this + should be set high. */ +#define MEMP_NUM_PBUF 8 +/* MEMP_NUM_UDP_PCB: the number of UDP protocol control blocks. One + per active UDP "connection". */ +#define MEMP_NUM_UDP_PCB 4 +/* MEMP_NUM_TCP_PCB: the number of simulatenously active TCP + connections. */ +#define MEMP_NUM_TCP_PCB 2 +/* MEMP_NUM_TCP_PCB_LISTEN: the number of listening TCP + connections. */ +#define MEMP_NUM_TCP_PCB_LISTEN 8 +/* MEMP_NUM_TCP_SEG: the number of simultaneously queued TCP + segments. */ +#define MEMP_NUM_TCP_SEG 8 + +/* The following four are used only with the sequential API and can be + set to 0 if the application only will use the raw API. */ +/* MEMP_NUM_NETBUF: the number of struct netbufs. */ +#define MEMP_NUM_NETBUF 0 +/* MEMP_NUM_NETCONN: the number of struct netconns. */ +#define MEMP_NUM_NETCONN 0 +/* MEMP_NUM_APIMSG: the number of struct api_msg, used for + communication between the TCP/IP stack and the sequential + programs. */ +#define MEMP_NUM_API_MSG 0 +/* MEMP_NUM_TCPIPMSG: the number of struct tcpip_msg, which is used + for sequential API communication and incoming packets. Used in + src/api/tcpip.c. */ +#define MEMP_NUM_TCPIP_MSG 0 +/* MEMP_NUM_SYS_TIMEOUT: the number of simulateously active + timeouts. */ +#define MEMP_NUM_SYS_TIMEOUT 0 + +/* ---------- Pbuf options ---------- */ +/* PBUF_POOL_SIZE: the number of buffers in the pbuf pool. */ +#define PBUF_POOL_SIZE 8 + +/* PBUF_POOL_BUFSIZE: the size of each pbuf in the pbuf pool. */ +#define PBUF_POOL_BUFSIZE 128 + +/* PBUF_LINK_HLEN: the number of bytes that should be allocated for a + link level header. */ +#define PBUF_LINK_HLEN 16 + +/* ---------- TCP options ---------- */ +#define LWIP_TCP 1 +#define TCP_TTL 255 + +/* Controls if TCP should queue segments that arrive out of + order. Define to 0 if your device is low on memory. */ +#define TCP_QUEUE_OOSEQ 0 + +/* TCP Maximum segment size. */ +#define TCP_MSS 128 + +/* TCP sender buffer space (bytes). */ +#define TCP_SND_BUF 256 + +/* TCP sender buffer space (pbufs). This must be at least = 2 * + TCP_SND_BUF/TCP_MSS for things to work. */ +#define TCP_SND_QUEUELEN 4 * TCP_SND_BUF/TCP_MSS + +/* TCP receive window. */ +#define TCP_WND 512 + +/* Maximum number of retransmissions of data segments. */ +#define TCP_MAXRTX 12 + +/* Maximum number of retransmissions of SYN segments. */ +#define TCP_SYNMAXRTX 4 + +/* ---------- ARP options ---------- */ +#define ARP_TABLE_SIZE 10 + +/* ---------- IP options ---------- */ +/* Define IP_FORWARD to 1 if you wish to have the ability to forward + IP packets across network interfaces. If you are going to run lwIP + on a device with only one network interface, define this to 0. */ +#define IP_FORWARD 0 + +/* If defined to 1, IP options are allowed (but not parsed). If + defined to 0, all packets with IP options are dropped. */ +#define IP_OPTIONS 1 + +/* ---------- ICMP options ---------- */ +#define ICMP_TTL 255 + + +/* ---------- DHCP options ---------- */ +/* Define LWIP_DHCP to 1 if you want DHCP configuration of + interfaces. DHCP is not implemented in lwIP 0.5.1, however, so + turning this on does currently not work. */ +#define LWIP_DHCP 0 + +/* 1 if you want to do an ARP check on the offered address + (recommended). */ +#define DHCP_DOES_ARP_CHECK 1 + +/* ---------- UDP options ---------- */ +#define LWIP_UDP 0 +#define UDP_TTL 255 + + +/* ---------- Statistics options ---------- */ +/*#define STATS*/ + +#ifdef STATS +#define LINK_STATS +#define IP_STATS +#define ICMP_STATS +#define UDP_STATS +#define TCP_STATS +#define MEM_STATS +#define MEMP_STATS +#define PBUF_STATS +#define SYS_STATS +#endif /* STATS */ + +#endif /* __LWIPOPTS_H__ */ diff --git a/ports/msvc6/pktif.c b/ports/msvc6/pktif.c new file mode 100644 index 0000000..c36cb82 --- /dev/null +++ b/ports/msvc6/pktif.c @@ -0,0 +1,524 @@ +/* + * Copyright (c) 2001,2002 Florian Schulze. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the authors nor the names of the contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * pktif.c - This file is part of lwIPtest + * + **************************************************************************** + * + * This file is derived from an example in lwIP with the following license: + * + * Copyright (c) 2001, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + */ + +#define WIN32_LEAN_AND_MEAN +#include +#include +#include +#include +#include + +#include "lwip/debug.h" + +#include "lwip/opt.h" +#include "lwip/def.h" +#include "lwip/mem.h" +#include "lwip/pbuf.h" +#include "lwip/stats.h" +#include "lwip/sys.h" +#include "lwip/ip.h" + +#include "netif/etharp.h" + +#undef NETIF_DEBUG + +/* Define those to better describe your network interface. */ +#define IFNAME0 'p' +#define IFNAME1 'k' + +struct ethernetif { + struct eth_addr *ethaddr; + /* Add whatever per-interface state that is needed here. */ +}; + +static const struct eth_addr ethbroadcast = {{0xff,0xff,0xff,0xff,0xff,0xff}}; + +/* Forward declarations. */ +static void ethernetif_input(struct netif *netif); +static err_t ethernetif_output(struct netif *netif, struct pbuf *p, + struct ip_addr *ipaddr); + +static struct netif *pktif_netif; + +LPADAPTER lpAdapter; +LPPACKET lpPacket; +char buffer[256000]; // buffer to hold the data coming from the driver +unsigned char *cur_packet; +int cur_length; + +struct eth_addr ethaddr; + +/*-----------------------------------------------------------------------------------*/ +int init_adapter(void) +{ + #define Max_Num_Adapter 10 + + char AdapterList[Max_Num_Adapter][1024]; + + int i; + DWORD dwVersion; + DWORD dwWindowsMajorVersion; + + //unicode strings (winnt) + WCHAR AdapterName[8192]; // string that contains a list of the network adapters + WCHAR *temp,*temp1; + + //ascii strings (win95) + char AdapterNamea[8192]; // string that contains a list of the network adapters + char *tempa,*temp1a; + + int AdapterNum=0; + ULONG AdapterLength; + + PPACKET_OID_DATA ppacket_oid_data; + + // obtain the name of the adapters installed on this machine + AdapterLength=4096; + + memset(AdapterList,0,sizeof(AdapterList)); + + i=0; + + // the data returned by PacketGetAdapterNames is different in Win95 and in WinNT. + // We have to check the os on which we are running + dwVersion=GetVersion(); + dwWindowsMajorVersion = (DWORD)(LOBYTE(LOWORD(dwVersion))); + if (!(dwVersion >= 0x80000000 && dwWindowsMajorVersion >= 4)) + { // Windows NT + if(PacketGetAdapterNames((char *)AdapterName,&AdapterLength)==FALSE){ + printf("Unable to retrieve the list of the adapters!\n"); + return -1; + } + temp=AdapterName; + temp1=AdapterName; + while ((*temp!='\0')||(*(temp-1)!='\0')) + { + if (*temp=='\0') + { + memcpy(AdapterList[i],temp1,(temp-temp1)*2); + temp1=temp+1; + i++; + } + + temp++; + } + + AdapterNum=i; + } + + else //windows 95 + { + if(PacketGetAdapterNames(AdapterNamea,&AdapterLength)==FALSE){ + printf("Unable to retrieve the list of the adapters!\n"); + return -1; + } + tempa=AdapterNamea; + temp1a=AdapterNamea; + + while ((*tempa!='\0')||(*(tempa-1)!='\0')) + { + if (*tempa=='\0') + { + memcpy(AdapterList[i],temp1a,tempa-temp1a); + temp1a=tempa+1; + i++; + } + tempa++; + } + + AdapterNum=i; + } + + if (AdapterNum<=0) + return -1; + + ppacket_oid_data=malloc(sizeof(PACKET_OID_DATA)+6); + lpAdapter=PacketOpenAdapter(AdapterList[0]); + if (!lpAdapter || (lpAdapter->hFile == INVALID_HANDLE_VALUE)) + return -1; + ppacket_oid_data->Oid=OID_802_3_PERMANENT_ADDRESS; + ppacket_oid_data->Length=6; + if (!PacketRequest(lpAdapter,FALSE,ppacket_oid_data)) + return -1; + memcpy(ppacket_oid_data->Data,ðaddr,6); + free(ppacket_oid_data); + PacketSetBuff(lpAdapter,512000); + PacketSetReadTimeout(lpAdapter,1); + PacketSetHwFilter(lpAdapter,NDIS_PACKET_TYPE_ALL_LOCAL); + if((lpPacket = PacketAllocatePacket())==NULL){ + return (-1); + } + PacketInitPacket(lpPacket,(char*)buffer,256000); + + return 0; +} + +void shutdown_adapter(void) +{ + struct ethernetif *ethernetif; + + ethernetif = pktif_netif->state; + + PacketFreePacket(lpPacket); + PacketCloseAdapter(lpAdapter); +} + +static void open_adapter(struct ethernetif *ethernetif) +{ + memcpy(ðaddr,ethernetif->ethaddr,6); +} + +/*-----------------------------------------------------------------------------------*/ +static void +low_level_init(struct netif *netif) +{ + struct ethernetif *ethernetif; + + ethernetif = netif->state; + + open_adapter(ethernetif); + +#ifdef NETIF_DEBUG + DEBUGF(NETIF_DEBUG, ("pktif: eth_addr %02X%02X%02X%02X%02X%02X\n",ethernetif->ethaddr->addr[0],ethernetif->ethaddr->addr[1],ethernetif->ethaddr->addr[2],ethernetif->ethaddr->addr[3],ethernetif->ethaddr->addr[4],ethernetif->ethaddr->addr[5])); +#endif /* NETIF_DEBUG */ + /* Do whatever else is needed to initialize interface. */ + + pktif_netif=netif; +} +/*-----------------------------------------------------------------------------------*/ +/* + * low_level_output(): + * + * Should do the actual transmission of the packet. The packet is + * contained in the pbuf that is passed to the function. This pbuf + * might be chained. + * + */ +/*-----------------------------------------------------------------------------------*/ + +static err_t +low_level_output(struct netif *ethernetif, struct pbuf *p) +{ + struct pbuf *q; + unsigned char buffer[1600]; + unsigned char *ptr; + LPPACKET lpPacket; + + /* initiate transfer(); */ + if (p->tot_len>=1600) + return ERR_BUF; + if((lpPacket = PacketAllocatePacket())==NULL) + return ERR_BUF; + PacketInitPacket(lpPacket,buffer,p->tot_len); + ptr=buffer; + for(q = p; q != NULL; q = q->next) { + /* Send the data from the pbuf to the interface, one pbuf at a + time. The size of the data in each pbuf is kept in the ->len + variable. */ + /* send data from(q->payload, q->len); */ +#ifdef NETIF_DEBUG + DEBUGF(NETIF_DEBUG, ("netif: send ptr %p q->payload %p q->len %i q->next %p\n", ptr, q->payload, (int)q->len, q->next)); +#endif + memcpy(ptr,q->payload,q->len); + ptr+=q->len; + } + + /* signal that packet should be sent(); */ + + if (!PacketSendPacket(lpAdapter,lpPacket,TRUE)) + return ERR_BUF; + PacketFreePacket(lpPacket); + +#ifdef LINK_STATS + lwip_stats.link.xmit++; +#endif /* LINK_STATS */ + return ERR_OK; +} +/*-----------------------------------------------------------------------------------*/ +/* + * low_level_input(): + * + * Should allocate a pbuf and transfer the bytes of the incoming + * packet from the interface into the pbuf. + * + */ +/*-----------------------------------------------------------------------------------*/ +static struct pbuf * +low_level_input(struct netif *ethernetif) +{ + struct pbuf *p, *q; + int start, length; + + /* Obtain the size of the packet and put it into the "len" + variable. */ + length = cur_length; + if (length<=0) + return NULL; + + /* We allocate a pbuf chain of pbufs from the pool. */ + p = pbuf_alloc(PBUF_LINK, (u16_t)length, PBUF_POOL); +#ifdef NETIF_DEBUG + DEBUGF(NETIF_DEBUG, ("netif: recv length %i p->tot_len %i\n", length, (int)p->tot_len)); +#endif + + if(p != NULL) { + /* We iterate over the pbuf chain until we have read the entire + packet into the pbuf. */ + start=0; + for(q = p; q != NULL; q = q->next) { + /* Read enough bytes to fill this pbuf in the chain. The + avaliable data in the pbuf is given by the q->len + variable. */ + /* read data into(q->payload, q->len); */ +#ifdef NETIF_DEBUG + DEBUGF(NETIF_DEBUG, ("netif: recv start %i length %i q->payload %p q->len %i q->next %p\n", start, length, q->payload, (int)q->len, q->next)); +#endif + memcpy(q->payload,&cur_packet[start],q->len); + start+=q->len; + length-=q->len; + if (length<=0) + break; + } + /* acknowledge that packet has been read(); */ + cur_length=0; +#ifdef LINK_STATS + lwip_stats.link.recv++; +#endif /* LINK_STATS */ + } else { + /* drop packet(); */ + cur_length=0; +#ifdef LINK_STATS + lwip_stats.link.memerr++; + lwip_stats.link.drop++; +#endif /* LINK_STATS */ + } + + return p; +} +/*-----------------------------------------------------------------------------------*/ +/* + * ethernetif_output(): + * + * This function is called by the TCP/IP stack when an IP packet + * should be sent. It calls the function called low_level_output() to + * do the actuall transmission of the packet. + * + */ +/*-----------------------------------------------------------------------------------*/ +static err_t +ethernetif_output(struct netif *netif, struct pbuf *p, + struct ip_addr *ipaddr) +{ + p = etharp_output(netif, ipaddr, p); + if(p != NULL) { + return low_level_output(netif, p); + } + return ERR_OK; +} +/*-----------------------------------------------------------------------------------*/ +/* + * ethernetif_input(): + * + * This function should be called when a packet is ready to be read + * from the interface. It uses the function low_level_input() that + * should handle the actual reception of bytes from the network + * interface. + * + */ +/*-----------------------------------------------------------------------------------*/ +static void +ethernetif_input(struct netif *netif) +{ + struct ethernetif *ethernetif; + struct eth_hdr *ethhdr; + struct pbuf *p; + + + ethernetif = netif->state; + + p = low_level_input(netif); + + if(p != NULL) { + +#ifdef LINK_STATS + lwip_stats.link.recv++; +#endif /* LINK_STATS */ + + ethhdr = p->payload; + + switch(htons(ethhdr->type)) { + case ETHTYPE_IP: + etharp_ip_input(netif, p); + pbuf_header(p, -14); + //if(ip_lookup(p->payload, netif)) { + netif->input(p, netif); + //} + break; + case ETHTYPE_ARP: + p = etharp_arp_input(netif, ethernetif->ethaddr, p); + if(p != NULL) { + low_level_output(netif, p); + pbuf_free(p); + } + break; + default: + pbuf_free(p); + break; + } + } +} +/*-----------------------------------------------------------------------------------*/ +static void +arp_timer(void *arg) +{ + etharp_tmr(); + sys_timeout(ARP_TMR_INTERVAL, (sys_timeout_handler)arp_timer, NULL); +} +/*-----------------------------------------------------------------------------------*/ +/* + * ethernetif_init(): + * + * Should be called at the beginning of the program to set up the + * network interface. It calls the function low_level_init() to do the + * actual setup of the hardware. + * + */ +/*-----------------------------------------------------------------------------------*/ +void +ethernetif_init(struct netif *netif) +{ + struct ethernetif *ethernetif; + + ethernetif = mem_malloc(sizeof(struct ethernetif)); + netif->state = ethernetif; + netif->name[0] = IFNAME0; + netif->name[1] = IFNAME1; + netif->output = ethernetif_output; + + ethernetif->ethaddr = (struct eth_addr *)&(netif->hwaddr[0]); + + low_level_init(netif); + etharp_init(); + + sys_timeout(ARP_TMR_INTERVAL, (sys_timeout_handler)arp_timer, NULL); +} +/*-----------------------------------------------------------------------------------*/ +/* + * pktif_update(): + * + * Needs to be called periodically to get new packets. This could + * be done inside a thread. + */ +/*-----------------------------------------------------------------------------------*/ +static void ProcessPackets(LPPACKET lpPacket) +{ + + ULONG ulLines, ulBytesReceived; + char *base; + char *buf; + u_int off=0; + u_int tlen,tlen1; + struct bpf_hdr *hdr; + struct ethernetif *ethernetif; + + ethernetif = pktif_netif->state; + + ulBytesReceived = lpPacket->ulBytesReceived; + + buf = lpPacket->Buffer; + + off=0; + + while(offbh_datalen; + cur_length=tlen1; + tlen=hdr->bh_caplen; + off+=hdr->bh_hdrlen; + + ulLines = (tlen + 15) / 16; + if (ulLines > 5) ulLines=5; + + base =(char*)(buf+off); + cur_packet=base; + off=Packet_WORDALIGN(off+tlen); + + ethernetif_input(pktif_netif); + } +} + +void update_adapter(void) +{ + struct ethernetif *ethernetif; + + ethernetif = pktif_netif->state; + + if(PacketReceivePacket(lpAdapter,lpPacket,TRUE)==TRUE) + ProcessPackets(lpPacket); + cur_length=0; + cur_packet=NULL; +} + diff --git a/ports/msvc6/pktif.dsp b/ports/msvc6/pktif.dsp new file mode 100644 index 0000000..9e3f20a --- /dev/null +++ b/ports/msvc6/pktif.dsp @@ -0,0 +1,104 @@ +# Microsoft Developer Studio Project File - Name="pktif" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** NICHT BEARBEITEN ** + +# TARGTYPE "Win32 (x86) Static Library" 0x0104 + +CFG=pktif - Win32 Debug +!MESSAGE Dies ist kein gültiges Makefile. Zum Erstellen dieses Projekts mit NMAKE +!MESSAGE verwenden Sie den Befehl "Makefile exportieren" und führen Sie den Befehl +!MESSAGE +!MESSAGE NMAKE /f "pktif.mak". +!MESSAGE +!MESSAGE Sie können beim Ausführen von NMAKE eine Konfiguration angeben +!MESSAGE durch Definieren des Makros CFG in der Befehlszeile. Zum Beispiel: +!MESSAGE +!MESSAGE NMAKE /f "pktif.mak" CFG="pktif - Win32 Debug" +!MESSAGE +!MESSAGE Für die Konfiguration stehen zur Auswahl: +!MESSAGE +!MESSAGE "pktif - Win32 Release" (basierend auf "Win32 (x86) Static Library") +!MESSAGE "pktif - Win32 Debug" (basierend auf "Win32 (x86) Static Library") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +RSC=rc.exe + +!IF "$(CFG)" == "pktif - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release" +# PROP Intermediate_Dir "Release" +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c +# ADD CPP /nologo /W3 /GX /O2 /I "$(LWIP_SRC)\include" /I "$(LWIP_SRC)\include\ipv4" /I ".\include" /I ".\\" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c +# ADD BASE RSC /l 0x407 /d "NDEBUG" +# ADD RSC /l 0x407 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LIB32=link.exe -lib +# ADD BASE LIB32 /nologo +# ADD LIB32 /nologo + +!ELSEIF "$(CFG)" == "pktif - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Debug" +# PROP Intermediate_Dir "Debug" +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c +# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "$(LWIP_SRC)\include" /I "$(LWIP_SRC)\include\ipv4" /I ".\include" /I ".\\" /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c +# ADD BASE RSC /l 0x407 /d "_DEBUG" +# ADD RSC /l 0x407 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LIB32=link.exe -lib +# ADD BASE LIB32 /nologo +# ADD LIB32 /nologo /out:"Debug\pktif_d.lib" + +!ENDIF + +# Begin Target + +# Name "pktif - Win32 Release" +# Name "pktif - Win32 Debug" +# Begin Group "Quellcodedateien" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE="$(LWIP_SRC)\netif\etharp.c" +# End Source File +# Begin Source File + +SOURCE=.\pktif.c +# End Source File +# End Group +# Begin Group "Header-Dateien" + +# PROP Default_Filter "h;hpp;hxx;hm;inl" +# Begin Source File + +SOURCE=..\..\..\src\include\netif\etharp.h +# End Source File +# End Group +# End Target +# End Project diff --git a/ports/msvc6/readme.txt b/ports/msvc6/readme.txt new file mode 100644 index 0000000..67bbce3 --- /dev/null +++ b/ports/msvc6/readme.txt @@ -0,0 +1,29 @@ +lwIP for Win32 + +***WARNING*** +The current CVS code of this port isn't much tested. +***WARNING*** + +This is a quickly hacked port and example project of the lwIP library to +Win32/MSVC. + +To get this compiling, you have to set the LWIP_SRC environment variable to +point to the src subdirectory in the main lwip tree. + +Due to the nature of the lwip library you have to copy this whole project +into a new subdir in proj and modify lwipopts.h to your needs. If you move +it to another directory besides proj, you have to update the include paths +in the project settings. + +Included in the proj/msvc6 directory is the network interface driver using +the winpcap library. + +There is no more documentation yet. Try to figure it out yourself. + +This is provided as is, it's just a hack to test some stuff, no serious +implementation. + +Florian Schulze (florian.proff.schulze@gmx.net) + +lwIP: http://www.sics.se/~adam/lwip/ +WinPCap: http://netgroup-serv.polito.it/winpcap/ \ No newline at end of file diff --git a/ports/msvc6/test.c b/ports/msvc6/test.c new file mode 100644 index 0000000..cb1c2a4 --- /dev/null +++ b/ports/msvc6/test.c @@ -0,0 +1,216 @@ +/* + * Copyright (c) 2001,2002 Florian Schulze. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the authors nor the names of the contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * test.c - This file is part of lwIPtest + * + */ + +#include +#include +#include +#include + +#include "lwip/debug.h" +#include "lwip/mem.h" +#include "lwip/memp.h" +#include "lwip/sys.h" + +#include "lwip/stats.h" + +#include "lwip/tcpip.h" + +#include "netif/loopif.h" + +#include "arch/perf.h" + +//#include "httpd.h" +//#include "ftpd.h" +//#include "fs.h" + +void ethernetif_init(struct netif *netif); +int init_adapter(void); +void shutdown_adapter(void); +void update_adapter(void); + +int dbg_printf(const char *fmt, ...) +{ + va_list v; + int r; + + va_start(v, fmt); + r = vfprintf(stderr,fmt, v); + va_end(v); + return r; +} + +static err_t netio_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err) +{ + if (err == ERR_OK && p != NULL) + { + tcp_recved(pcb, p->tot_len); + pbuf_free(p); + } + else + pbuf_free(p); + + if (err == ERR_OK && p == NULL) + { + tcp_arg(pcb, NULL); + tcp_sent(pcb, NULL); + tcp_recv(pcb, NULL); + tcp_close(pcb); + } + + return ERR_OK; +} + +static err_t netio_accept(void *arg, struct tcp_pcb *pcb, err_t err) +{ + tcp_arg(pcb, NULL); + tcp_sent(pcb, NULL); + tcp_recv(pcb, netio_recv); + return ERR_OK; +} + +void netio_init(void) +{ + struct tcp_pcb *pcb; + + pcb = tcp_new(); + tcp_bind(pcb, IP_ADDR_ANY, 18767); + pcb = tcp_listen(pcb); + tcp_accept(pcb, netio_accept); +} + +void main_loop() +{ + struct ip_addr ipaddr, netmask, gw; + int last_time; + int timer1; + int timer2; + int done; + + IP4_ADDR(&gw, 192,168,2,201); + IP4_ADDR(&ipaddr, 192,168,2,200); + IP4_ADDR(&netmask, 255,255,255,0); + + if (init_adapter() != 0) + return; + + netif_set_default(netif_add(&ipaddr, &netmask, &gw, ethernetif_init, + ip_input)); + + /* + IP4_ADDR(&gw, 127,0,0,1); + IP4_ADDR(&ipaddr, 127,0,0,1); + IP4_ADDR(&netmask, 255,0,0,0); + + netif_add(&ipaddr, &netmask, &gw, loopif_init, + ip_input); + */ + + tcp_init(); + udp_init(); + ip_init(); + + //httpd_init(); + netio_init(); + //ftpd_init(); + + last_time=clock(); + timer1=0; + timer2=0; + done=0; + + while(!done) + { + int cur_time; + int time_diff; + + cur_time=clock(); + time_diff=cur_time-last_time; + if (time_diff>0) + { + last_time=cur_time; + timer1+=time_diff; + timer2+=time_diff; + } + + if (timer1>10) + { + tcp_fasttmr(); + timer1=0; + } + + if (timer2>45) + { + tcp_slowtmr(); + timer2=0; + done=kbhit(); + } + + update_adapter(); + } + + shutdown_adapter(); +} + +void bcopy(const void *src, void *dest, int len) +{ + memcpy(dest,src,len); +} + +void bzero(void *data, int n) +{ + memset(data,0,n); +} + +int main(void) +{ + setvbuf(stdout,NULL,_IONBF,0); +#ifdef PERF + perf_init("/tmp/lwip.perf"); +#endif /* PERF */ +#ifdef STATS + stats_init(); +#endif /* STATS */ + sys_init(); + mem_init(); + memp_init(); + pbuf_init(); + + //tcpdump_init(); + + printf("System initialized.\n"); + + main_loop(); + + return 0; +} + diff --git a/ports/msvc6/test.dsp b/ports/msvc6/test.dsp index 1a54ab1..b43fce6 100644 --- a/ports/msvc6/test.dsp +++ b/ports/msvc6/test.dsp @@ -100,7 +100,7 @@ SOURCE=.\test.c # End Group # Begin Source File -SOURCE=.\lwip4\Release\lwip4.lib +SOURCE=.\Release\lwip4.lib !IF "$(CFG)" == "test - Win32 Release" @@ -113,7 +113,7 @@ SOURCE=.\lwip4\Release\lwip4.lib # End Source File # Begin Source File -SOURCE=.\lwip4\Debug\lwip4_d.lib +SOURCE=.\Debug\lwip4_d.lib !IF "$(CFG)" == "test - Win32 Release" @@ -126,7 +126,7 @@ SOURCE=.\lwip4\Debug\lwip4_d.lib # End Source File # Begin Source File -SOURCE=.\pktif\Debug\pktif_d.lib +SOURCE=.\Debug\pktif_d.lib !IF "$(CFG)" == "test - Win32 Release" @@ -139,7 +139,7 @@ SOURCE=.\pktif\Debug\pktif_d.lib # End Source File # Begin Source File -SOURCE=.\pktif\Release\pktif.lib +SOURCE=.\Release\pktif.lib !IF "$(CFG)" == "test - Win32 Release" diff --git a/ports/msvc6/test.dsw b/ports/msvc6/test.dsw index e37aae0..9bdd8e8 100644 --- a/ports/msvc6/test.dsw +++ b/ports/msvc6/test.dsw @@ -3,7 +3,7 @@ Microsoft Developer Studio Workspace File, Format Version 6.00 ############################################################################### -Project: "lwip4"=.\lwip4\lwip4.dsp - Package Owner=<4> +Project: "lwip4"=.\lwip4.dsp - Package Owner=<4> Package=<5> {{{ @@ -15,7 +15,7 @@ Package=<4> ############################################################################### -Project: "pktif"=.\pktif\pktif.dsp - Package Owner=<4> +Project: "pktif"=.\pktif.dsp - Package Owner=<4> Package=<5> {{{