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

Low-overhead UDP Functions

8.1UDP functions

These calls to the UDP layer are provided for systems that do not need the overhead of sockets (see Chapter 9 Sockets). These routines impose a lower demand on CPU and system memory requirements than sockets. However, they do not offer the portability of sockets. Most of these calls are found in \inet\udp.c. The exceptions are documented.

The following sections describe the low-overhead UDP functions. They are as follows:

udp_alloc() on page 8-2

udp_close() on page 8-3

udp_open() on page 8-4

udp_send() on page 8-5

udp_socket() on page 8-6.

8.1.1udp_alloc()

This returns a packet large enough for the UDP data. It works by adding the space needed for UDP, IP, and MAC headers to the datalen passed, and calling pk_alloc().

Syntax

PACKET udp_alloc(int datalen, int optlen)

where:

datalen is the length of UDP data, not including the UDP header.

optlen is the length of IP options, if any. This is typically 0.

Return value

Returns one of the following:

PACKET if successful.

NULL if a large enough packet was not available.

When the packet has been successfully transmitted by the hardware, it should be released by calling pk_free(). This is usually done by the sending interface.

8-2

Copyright © 1998 and 1999 ARM Limited. All rights reserved.

ARM DUI 0079B

Low-overhead UDP Functions

8.1.2udp_close()

This function should be called by your application when it has finished with a UDP connection and is no longer interested in receiving UDP packets associated with the connection.

Syntax

void udp_close(UDPCONN con)

where:

 

con

is the UDP connection identifier returned by a previous call to

 

udp_open().

Return value

None.

ARM DUI 0079B

Copyright © 1998 and 1999 ARM Limited. All rights reserved.

8-3

Low-overhead UDP Functions

8.1.3udp_open()

This function creates a structure in the UDP layer to receive, and pass upwards, UDP packets that match the parameters passed. The foreign host, fhost, and port, fport, can be set to 0 as a wild card, which enables the reception of broadcast datagrams.

The handler function passed is similar to the other call-back handler functions in this section, except that it is also passed a copy of the data pointer which is passed to udp_open(). This can be any data the programmer requires, such as a pointer to another function, or a control structure to aid in demultiplexing the received UDP packet.

Syntax

UDPCONN udp_open(ip_addr fhost, unsigned short fport,

 

unsigned short lport,

 

int (*handler)(PACKET, void *), void *data)

where:

 

fhost

is the host from which you will accept data. It must be set to 0 if listening

 

for any host.

fport

is the foreign port number. It must be set to 0 if listening for datagrams

 

from any foreign port.

lport

is the local port on which to receive data.

handler

is the UDP received callback function.

data

is the data that is passed (along with the received UDP datagram) to the

 

callback handler.

Return value

Returns one of the following:

a UDP connection identifier

if successful. This handle should be passed to udp_close() when the connection is no longer required.

NULL if not successful.

File

\inet\udp_open.c

8-4

Copyright © 1998 and 1999 ARM Limited. All rights reserved.

ARM DUI 0079B

Low-overhead UDP Functions

8.1.4udp_send()

This function sends a UDP datagram to the foreign host in pkt->fhost. Local and remote ports in the UDP header are set from the values passed.

Syntax

int udp_send(unsigned short fport, unsigned short lport,

PACKET pkt)

where:

fport is the target UDP port. lport is the local UDP port.

pkt is the packet to send, with nb_prot, nb_plen, and fhost (members of the PACKET structure) set.

Return value

Returns one of the following:

0 if successful.

ENP_Code if not successful (see ENP_ error codes on page A-2).

ARM DUI 0079B

Copyright © 1998 and 1999 ARM Limited. All rights reserved.

8-5