28 #if defined(_USE_WIN_API) 30 #pragma comment(lib, "wsock32.lib") 32 #elif defined(_USE_LINUX_API) 33 #include <arpa/inet.h> 35 #include <sys/socket.h> 57 if (param == NULL || sock == NULL)
102 if (buf == NULL || strlen(buf) == 0 || arg == NULL)
105 len_send = (len_buf != 0) ? len_buf : strlen(buf);
118 if (len_send > len_sended) {
145 if (buf == NULL || len_recved == NULL || arg == NULL)
201 hr =
udp_recv(sock, buf_tmp, len_recv, &len_recved, 0, &opt);
219 if (sock_to == NULL || sock_from == NULL)
HRESULT udp_open(void *param, int *sock)
Opens UDP socket.
static int sendto(SOCKET s, const char *buf, int len, int flags, const struct sockaddr *to, int tolen)
HRESULT udp_close(int *sock)
Closes the socket.
HRESULT udp_recv(int sock, char *buf, uint32_t len_buf, uint32_t *len_recved, uint32_t timeout, void *arg)
Receives UDP packet.
A type definition for parameters of udp_send and udp_recv.
#define FAILED(hr)
A macro that returns TRUE/FALSE. If hr is less than zero, then returns TRUE.
#define E_HANDLE
Failed because the handle is invalid.
#define DEV_BUF_MAX
The maximum buffer size of a packet.
#define E_ACCESSDENIED
Failed because the resource is not ready.
#define E_INVALIDARG
Failed because some arguments are invalid.
static int recvfrom(SOCKET s, char *buf, int len, int flags, struct sockaddr *from, int *fromlen)
#define DNGetLastError()
A macro that gets last OS error.
HRESULT udp_clear(int sock, uint32_t timeout)
Clears the received buffer.
_DN_EXP_SOCKET HRESULT socket_close(int *sock)
Closes the socket.
#define SUCCEEDED(hr)
A macro that returns TRUE/FALSE. If hr is zero or more, then returns TRUE.
_DN_EXP_SOCKET HRESULT socket_bind(const struct CONN_PARAM_ETH *param, int *sock)
Binds the socket with param's source address and source port.
A type definition for Ethernet connection parameters.
HRESULT udp_send(int sock, const char *buf, uint32_t len_buf, void *arg)
Sends UDP packet.
_DN_EXP_SOCKET HRESULT socket_set_timeout(int sock, uint32_t timeout)
Sets timeout value to the socket.
_DN_EXP_SOCKET HRESULT socket_open(int type, int *sock)
Creates a socket.
_DN_EXP_DEVICE HRESULT check_timeout(int sock, uint32_t timeout)
Checks the communication timeout.
HRESULT udp_check_sockaddr(const struct sockaddr_in *sock_to, const struct sockaddr_in *sock_from)
Checks the socket address. If sock_to and sock_from are equivalent, then returns S_OK.
#define E_TIMEOUT
Failed because the communication timed out.
HRESULT udp_set_timeout(int sock, uint32_t timeout)
Sets timeout value to the UDP socket.
#define OSERR2HRESULT(err)
A macro that returns HREUSLT(0x8091) which means OS error.