lwIP - Lightweight TCP/IP Stack

repository·master·Indexed 23 days ago

https://github.com/lwip-tcpip/lwip

A lightweight TCP/IP stack optimized for embedded systems with limited RAM and ROM resources. Features include support for custom DHCP options via hooks, an IPv6 static routing addon with Longest Prefix Match (LPM), and TCP MD5 signatures. The project includes demonstration applications like a CHARGEN server and HTTPServer (Raw TCP and Netconn/Netbuf APIs), as well as ports for Unix-like systems and Win32.

Tokens
3.7K
Snippets
5
Records
29
Agent score
83%

What's inside lwIP

  1. Use the makefsdata script to generate C code for httpd

    master

    The makefsdata script (or the htmlgen command) converts HTML pages and other files in a directory into C code suitable for use with the httpd web server in lwIP.

    By default, if no target directory is specified, the tool attempts to process files located in a subdirectory named fs.

    Usage: htmlgen [targetdir] [-s] [-i]s

    Arguments and Switches:

    • targetdir: The relative or absolute path to the files you wish to convert.
    • -s: Toggles processing of subdirectories (enabled by default).
    • -e: Excludes the HTTP header from the generated file (the header is created at runtime; enabled by default).
    • -11: Includes the HTTP 1.1 header (the default is HTTP 1.0).
    htmlgen [targetdir] [-s] [-i]s
  2. Configure the example application for Win32

    master

    Before running the example application, you must create a local configuration file.

    1. Copy contrib/examples/example_app/lwipcfg.h.example to contrib/examples/example_app/lwipcfg.h.
    2. Edit lwipcfg.h to configure your specific requirements, including:
      • The WinPcap adapter number.
      • IP configuration.
      • Application-specific settings.
  3. Enable Deflate compression for fsdata using the C version of makefsdata

    master

    The C console application version of makefsdata can store non-SSI files in a compressed format. When served, these files are sent to the web client using Deflate content encoding (the client must support this encoding). Files that do not compress well are automatically stored uncompressed to prevent size growth.

    Compression is highly recommended for .html, .js, .css, and .svg files to reduce the overall program size.

    To enable compression, use one of the following methods during compilation:

    1. Using minizip: Define MAKEFS_SUPPORT_DEFLATE=1. You must manually provide minizip.c in your environment.
    2. Using system zlib: Define MAKEFS_SUPPORT_DEFLATE_ZLIB to utilize your system's existing zlib library.
  4. Set up the Win32 port for lwIP

    master

    To use the lwIP Win32 port, you must provide the WinPcap Developer's Pack so the build system can locate the necessary headers and libraries. You can do this in one of two ways:

    1. Set an environment variable PCAP_DIR pointing to the directory containing the WinPcap include and lib folders.
    2. Place the WinPcap Developer's Pack in a directory named winpcap\WpdPack located immediately next to the lwip folder.

    This port uses WinPCAP to send and receive packets via a network interface driver included in the contrib\ports\win32 directory.

  5. Overview of lwIP TCP/IP stack

    master
    lwIP is a lightweight, independent implementation of the TCP/IP protocol suite designed specifically for embedded systems. It focuses on minimizing RAM usage while providing a full-scale TCP implementation. It is suitable for devices with tens of kilobytes of free RAM and approximately 40 kilobytes of code ROM.
  6. Overview of the lwIP Unix port

    master
    The Unix port provides infrastructure and examples for running lwIP on Unix-like operating systems such as Linux, OpenBSD, and Cygwin. It is primarily designed for testing lwIP applications in a controlled environment. The port includes generic platform porting files, network interface implementations, and a unit testing suite.
  7. Use the IPv6 Static Routing Addon

    master

    The ipv6_static_routing addon provides a simple routing table implementation for adding, deleting, and looking up IPv6 routes. It supports Longest Prefix Match (LPM) by maintaining entries sorted in decreasing order of prefix length.

    Key Characteristics:

    • Prefix Length: The prefix length must be at an 8-bit boundary.
    • Lookup Mechanism: Uses a linear search through the sorted list to ensure the longest prefix match is found.
    • Integration: To enable route lookups from the table, assign ip6_static_route() to the LWIP_HOOK_IP6_ROUTE hook in ip6_route(..) within ip6.c.
  8. Explore lwIP HTTPServer demonstration apps

    master

    The httpserver application in the contrib/apps directory provides two different ways to implement a basic web server using the lwIP stack. Depending on your requirements for abstraction and performance, you can choose between the raw TCP API or the higher-level netconn/netbuf API:

    1. Raw TCP API (httpserver-raw.c): Uses direct TCP calls. This is typically used for maximum performance and minimal overhead, though it requires more manual state management.
    2. Netconn/Netbuf API (httpserver-netconn.c): Uses the netconn and netbuf abstraction layers. This provides a more structured, easier-to-use interface for socket-like operations.
  9. Use Unix network interface implementations

    master

    The Unix port provides several network interface (netif) implementations to facilitate testing and development:

    • pcapif: A network interface that replays packets from a PCAP dump file. Note that packets sent out from this interface are discarded.
    • tapif: A network interface mapped to a Unix user-space Layer 2 network device (tap interface). This implementation utilizes lwIP threads.
    • sio: Maps Unix character devices to lwIP's sio mechanisms.
    • fifo: A helper used by sio.
    • list: A helper used by unixif.
  10. Available applications in lwIP

    master

    lwIP includes several built-in application implementations:

    • Web/Management: HTTP server with SSI and CGI (supports HTTPS via altcp), SNMPv2c agent with MIB compiler (supports v3 via altcp).
    • Services: SNTP (Simple Network Time Protocol), NetBIOS name service responder, and MDNS responder.
    • Testing/IoT: iPerf server implementation and MQTT client (supports TLS via altcp).