Installing and running lwIP from Windows 98

 

Introduction

lwIP is a small TCP/IP stack intended for embedded CPU's or any other system with limited resources.  It was written by Adam Dunkels.   Reading information and downloading of the source code can be done using the following URL:

 

http://www.sics.se/~adam/lwip

 

LwIP has be successfully ported to Windows by Florian Schulze.  This document is about how to get his win32 version of lwIP running under Windows 98 for testing and learning purposes.   You’ll need a Windows machine with Microsoft Visual C 6.0 in order to compile the source.

 

TCP/IP was designed to run on just about any data pathway that packets can run on.  This includes telephone lines, Ethernet, or wireless devices, etc.   The TCP/IP protocol software doesn’t need to know which kind of data path it is, or what the hardware is like.

 

And so a TCP/IP stack usually needs a driver with all the hardware-specifics about how to actually put packets out on the hardware.  This driver would have to be customized for the particular chip on the network card, or whatever system will be used to send packets on the data path.   Some TCP/IP stacks use a standard Packet driver as specified by FTP Software.  Others require you to write custom code to deal with the hardware.

 

This version for Windows uses your regular Windows drivers.   However, in order to get low-level access to the installed hardware drivers, you will have to download and install a free program called WinPcap.

 

By using lwIP on Windows, we can actually just use the installed Windows drivers for our low-level access.  This is accomplished using a free program called WinPcap.

 

Installing and Using WinPcap

A)  Installing WinPCap Itself

 

The first step is to install a program called WinPCap.   When installed, this software provides easy access to all packets that the host computer sees.  In the words of the author:

 

WinPcap is an architecture for packet capture and network analysis for the Win32 platforms. It includes a kernel-level packet filter, a low-level dynamic link library (packet.dll), and a high-level and system-independent library (wpcap.dll, based on libpcap version 0.6.2).

 

It is available free from their website:

 

http://winpcap.polito.it

 

 

To use winpcap with lwip, download both the WinPCap driver and DLL's, and the Developer's pack download.

 

Installing winPCap is a breeze.  However, once installed, there is no particular indication on the machine that the program is indeed installed.

 

B) Playing with WinPcap:

 

Before installing the developer's pack, it makes sense to see how cool WinPcap is.   To do this, download their program called 'Analyzer' also.   This program allows you to capture all the packet activity on your system, and has lots of tools for filtering out only the ones you are interested in.

 

 

1.) Finding Analyzer:

  Go to the Links page on the WinPcap site.   Look under the heading: WinPcap-based tools and programs

  Click on the link, and choose Download on the right when you get to the Analyzer site.

 

 

2.) Installing Analyzer

 

   You will download a self-extracting .exe.   Create a folder to put the files in first, then double click on the analyzer.exe file.    Do not put the original self-extracting analyzer.exe in the folder that you will unpack to, since the actual program name is also analyzer.exe.    The program cannot unpack in a folder that already has analyzer.exe in it.

 

3.) Playing with Analyzer.

   Analyzer captures packets, and displays them in all their raw beauty on the screen.   Before capturing, start up your web browser and go to a simple site which doesn't have ads or any ongoing traffic when idle.

 

  Then start up the analyzer.exe program, and choose 'New Capture' from the File menu.    A dialog box appears which give you options about what kind of packets you want to capture.

 

  Choose the transport layer, and choose TCP Traffic.   Then press OK.   A dialog will pop up showing how many packets have been seen, and how many captured at this moment.

 

  Now switch to your browser window and type www.google.com into your browser URL bar and press enter.

 

   The TCP packets between your computer and the GOOGLE server should now be captured.   Switch back to the Analyzer program and stop capturing data via the stop button. 

 

  Analyzer will have shown you all the TCP traffic involved in retrieving the HTML from Google's site.

 

  If you have other machines on your LAN, you tell analyzer to do a new capture.  This time choose MAC packets (the very lowest level primitive layer of communication).  Then open a MSDOS command line box and type

 

ping (machine name)

 

When finished, you can stop the capture and look at the echo requests sent on the network. 

 

Installing and Compiling lwIP for Win32

A) Downloading lwIP for Win32

  lwIP is available in a general form which is meant to be ported to any operating system.   However, Florian Schulze has made a version which compiles under Win32 using Microsoft Visual C 6.0.    It is meant to be used with winPCap, so you don't have to make a MAC driver for your network interface card.

 

 

http://proff.crowproductions.de/lwipdev_en.php

 

 

Grab the file with both lwIP and Win32 in the name.  At the time this was written, the filename is lwip-0.5.3-win32.zip.  

 

Install the file in a folder and unzip with with any proper unzipping tool which preserves the original folder structure.

 

Fire up MSVC and open the project in the PROJ\msvc folder.

 

Set the active project to lwip4 and build it.   There will be quite a few warning/error messages, but the library should be created.

 

This library is your TCP/IP stack.   Now you can build applications using that library, so the whole TCP/IP stack will be loaded into the EXE.

 

B) Installing the Windows Packet Capture Driver

 

  After downloading WinPcap, you may have already downloaded Wpdpack_2_3.zip also.   This is the low-level capture packet driver which can be used with lwIP for Win32.

 

  Unzip this into a folder.   This will give the .lib files and the include files for using lwIP under Win32.

 

  In order to compile the test.exe file, you’ll get errors because packet32.h isn’t found until you put the Wpdpack packet driver include folder in the include search path.

 

  However, there are still two unidentified things when you try to compile test.exe.   These require the inclusion of “ntddndis.h” from the same include folder.

 

  On my system, the MSVC 6.0 linker would not accept the packet.lib file.   The reason for this failure was unclear, however, recompiling the Packet.dll file from the downloaded sources fixed the problem.

 

 

   1.) Compiling a new packet.lib that is compatible with MSVC.

 

There are very nice instructions for downloading and compiling the packet.lib with MSVC:

 

http://winpcap.polito.it/docs/compile.htm

 

  Ignore them.   They imply you need the Microsoft Driver Development kit etc.  However, all you really want to compile is packet.lib.  So download the dev kit, and load the project .\packet9x\dll\project\packet.dsw.    And do a build.   Your packet.lib file and packet.exp files are happily generated.

 

  Set your active configuration to the Release config, and rebuild.  You will get a Packet.dll, Packet.lib and a Packet.exp file in the Release subfolder.   Copy all three of these files to your proj\msvc6 folder in your lwIP tree.   Then add the Packet.lib file to your lwIP project.

 

  Now you can compile your lwIP project, and it hopefully will link happily.

 

   2.)  Changing the IP, gateway and Mask to match your current settings.

  But before you try to run it, you’ll want to give it some correct information for the IP address and so on.  To do this requires editing test.c at approximately line 106. 

 

      IP4_ADDR(&gw, 192,168,2,201);

      IP4_ADDR(&ipaddr, 192,168,2,200);

      IP4_ADDR(&netmask, 255,255,255,0);

 

  These numbers are for the author’s computer.  To find out these relevant number for your machine, open a DOS prompt box and type

 

Winipcfg

 

   A dialog will pop up with all the info you need.   Based on the numbers in the picture below, the three lines above were changed to:

 

 

 

     

      IP4_ADDR(&gw, 192,192,192,22);             /* The default Gateway. */

      IP4_ADDR(&ipaddr, 192,192,192,205);        /* Choose a different IP than your Windows TCP/IP has */

      IP4_ADDR(&netmask, 255,255,255,0);         /* Make the network mask the same as IP Config says.  */

 

  You can choose a IP address which is similar to the IP’s on your current network, but make the last digits different from the Windows IP for your machine.   Also, make sure you do not choose an IP address that is already in use by another machine on your local network, or you may get confusing results and/or cripple your network. 

 

 

3.) Fixing the error message about the tcpdump file.

 

And now, you can run finally run the .EXE.   You will get a message that a file called tcpdump could not be opened.   Press the spacebar to abort the running program.

 

 Now go to the root of the current drive and make sure there is a folder called ‘tmp’  there.   If not, then create one.   Then create an empty file called tcpdump.   One way to do this is with the dos prompt:

 

Cd tmp

Copy con: tcpdump

 

^Z

 

 

Copying the console to the file tcpdump will cause the file tcpdump to be created.   To finish inputting text, type a Control-Z and press enter.

 

Now try running the test.exe again, and it should appear to be normal with no error messages.

 

4.)  Testing the stack

 

I have picked an unused IP on our network and put that into test.c (on the IP4_ADDR() call.)  I choose address 192.192.192.205.  The program started up and ran ok.   I could ping the address ok.

 

  Now for some fun, go to your browser, and type http://192.192.192.205

 

  And the lwIP web page should pop up.   The html pages are actually stored in global data arrays of characters in the fsdata.c file.   So if you get these pages, you know you are dealing with the lwIP stack!

 

  Congratulations, you now have lwIP running under WIN32.

 

-Kevin Stokes

Pie in the Sky Software

http://www.pieskysoft.com/

Kevin@pieskysoft.com