Microchip® Advanced Software Framework

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
sendto

Asynchronous sending function, used to send data on a UDP socket.

Called by the application code when there is data required to be sent on a UDP socket handler. The application code is expected to receive data from a successful bounded socket node. The only difference between this function and the similar send function, is the type of socket the data is received on. This function works only with UDP sockets. After the data is sent, the socket callback function registered using registerSocketCallback(), is expected to receive an event of type SOCKET_MSG_SENDTO.

Functions

NMI_API sint16 sendto (SOCKET sock, void *pvSendBuffer, uint16 u16SendLength, uint16 flags, struct sockaddr *pstrDestAddr, uint8 u8AddrLen)
 

NMI_API sint16 sendto ( SOCKET  sock,
void *  pvSendBuffer,
uint16  u16SendLength,
uint16  flags,
struct sockaddr pstrDestAddr,
uint8  u8AddrLen 
)
Parameters
[in]sockSocket ID, must hold a non negative value. A negative value will return a socket error SOCK_ERR_INVALID_ARG. Indicating that an invalid argument is passed in.
[in]pvSendBufferPointer to a buffer holding data to be transmitted. A NULL value will return a socket error SOCK_ERR_INVALID_ARG. Indicating that an invalid argument is passed in.
[in]u16SendLengthThe buffer size in bytes. It must not exceed SOCKET_BUFFER_MAX_LENGTH.
[in]flagsNot used in the current implementation
[in]pstrDestAddrThe destination address.
[in]u8AddrLenDestination address length in bytes. Not used in the current implementation, only included for BSD compatibility.
Precondition
Sockets must be initialized using socketInit.
Warning
u16SendLength must not exceed SOCKET_BUFFER_MAX_LENGTH.
Use a valid socket (returned from socket ). A valid buffer pointer must be used (not NULL).
Successful completion of a call to sendto() does not guarantee delivery of the message, A negative return value indicates only locally-detected errors
See Also
socketInit recvfrom sendto socket connect accept send
Returns
The function returns SOCK_ERR_NO_ERROR for successful operation and a negative value (indicating the error) otherwise.

References m2m_memset(), M2M_REQ_DATA_PKT, MAX_SOCKET, NM_BSP_B_L_16, NULL, in_addr::s_addr, sockaddr_in::sin_addr, sockaddr_in::sin_family, sockaddr_in::sin_port, tstrSendCmd::sock, SOCK_ERR_BUFFER_FULL, SOCK_ERR_INVALID_ARG, SOCK_ERR_NO_ERROR, SOCKET_BUFFER_MAX_LENGTH, SOCKET_CMD_SENDTO, SOCKET_REQUEST, tstrSendCmd::strAddr, tstrSendCmd::u16DataSize, tstrSockAddr::u16Family, tstrSockAddr::u16Port, tstrSocket::u16SessionID, tstrSendCmd::u16SessionID, tstrSockAddr::u32IPAddr, and UDP_TX_PACKET_OFFSET.

Referenced by demo_start().