26.12.2013 Views

lwIP - A Minimal TCP/IP implementation - Wikia

lwIP - A Minimal TCP/IP implementation - Wikia

lwIP - A Minimal TCP/IP implementation - Wikia

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

7 NETWORK INTERFACES<br />

next<br />

prev<br />

used = 1<br />

next<br />

prev<br />

used = 0<br />

next<br />

prev<br />

used = 1<br />

Figure 4. The memory allocation structure.<br />

struct netif {<br />

struct netif *next;<br />

char name[2];<br />

int num;<br />

struct ip_addr ip_addr;<br />

struct ip_addr netmask;<br />

struct ip_addr gw;<br />

void (* input)(struct pbuf *p, struct netif *inp);<br />

int (* output)(struct netif *netif, struct pbuf *p,<br />

struct ip_addr *ipaddr);<br />

void *state;<br />

};<br />

Figure 5. The netif structure.<br />

interface is configured by a human operator at runtime. The name is set by the device driver and<br />

should reflect the kind of hardware that is represented by the network interface. For example, a<br />

network interface for a Bluetooth driver might have the name bt and a network interface for IEEE<br />

802.11b WLAN hardware could have the name wl. Since the names not necessarily are unique,<br />

the num field is used to distinguish different network interfaces of the same kind.<br />

The three <strong>IP</strong> addresses ip addr, netmask and gw are used by the <strong>IP</strong> layer when sending and<br />

receiving packets, and their use is described in the next section. It is not possible to configure a<br />

network interface with more than one <strong>IP</strong> address. Rather, one network interface would have to be<br />

created for each <strong>IP</strong> address.<br />

The input pointer points to the function the device driver should call when a packet has been<br />

received.<br />

A network interface is connected to a device driver through the output pointer. This pointer<br />

points to a function in the device driver that transmits a packet on the physical network and it is<br />

called by the <strong>IP</strong> layer when a packet is to be sent. This field is filled by the initialization function<br />

of the device driver. The third argument to the output function, ipaddr, is the <strong>IP</strong> address of<br />

the host that should receive the actual link layer frame. It does not have to be the same as the<br />

destination address of the <strong>IP</strong> packet. In particular, when sending an <strong>IP</strong> packet to a host that is<br />

not on the local network, the link level frame will be sent to a router on the network. In this case,<br />

the <strong>IP</strong> address given to the output function will be the <strong>IP</strong> address of the router.<br />

Finally, the state pointer points to device driver specific state for the network interface and<br />

6

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!