Maxim Integrated High-Speed Microcontroller Users Guide: Network Microcontroller Supplement User Manual

Page 197

Advertising
background image

High-Speed Microcontroller User’s

Guide: Network Microcontroller

Supplement

197

recvfrom

Description:

int recvfrom(
int
s,

/* receive on socket with handle s */

void *buf,

/* datagram data array at *buf */

int len,

/* size of datagram received */

int flags,

/* currently ignored */

struct sockaddr *addr,

/* remote address */

int addrlen);

/* size of address structure */

The

recvfrom function receives a UDP datagram. This function receives a message on socket s, storing the message at *buf.

len is the size of buf. If addr is not NULL, the remote address is filled in at *addr. The flags parameter is ignored.

recvfrom

returns the number of bytes read. If no data is available on the socket,

recvfrom blocks for the amount of time specified with

the

setsockopt/SO_TIMEOUT call. Note: It is generally required to use bind in order to first assign a local port to the socket.

connect

Description:

int connect(
int s,

/* socket to connect to a specific address */

struct sockaddr *addr,

/* address to which socket s should be connected */

int addrlen);

/* size of address structure */

The

connect function connects a TCP socket to the specified address. This function connects the sockets to the remote

address specified by the addr structure and returns a success/failure code in the accumulator.

Connect can only be used

once with each socket.

bind

Description:

int bind(
int s,

/* socket to bind to specified address/port */

struct sockaddr *addr,

/* address to which socket s should be bound */

int addrlen);

/* length of addr structure */

The

bind function binds a socket to the specified address. This function assigns a local address and port at *addr to the sock-

et s. The combination of IP address and port is often referred to as “name.” Binding a socket is necessary for server sockets.

For client sockets, use

bind if a specific source port is requested. Socket s is to be assigned a local name, addr contains the

local address (IP and port values). The

bind function returns a success/failure code in the accumulator.

INPUT

PARAMETER#–DESCRIPTION

OUTPUT

DESCRIPTION

s

*addr

addrlen

Param0[0]–socket handle #

Param1[0:2]–pointer to target addr

Param2[0]–size of addr structure

ACC

Return value (= 0 for success)

INPUT

PARAMETER#–DESCRIPTION

OUTPUT

DESCRIPTION

s

*addr

addrlen

Param0[0]–socket handle #

Param1[0:2]–pointer to target addr

Param2[0]–size of addr structure

ACC

Return value (= 0 for success)

INPUT

PARAMETER#–DESCRIPTION

OUTPUT

DESCRIPTION

s

*buf

len

flags

*addr

addrlen

Param0[0]–socket handle #

Param1[0:2]–pointer to UDP data

Param2[0:1]–size of datagram

Param3–currently ignored

Param4[0:2]–pointer to target addr

Param5[0]–size of addr structure

ACC

R1:R0

Return value (= 0 for success)

Number of bytes received

Maxim Integrated

Advertising