小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

lwip之接口netif

 立志德美 2019-07-17

1、miscellaneous聲明

(1)結(jié)構(gòu)體聲明
struct netif {

  struct netif *next;

  ip_addr_t ip_addr;
  ip_addr_t netmask;
  ip_addr_t gw;

// 接口接收數(shù)據(jù)函數(shù),調(diào)用系統(tǒng)函數(shù)ethernet_input
  netif_input_fn input;

//接口輸出數(shù)據(jù)函數(shù),調(diào)用系統(tǒng)函數(shù)etharp_output
  netif_output_fn output;

//底層硬件輸出數(shù)據(jù)函數(shù),調(diào)用自定義函數(shù)low_level_output
  netif_linkoutput_fn linkoutput;

  void *state;
  u16_t mtu;
  u8_t hwaddr_len;
  u8_t hwaddr[NETIF_MAX_HWADDR_LEN];
  u8_t flags;
  char name[2];
  u8_t num;

 #if ENABLE_LOOPBACK
  /* List of packets to be queued for ourselves. */
  struct pbuf *loop_first;
  struct pbuf *loop_last;
#if LWIP_LOOPBACK_MAX_PBUFS
  u16_t loop_cnt_current;
#endif /* LWIP_LOOPBACK_MAX_PBUFS */
#endif /* ENABLE_LOOPBACK */
};

結(jié)構(gòu)體中的typedef定義

typedef err_t (*netif_init_fn)(struct netif *netif);
typedef err_t (*netif_input_fn)(struct pbuf *p, struct netif *inp);
typedef err_t (*netif_output_fn)(struct netif *netif, struct pbuf *p, ip_addr_t *ipaddr);
typedef err_t (*netif_linkoutput_fn)(struct netif *netif, struct pbuf *p);
(2)全局變量聲明
struct netif *netif_list;      //網(wǎng)絡(luò)接口鏈表指針
struct netif *netif_default;   //default 接口

static u8_t netif_num;
static struct netif loop_netif;

2、loopback interface 介紹

以loopback 接口初始化自定義的接口。

void netif_init(void)
{
#if LWIP_HAVE_LOOPIF
  ip_addr_t loop_ipaddr, loop_netmask, loop_gw;
  IP4_ADDR(&loop_gw, 127,0,0,1);
  IP4_ADDR(&loop_ipaddr, 127,0,0,1);
  IP4_ADDR(&loop_netmask, 255,0,0,0);

// 無操作系統(tǒng)input函數(shù)使用ip_input,若使用操作系統(tǒng),則使用tcpip_input,不經(jīng)過底層網(wǎng)卡數(shù)據(jù)
#if NO_SYS
  netif_add(&loop_netif, &loop_ipaddr, &loop_netmask, &loop_gw, NULL, netif_loopif_init, ip_input);
#else  /* NO_SYS */
  netif_add(&loop_netif, &loop_ipaddr, &loop_netmask, &loop_gw, NULL, netif_loopif_init, tcpip_input);
#endif /* NO_SYS */
  netif_set_up(&loop_netif);

#endif /* LWIP_HAVE_LOOPIF */
}

netif_loopif_init 和netif_add實現(xiàn)對struct netif成員變量的初始化

static err_t netif_loopif_init(struct netif *netif)
{
  netif->name[0] = 'l';
  netif->name[1] = 'o';
  netif->output = netif_loop_output;     //使用函數(shù)net_poll傳送至netif->input函數(shù)
  return ERR_OK;
}

struct netif *netif_add(struct netif *netif, ip_addr_t *ipaddr, ip_addr_t *netmask,
  ip_addr_t *gw, void *state, netif_init_fn init, netif_input_fn input)
{

  ip_addr_set_zero(&netif->ip_addr);
  ip_addr_set_zero(&netif->netmask);
  ip_addr_set_zero(&netif->gw);
  netif->flags = 0;

#if ENABLE_LOOPBACK
  netif->loop_first = NULL;
  netif->loop_last = NULL;
#endif /* ENABLE_LOOPBACK */

  /* remember netif specific state information data */
  netif->state = state;
  netif->num = netif_num++;
  netif->input = input;

  netif_set_addr(netif, ipaddr, netmask, gw);

  /* call user specified initialization function for netif */
  if (init(netif) != ERR_OK) {
    return NULL;
  }

  /* add this netif to the list */
  netif->next = netif_list;
  netif_list = netif;

  return netif;
}

net_set_up實現(xiàn)對struct netif 成員變量flags的設(shè)置

#define NETIF_FLAG_UP           0x01U
#define NETIF_FLAG_BROADCAST    0x02U
#define NETIF_FLAG_POINTTOPOINT 0x04U
#define NETIF_FLAG_DHCP         0x08U
#define NETIF_FLAG_LINK_UP      0x10U
#define NETIF_FLAG_ETHARP       0x20U
#define NETIF_FLAG_ETHERNET     0x40U
#define NETIF_FLAG_IGMP         0x80U

void netif_set_up(struct netif *netif)
{
  if (!(netif->flags & NETIF_FLAG_UP)) {
    netif->flags |= NETIF_FLAG_UP;

    NETIF_STATUS_CALLBACK(netif);

    if (netif->flags & NETIF_FLAG_LINK_UP) {
#if LWIP_ARP
      /* For Ethernet network interfaces, we would like to send a "gratuitous ARP" */ 
      if (netif->flags & (NETIF_FLAG_ETHARP)) {
        etharp_gratuitous(netif);
      }
#endif /* LWIP_ARP */
    }
  }
}

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多