Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
(ARM).Porting TCP-IP programmer's guide.Ver 1.6.pdf
Скачиваний:
43
Добавлен:
23.08.2013
Размер:
2.64 Mб
Скачать

Internal Functions

10.2IP routines

The IP routines are located in various files in the inet directory and are as follows:

ip_write() on page 10-5

ip2mac() on page 10-6

ip_mymach() on page 10-7

iproute() on page 10-8

add_route() on page 10-9

ip_rcv() on page 10-10

parse_ipad() on page 10-11

pk_alloc() on page 10-12

pk_free() on page 10-13.

10-4

Copyright © 1998-2001 ARM Limited. All rights reserved.

ARM DUI 0144B

Internal Functions

10.2.1ip_write()

The ip_write() routine fills in the Internet header in the packet and sends the packet through the appropriate net interface.

Syntax

int ip_write(u_char prot, PACKET p); where:

prot

Indicates which protocol the packet is carrying (TCP, UDP, ICMP).

p

Is the packet to send.

Usage

This routine uses routing. You call it with the p->nb_plen and p->nb_prot fields set to the start of the upper (UDP) layer, and with the p->fhost field set to the target IP address.

Return values

Return one of the following:

0

If the transmission was successful.

ENP_SEND_PENDING

 

If it is waiting for ARP.

ENP_ code

If an error is detected (see ENP_ error codes on page A-2).

Location

The ip_write() routine is found in the following file:

inet\ip.c

ARM DUI 0144B

Copyright © 1998-2001 ARM Limited. All rights reserved.

10-5

Internal Functions

10.2.2ip2mac()

The ip2mac() routine takes as input an outgoing IP packet with no MAC information and tries to resolve an Ethernet address matching the passed IP address.

Syntax

int ip2mac(PACKET pkt, ip_addr dest_ip);

where:

pkt

Is the packet itself, without the MAC address

dest_ip Is the IP address of the host or gateway.

Usage

If the MAC address is not already cached, an ARP request is broadcast for the missing IP address. The packet is then attached to the pending pointer. The packet is sent when the ARP reply comes in, or it is freed if the request times out.

Return values

Returns one of the following values:

SUCCESS (0)

If the packet was sent.

ENP_SEND_PENDING

If awaiting the ARP reply.

SEND_FAILED

If an error was detected.

Location

The ip2mac() routine is found in the following file:

inet/ipnet.c

10-6

Copyright © 1998-2001 ARM Limited. All rights reserved.

ARM DUI 0144B

Internal Functions

10.2.3ip_mymach()

The ip_mymach() routine returns the address of your machine, relative to a given foreign host IP address.

Syntax

ip_addr ip_mymach(ip_addr host);

where:

host

Is the IP address of the foreign host.

Usage

On a single-home host, this always returns the IP address of the sole interface. On a router, it returns the address of the interface where packets for the host are routed.

Return value

This routine returns the IP address of the interface used to send packets to host.

Location

The ip_mymach() routine is found in the following file:

inet\ip.c

ARM DUI 0144B

Copyright © 1998-2001 ARM Limited. All rights reserved.

10-7