Socket functions/pointers, Parambuffer, Socket functions/pointers parambuffer – Maxim Integrated High-Speed Microcontroller Users Guide: Network Microcontroller Supplement User Manual

Page 196

Advertising
background image

High-Speed Microcontroller User’s

Guide: Network Microcontroller

Supplement

196

SOCKET FUNCTIONS/POINTERS

PARAMBUFFER

The DS80C400 silicon software exports a pointer the six-argument parameter buffer (PARAMBUFFER) that is used by the DHCP task for

its socket-function calls. The user application is free to use this parameter buffer but should recognize that if more than one task needs to

use a parameter buffer, separate buffers must be declared for each task, or the PARAMBUFFER must be protected from concurrent access.

socket

Description:

int socket(

int domain,

/* currently ignored */

int type,

/* type of socket (UDP = 00h or TCP = 01h) */

int protocol);

/* currently ignored */

The

socket function creates a network socket (a local endpoint) for TCP or UDP communication. The type can either be

SOCK_STREAM for TCP sockets or SOCK_DGRAM for UDP sockets. The domain and protocol parameters are ignored. The

socket function returns a socket handle (i.e., an identifier for the new socket), but has no specific local address assigned to
it. To use it as a server socket, the use of

bind is required. To use a streaming (TCP) socket, the socket must be connected

using either

connect or listen/accept. To destroy/free a socket, use closesocket. This is the only function that returns a sock-

et number. All other socket functions require the socket number to be passed to them to access the correct socket.

Note: The

socket function calls gettaskID through the function redirect table to get the current task ID.

closesocket

Description:

int closesocket(
int
s);

/* closes socket with handle = s */

The

closesocket function closes a socket. It closes the socket having handle, which was created by the socket call and

returns a success/failure code in the accumulator.

sendto

Description:

int sendto(
int
s,

/* send to socket with handle s */

void *buf,

/* datagram data array at *buf */

int len,

/* size of datagram to be sent */

int flags,

/* currently ignored */

struct sockaddr *addr,

/* target address */

int addrlen);

/* size of address structure */

The

sendto function sends a UDP datagram to the specified address. The target address is specified at *addr; addrlen is the

size of the sockaddr structure. The datagram itself is referenced by *buf, and len is the size of the datagram. The flags para-

meter is ignored. The

sendto function is unable to detect whether the datagram has successfully reached the destination and

only returns a failure code on local errors. Use

bind to specify a local port number. Without bind, sendto chooses a random

local port.

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

Return value (= 0 for success)

INPUT

PARAMETER#–DESCRIPTION

OUTPUT

DESCRIPTION

s

Param0[0]–socket handle #

ACC

Return value (= 0 for success)

INPUT

PARAMETER#–DESCRIPTION

OUTPUT

DESCRIPTION

domain

type

protocol

Param0–currently ignored

Param1[0]–00h = UDP

01h = TCP

Param2–currently ignored

ACC

R0

Return value (= 0 for success)

Socket handle

Maxim Integrated

Advertising