首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网络技术 > 网络基础 >

uip main函数分析1_IP地址的兑现

2012-11-23 
uip main函数分析1_IP地址的实现uip_ipaddr_t ipaddruip_ipaddr_t 定义:/*** Repressentation of an IP a

uip main函数分析1_IP地址的实现

    uip_ipaddr_t ipaddr;

    uip_ipaddr_t 定义:

    /**
     * Repressentation of an IP address.
     *
     */
    typedef u16_t uip_ip4addr_t[2];//uip_ip4addr_t为u16_t的数组类型,该数组类型有两个数据。
    typedef u16_t uip_ip6addr_t[8];//同上
    #if UIP_CONF_IPV6
    typedef uip_ip6addr_t uip_ipaddr_t;//别名,用来存储IP地址,用两个16位的数据来存储32位的IP地址,具体实现如下。
    #else /* UIP_CONF_IPV6 */
    typedef uip_ip4addr_t uip_ipaddr_t;//别名
    #endif /* UIP_CONF_IPV4 */

    u16_t为16位的数据类型。 移植代码参考如下:typedef unsigned int u16_t;

    main函数中另外的一个函数uip_ipaddr(ipaddr, 192,168,0,2);

    uip_ipaddr函数(其实是一个macro)定义如下:

    /** @} */
/* uIP convenience and converting functions. */
 * These functions can be used for converting between different data formats used by uIP.
 * Construct an IP address from four bytes
 * This function constructs an IP address of the type that uIP handles internally from four bytes. The function is handy for specifying IP addresses to use with e.g. the uip_connect() function.
 * Example:
 \code
 uip_ipaddr_t ipaddr;
 struct uip_conn *c;
 uip_ipaddr(&ipaddr, 192,168,1,2);
 c = uip_connect(&ipaddr, HTONS(80));
 \endcode
 * \param addr A pointer to a uip_ipaddr_t variable that will be
 * filled in with the IP address.
 * \param addr0 The first octet of the IP address.
 * \param addr1 The second octet of the IP address.
 * \param addr2 The third octet of the IP address.
 * \param addr3 The forth octet of the IP address.
 */
#define uip_ipaddr(addr, addr0,addr1,addr2,addr3) do { \
                     ((u16_t *)(addr))[0] = HTONS(((addr0) << 8) | (addr1)); \
                     ((u16_t *)(addr))[1] = HTONS(((addr2) << 8) | (addr3)); \
                  } while(0)

从上述英文介绍可知该宏用于存储IP地址,将IP地址存储在刚才所述的uip_ipaddr_t类型变量中,用于以后函数调用。

热点排行