untitled

Similar documents
VoIP Make a Rtp Call VoIP Abstract... 2 VoIP RTP...3 Socket IP...9 Config Two Voice-hub

Chap6.ppt

一个开放源码的嵌入式仿真环境 ― SkyEye

/ / (FC 3)...

嵌入式Linux块设备驱动开发解析

穨control.PDF

(Methods) Client Server Microsoft Winsock Control VB 1 VB Microsoft Winsock Control 6.0 Microsoft Winsock Control 6.0 1(a). 2

股 票 代 码 年 9 月 印 总 第 012 期 2012 年 9 月 印 总 第 012 期 主 管 单 位 成 都 金 亚 科 技 股 份 有 限 公 司 主 办 单 位 成 都 金 亚 科 技 股 份 有 限 公 司 行 政 部 名 誉 总 编 周 旭 辉 主 编 王

Microsoft PowerPoint - 数据通信-ch1.ppt

Microsoft PowerPoint - Aqua-Sim.pptx

, 7, Windows,,,, : ,,,, ;,, ( CIP) /,,. : ;, ( 21 ) ISBN : -. TP CIP ( 2005) 1

AL-M200 Series

C/C++ - 文件IO

Socket Socket TcpClient Socket.Connect TcpClient.Connect Socket.Send / Receive NetworkStream 6-5

ebook140-8

Simulator By SunLingxi 2003

ebook12-1

ebook140-11

Oracle 4

ARP ICMP

C6_ppt.PDF

ebook35-21

int *p int a 0x00C7 0x00C7 0x00C int I[2], *pi = &I[0]; pi++; char C[2], *pc = &C[0]; pc++; float F[2], *pf = &F[0]; pf++;

Chapter #

目 录

概述

目次 

TCP/IP TCP/IP OSI IP TCP IP IP TCP/IP TCP/IP

epub

Data Server_new_.doc

工程师培训

mvc

1 o o o CPU o o o o o SQL Server 2005 o CPU o o o o o SQL Server o Microsoft SQL Server 2005

UDP 8.2 TCP/IP OSI OSI 3 OSI TCP/IP IP TCP/IP TCP/IP Transport Control Protocol TCP User Datagram Protocol UDP TCP TCP/IP IP TCP TCP/IP TC

51 C 51 isp 10 C PCB C C C C KEIL

CC213

ebook 132-6

Bus Hound 5

OSI OSI 15% 20% OSI OSI ISO International Standard Organization 1984 OSI Open-data System Interface Reference Model OSI OSI OSI OSI ISO Prototype Prot

¶C¶L§§¬_™¨ A.PDF

c_cpp

Chapter 2

Microsoft Word - 正文.doc

LwIP TCP/IP STM32Cube

提问袁小兵:

Microsoft Word - MSP430 Launchpad 指导书.docx

國家圖書館典藏電子全文

EK-STM32F

展讯平台软件架构介绍 [只读]

BYOD IP+Optical (IP NGN) API 4. End-to-End (Service Aware) 5. IP NGN (IP Next Generation Network) ( ) Prime Carrier Management Access Edge Co

1 Project New Project 1 2 Windows 1 3 N C test Windows uv2 KEIL uvision2 1 2 New Project Ateml AT89C AT89C51 3 KEIL Demo C C File

计算机网络

A Preliminary Implementation of Linux Kernel Virus and Process Hiding

第 1 章 概 述 1.1 计 算 机 网 络 在 信 息 时 代 中 的 作 用 1.2 计 算 机 网 络 的 发 展 过 程 *1.2.1 分 组 交 换 的 产 生 *1.2.2 因 特 网 时 代 *1.2.3 关 于 因 特 网 的 标 准 化 工 作 计 算 机 网 络 在

WinMDI 28

02

IP-Routing-05.pdf

Abstract arm linux tool-chain root NET-Start! 2

前言 C# C# C# C C# C# C# C# C# microservices C# More Effective C# More Effective C# C# C# C# Effective C# 50 C# C# 7 Effective vii

新・解きながら学ぶC言語

Windows RTEMS 1 Danilliu MMI TCP/IP QEMU i386 QEMU ARM POWERPC i386 IPC PC104 uc/os-ii uc/os MMI TCP/IP i386 PORT Linux ecos Linux ecos ecos eco

RS-232C [11-13] 1 1 (PLC) (HMI) Visual Basic (PLC) 402

untitled

ebook67-1

PIC_SERVER (11) SMTP ( ) ( ) PIC_SERVER (10) SMTP PIC_SERVER (event driven) PIC_SERVER SMTP 1. E-

AN INTRODUCTION TO PHYSICAL COMPUTING USING ARDUINO, GRASSHOPPER, AND FIREFLY (CHINESE EDITION ) INTERACTIVE PROTOTYPING

第3章 计算机网络体系结构

Microsoft Word - A doc

ebook67-9

epub83-1

<4D F736F F F696E74202D FC2B2B3F85FA44AAB49B0BBB4FABB50B977A8BEA874B2CEC2B2A4B6BB50C0B3A5CE2E707074>

Huawei Technologies Co

新版 明解C++入門編

9 Internet 10 Internet

Total Internet Connectivity in a Single Chip

飞鱼星多WAN防火墙路由器用户手册

ebook71-13

IP Access Lists IP Access Lists IP Access Lists

Microsoft PowerPoint - os_4.ppt

(Load Project) (Save Project) (OffLine Mode) (Help) Intel Hex Motor

<4D F736F F D20B9F9B0EABBCDBBAFAB48DEB3B4C1A5BDB3F8A7692E646F63>

IP505SM_manual_cn.doc

Computer Architecture

四川省普通高等学校

KL DSC DEMO 使用说明

计 算 机 网 络 基 础 任 务 教 程 () 组 成 计 算 机 网 络 的 每 台 计 算 机 都 是 独 立 的 即 计 算 机 之 间 没 有 明 显 的 主 从 关 系, 每 台 计 算 机 可 以 连 网 工 作, 也 可 以 不 连 网 工 作 (2) 建 立 计 算 机 网 络 的

Oracle Solaris Studio makefile C C++ Fortran IDE Solaris Linux C/C++/Fortran IDE "Project Properties" IDE makefile 1.

新版 明解C言語入門編

ebook140-9

FY.DOC

AL-MX200 Series

W. Richard Stevens UNIX Sockets API echo Sockets TCP OOB IO C struct C/C++ UNIX fork() select(2)/poll(2)/epoll(4) IO IO CPU 100% libevent UNIX CPU IO

CH01.indd

SL2511 SR Plus 操作手冊_單面.doc

ESP-Jumpstart

R3105+ ADSL

Microsoft Word htm

Value Chain ~ (E-Business RD / Pre-Sales / Consultant) APS, Advanc

/3/15 1, linux. linux,,. : 1.NAT ; 2. (load balance, virtual server);; 3. ; 4. ; 5. 6.VPN; 7. ; 8. ; 9.. (,

Transcription:

Lwip Swedish Institute of Computer Science February 20, 2001 Adam Dunkels adam@sics.se (QQ: 10205001) (QQ: 329147) (QQ:3232253) (QQ:3232253) QQ ARM TCPIP LCD10988210

LWIP TCP/IP LWIP LWIP lwip API lwip LWIP APILWIP 1 Introduction..1 2 Protocol layering..1 3 Overview...2 4 Process model...2 5 The operating system emulation layer...3 6 Buffer and memory management.......3 6.1 Packet buffers pbufs 3 6.2 Memory management..5 7 Network interfaces...5 8 IP processing. 7 8.1 Receiving packets.7 8.2 Sending packets 7 8.3 Forwarding packets..8 8.4 ICMP processing.8 9 UDP processing.....8 10 TCP processing...9 10.1 Overview 9 10.2 Data structures..10

10.3 Sequence number calculations.12 10.4 Queuing and transmitting data.12 10.4.1 Silly window avoidance 13 10.5 Receiving segments..13 10.5.1 Demultiplexing..13 10.5.2 Receiving data...14 10.6 Accepting new connections.14 10.7 Fast retransmit..14 10.8 Timers..14 10.9 Round-trip time estimation..15 10.10Congestion control..15 11 Interfacing the stack 15 12 Application Program Interface...16 12.1 Basic concepts..16 12.2 Implementation of the API.. 17 13 Statistical code analysis 17 13.1 Lines of code 18 13.2 Object code size...19 14 Performance analysis...20 15 API reference....21 15.1 Data types.21 15.1.1 Netbufs..21 15.2 Bu er functions..21 15.2.1 netbuf new()..21 15.2.2 netbuf delete()...21 15.2.3 netbuf alloc().22 15.2.4 netbuf free()..22 15.2.5 netbuf ref() 22 15.2.6 netbuf len()... 23 15.2.7 netbuf data(). 23 15.2.8 netbuf next(). 23 15.2.9 netbuf rst()..24 15.2.10 netbuf copy()...24 15.2.11 netbuf chain()..24 15.2.12 netbuf fromaddr() 24 15.2.13 netbuf fromport() 25 16 Network connection functions.25 16.0.14 netconn new()..25 16.0.15 netconn delete()...25 16.0.16 netconn type()..25 16.0.17 netconn peer(). 25 16.0.18 netconn addr() 26 16.0.19 netconn bind() 26 16.0.20 netconn connect(.26 16.0.21 netconn listen() 26 16.0.22 netconn accept()..26 16.0.23 netconn recv().27 16.0.24 netconn write() 28 16.0.25 netconn send().29 16.0.26 netconn close() 30 17 BSD socket library...30 17.1 The representation of a socket.30 17.2 Allocating a socket..30 17.2.1 The socket() call 30 17.3 Connection setup..31 17.3.1 The bind() call...31

17.3.2 The connect() call. 31 17.3.3 The listen() call.32 17.3.4 The accept() call.. 32 17.4 Sending and receiving data..33 17.4.1 The send() call.33 17.4.2 The sendto() and sendmsg() calls 34 17.4.3 The write() call. 34 17.4.4 The recv() and read() calls 35 17.4.5 The recvfrom() and recvmsg() calls.36 18 Code examples.36 18.1 Using the API.36 18.2 Directly interfacing the stack.. 39 Bibliography..41 1 2 Protocol layering

3 Overview 4 Process model 5 lwip lwip

6 Pbuf lwip Pbufs BSD mbufs pbuf Pbufs pbuf pbufs Pbufs PBUF RAM PBUF ROMPBUF POOL 1 pbuf PBUF RAMpbuf 2pbuf pbuf pbufpbuf RAM where the first pbufin the chain is of the PBUF RAM typepbuf ROMpbuf pbuf PBUF POOL3pbufs pbufs consists of fixed size pbufs allocated from a pool of fixedsize pbufs. pbuf pbufs PBUF_POOL pbuf suitable foruse in an interrupt handler PBUF_ROM pbuftcp/ip pbufrom ( PBUF_ROM )

16 161 alignment9

9 UDP UDP checksumming UDP

12. API 1

13 2. LWIP Intel x86

14. LWIP X86 3. LWIP 6502

15. LWIP 6502

15.2.1 netbuf new() 15.2.2 netbuf delete() netbufs int main() { struct netbuf *buf; buf = netbuf_new(); /* netbuf */ netbuf_alloc(buf, 100); /* 100 bytes buffer */ struct netbuf * netbuf new(void) void netbuf delete(struct netbuf *) /* netbuf */ /* [...] */ netbuf_delete(buf); /* netbuf */ } 15.2.3 netbuf alloc()

15.2.4 netbuf free() netbuf buf buffer buffer netbuf buf 15.2.5 netbuf ref() netbuf buf size netbuf netbuf_alloc() netbufmalloc() netbuf_ref()buffer netbuf_ref() int main() { struct netbuf *buf; char string[] = " "; /* netbuf */ buf = netbuf_new(); void * netbuf alloc(struct netbuf *buf, int size) int netbuf free(struct netbuf *buf) int netbuf ref(struct netbuf *buf, void *data, int size) /* */ netbuf_ref(buf, string, sizeof(string)); /* netbuf */ /* [...] */ /* netbuf */ netbuf_delete(buf); }

15.2.6 netbuf len() netbuf buf netbufnetbuf netbuf 15.2.7 netbuf data() netbuf data len netbuf netbuf netbuf_first() netbuf_next() netbuf netbuf_next() netbuf_data() 15.2.8 netbuf next() netbuf buf netbuf netbuf>0 <0. netbuf_next() buf netbuf /* [...] */ do { char *data; int len; int netbuf len(struct netbuf *buf) int netbuf data(struct netbuf *buf, void **data, int *len) int netbuf next(struct netbuf *buf) /* */ netbuf_data(buf, &data, &len); /* */ do_something(data, len); } while(netbuf_next(buf) >= 0); /* [...] */ 15.2.9 netbuf first()

netbuf buf 15.2.10 netbuf copy() netbuf bufdatanetbuf buflen data netbuf_copy()200 netbuf buf 200200data void example_function(struct netbuf *buf) { char data[200]; netbuf_copy(buf, data, 200); /* */ } 15.2.11 netbuf chain() netbufs netbuf 15.2.12 netbuf fromaddr() void netbuf first(struct netbuf *buf) void netbuf copy(struct netbuf *buf, void *data, int len) void netbuf chain(struct netbuf *head, struct netbuf *tail) struct ip addr * netbuf fromaddr(struct netbuf *buf) netbuf buf IPnetbuf netbuf_fromport() 15.2.13 netbuf fromport()

netbuf bufnetbuf netbuf_fromaddr() IP 16 16.0.14 netconn new() TCP UDP NETCONN_TCP NETCONN_UDP 16.0.15 netconn delete() netconn conn 16.0.16 netconn type() connnetconn_new() NETCONN_TCP NETCONN_UDP 16.0.17 netconn peer() unsigned short netbuf fromport(struct netbuf *buf) struct netconn * netconn new(enum netconn type type) void netconn delete(struct netconn *conn) enum netconn type netconn type(struct netconn *conn) int netconn peer(struct netconn *conn, struct ip addr **addr, unsigned short port) IPaddr port conn

conn IP 16.0.19 netconn bind() conn IP addr TCPUDP addr IP 16.0.20 netconn connect() UDP UDP remote_addr remote_port TCP netconn_connect() 16.0.21 netconn listen() TCPconnTCP 16.0.22 netconn accept() TCPconn netconn_listen() netconn_accept() 2000 TCP int main() { struct netconn *conn, *newconn; /* */ conn = netconn_new(netconn_tcp); /* IP 2000*/ netconn_bind(conn, NULL, 2000); /* */ netconn_listen(conn);

/* block*/ newconn = netconn_accept(conn); /* newconn */ process_connection(newconn); /* */ netconn_delete(newconn); netconn_delete(conn); } 16.0.23 netconn recv() conn NULL netbuf netconn_ recv() example_function() void example_function(struct netconn *conn) { struct netbuf *buf; /* */ while((buf = netconn_recv(conn))!= NULL) { do_something(buf); } /* */ netconn_close(conn); } 16.0.24 netconn write() TCP TCP conn bu &-#174;ers TCP It puts the data pointed to by data on the output queue for the TCP connection conn. len flags #define NETCONN_NOCOPY 0x00 #define NETCONN_COPY 0x01

NETCONN_COPY flag flag NETCONN_NOCOPY stay there for an indeterminate amount of time. ROM netconn_write() flag NETCONN_COPY text int main() { struct netconn *conn; char data[10]; char text[] = "Static text"; int i; /*conn */ /* [...] */ /* */ for(i = 0; i < 10; i++) data[i] = i; netconn_write(conn, data, 10, NETCONN_COPY); netconn_write(conn, text, sizeof(text), NETCONN_NOCOPY); /* */ for(i = 0; i < 10; i++) data[i] = 10 - i; /* take down the connection conn */ netconn_close(conn); } 16.0.25 netconn send() UDPconn netbuf bufnetbuf IP MTU netbuf1000 netbuf IP10.10.0.1UDP7000 UDP

int main() { struct netconn *conn; struct netbuf *buf; struct ip_addr addr; char *data; char text[] = "A static text"; int i; /* */ conn = netconn_new(netconn_udp); /* IP*/ addr.addr = htonl(0x0a000001); /* */ netconn_connect(conn, &addr, 7000); /* netbuf */ buf = netbuf_new(); data = netbuf_alloc(buf, 10); /* */ for(i = 0; i < 10; i++) data[i] = i; /* */ netconn_send(conn, buf); netbuf_ref(buf, text, sizeof(text)); /* text */ netconn_send(conn, buf); /*connection netbuf */ netconn_delete(conn); netconn_delete(buf); 16.0.26 netconn close() conn 17 BSD socket BSD socket APILWIP API BSD socket API BSD socket APInetconn BSD socketsnetconn BSD socket

socketbsdsocket socket API UDP (SOCK DGRAM) TCP (SOCK STREAM)