硬汉嵌入式论坛

 找回密码
 立即注册
查看: 6574|回复: 0
收起左侧

【转载】UIP中文文档第二  uIP初始化函数

[复制链接]

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106959
QQ
发表于 2013-11-3 11:10:14 | 显示全部楼层 |阅读模式
转载地址:http://www.usr.cc/thread-51108-1-1.html
uIP初始化函数用于启动uIP.它包括以下两个函数:
  1. void uip_init(void)
  2. void uip_setipid(u16_t id)
复制代码
1. void uip_init(void)
此函数用于在启动时初始化uIP的TCP/IP栈。
应用示例:
example-mainloop-with-arp.c, and example-mainloop-without-arp.c.
定义于uip.c379行
void uip_init(void)代码分析
  1. void
  2. uip_init(void)
  3. {
  4. for(c = 0; c < UIP_LISTENPORTS; ++c) {
  5. uip_listenports[c] = 0;
  6. }   //将uip_listenports数组全部清零
  7. for(c = 0; c < UIP_CONNS; ++c) {
  8. uip_conns[c].tcpstateflags = UIP_CLOSED;
  9. }  //将所有连接的tcpstateflags状态标志设为关闭,表示此连接为关闭状态。
  10. #if UIP_ACTIVE_OPEN
  11. lastport = 1024;
  12. #endif /* UIP_ACTIVE_OPEN */
  13. //上面的段不知什么意思。
  14. #if UIP_UDP
  15. for(c = 0; c < UIP_UDP_CONNS; ++c) {
  16. uip_udp_conns[c].lport = 0;
  17. }
  18. #endif /* UIP_UDP *///如果定义了UIP_UDP则将uip_udp_conns的lport清零。
  19. /* IPv4 initialization. */
  20. #if UIP_FIXEDADDR == 0
  21. /* uip_hostaddr[0] = uip_hostaddr[1] = 0;*/
  22. #endif /* UIP_FIXEDADDR *///如果主机地址要为固定的,在上面这里赋值。
  23. }
复制代码
UIP_LISTENPORTS:可同时监听的TCP端口数最大值,每监听一个TCP端口都要占用两字节内存。
此宏定义于uipopt.h259行。其默认值为20。
UIP_CONNS: 可同时打开的TCP端口数的最大值,由于TCP连接是静态分配的,所以降低这个值的大小可以降低占

用的内存空间,每个TCP连接大约需要30字节内存。
此宏定义于uipopt.h245行。其默认值为10。
UIP_UDP_CONNS:最大的并行UDP连接数。
此宏定义于uipopt.h的206行。其默认值是10。
uip_conns: struct uip_conn型结构体数列,数列大小为UIP_CONNS.每个uip_conn代表一个TCP连接。
uip_udp_conns:struct uip_udp_conn型号结构体数列,数列大小为UIP_UDP_CONNS.每个uip_udp_conn代表一个UDP连接。
UIP_ACTIVE_OPEN:是否编译可以让上层应用程序动态打开外向的TCP连接的代码。关闭此功能可以降低uIP的代码大小。
此宏定义于uipopt.h233行

2. void uip_setipid(u16_t id)
此函数用于启动时设置初始的ip_id.
此函数定义于uip.c181行

3. uip_conn结构体
代表一个uip的TCP连接
此结构体用于鉴定一个TCP连接,对应用来说,除一个域之外,所有的域都是只读的。例外的是appstate域,它的目的是让应
用存取应用相关的连接状态,此域的类型定义于uipopt.h中。
此结构体定义于uip.h1153行

  1. struct uip_conn {
  2. uip_ipaddr_t ripaddr; /**< The IP address of the remote host. 运程主机的ip地址*/
  3. u16_t lport; /**< The local TCP port, in network byte order. 本地主机的TCP端口,以网络传输中的字节顺序*/
  4. u16_t rport; /**< The local remote TCP port, in network byte
  5. order. 远程主机的TCP端口,以网络传输中的字节顺序*/
  6. u8_t rcv_nxt[4]; /**< The sequence number that we expect to
  7. receive next.我们期待接收的下一个序号*/
  8. u8_t snd_nxt[4]; /**< The sequence number that was last sent by
  9. us. 我们上次发送的序号*/
  10. u16_t len; /**< Length of the data that was previously sent.上次发送的数据长度 */
  11. u16_t mss; /**< Current maximum segment size for the
  12. connection. 现行连接的段大小最大值*/
  13. u16_t initialmss; /**< Initial maximum segment size for the
  14. connection. 连接的初始段大小最大值*/
  15. u8_t sa; /**< Retransmission time-out calculation state
  16. variable. 重传超时计算状态变量*/
  17. u8_t sv; /**< Retransmission time-out calculation state
  18. variable. 重传超时计算状态变量*/
  19. u8_t rto; /**< Retransmission time-out.重传超时 */
  20. u8_t tcpstateflags; /**< TCP state and flags. TCP状态标志*/
  21. u8_t timer; /**< The retransmission timer. 重传定时器*/
  22. u8_t nrtx; /**< The number of retransmissions for the last
  23. segment sent. 上次发送的段的重传次数*/
  24. /** The application state.应用状态 */
  25. uip_tcp_appstate_t appstate;
  26. };
复制代码
4. uip_udp_conn结构体
代表一个uIP UDP连接
定义于uip.h1210行
  1. struct uip_udp_conn {
  2. uip_ipaddr_t ripaddr; /**< The IP address of the remote peer. 远程对等主机的ip地址*/
  3. u16_t lport; /**< The local port number in network byte order. 本地端口号,以网络字节顺序*/
  4. u16_t rport; /**< The remote port number in network byte order. 远程端口号,以网络字节顺序*/
  5. u8_t ttl; /**< Default time-to-live. 默认存活时间*/
  6. /** The application state. 应用状态*/
  7. uip_udp_appstate_t appstate;
  8. };
复制代码
5.  void uip_setipid(u16_t id)
void uip_setipid(u16_t id) { ipid = id; }//此函数只是将传来的参数赋值给ipid.
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2024-5-12 00:36 , Processed in 0.154365 second(s), 25 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表