29 #if defined(_USE_WIN_API) 31 #pragma comment(lib, "wsock32.lib") 32 #elif defined(_USE_LINUX_API) 33 #include <arpa/inet.h> 37 #define strnicmp strncasecmp 46 #define _STR_ISNUMERIC "0123456789" 49 #define _PARA_MAX_COM (7) 50 #define _PARA_MAX_ETH (5) 53 #ifndef __LITTLE_ENDIAN__ 54 #ifndef __BIG_ENDIAN__ 55 #if __BYTE_ORDER == __LITTLE_ENDIAN 56 #define __LITTLE_ENDIAN__ 57 #elif __BYTE_ORDER == __BIG_ENDIAN 58 #define __BIG_ENDIAN__ 74 if ((src == NULL) || ((len = strlen(src)) == 0)) {
97 if (opt != NULL && strlen(opt) >=
_TYPE_MIN) {
98 if (strnicmp(opt,
"tcp",
_TYPE_MIN) == 0) {
101 else if (strnicmp(opt,
"udp",
_TYPE_MIN) == 0) {
104 else if (strnicmp(opt,
"com",
_TYPE_MIN) == 0) {
123 int tmp, type, n = 0;
126 char *opt_cpy = NULL;
133 opt_cpy = (
char *) malloc(strlen(opt) + 1);
135 if (opt_cpy == NULL) {
140 strcpy(opt_cpy, opt);
149 pos_param[n++] = top;
151 pos = strchr(top,
':');
165 tmp = atoi(pos_param[4]);
166 if ((tmp < 0) || (tmp != (
uint16_t) tmp)) {
177 && strcmp(pos_param[3],
"255.255.255.255") != 0)
189 tmp = atoi(pos_param[2]);
190 if ((tmp < 0) || (tmp != (
uint16_t) tmp)) {
201 && strcmp(pos_param[1],
"255.255.255.255") != 0)
213 if (opt_cpy != NULL) {
240 char *opt_cpy = NULL;
247 opt_cpy = (
char *) malloc(strlen(opt) + 1);
249 if (opt_cpy == NULL) {
254 strcpy(opt_cpy, opt);
263 pos_param[n++] = top;
265 pos = strchr(top,
':');
274 if (n == 4 || n == 5) {
283 tmp = atol(pos_param[6]);
284 if (tmp < 0 || 3 < tmp) {
288 param->
flow = (char) tmp;
293 tmp = (int) (atof(pos_param[5]) * 10.0);
312 tmp = atol(pos_param[4]);
313 if (tmp < 5 || 8 < tmp) {
322 if (strlen(pos_param[3]) != 1) {
326 switch (*pos_param[3]) {
357 tmp = atol(pos_param[1]);
358 if ((tmp < 0) || (tmp != (
int) tmp)) {
370 if (opt_cpy != NULL) {
397 tv.
tv_sec = timeout / 1000;
398 tv.
tv_usec = (timeout % 1000) * 1000;
400 ret =
select(sock + 1, &fds, NULL, NULL, &tv);
425 if (device->
sock <= 0)
430 if (!(flag & device->
type))
471 #ifdef __BIG_ENDIAN__ 476 psrc = (
uint8_t *)(src) + len - 1;
479 for (i = 0; i < len; i++) {
483 memcpy(dst, src, len);
497 #ifndef __BIG_ENDIAN__ 502 psrc = (
uint8_t *) (src) + len - 1;
505 for (i = 0; i < len; i++) {
509 memcpy(dst, src, len);
HRESULT check_conn_param(const struct CONN_PARAM_COMMON *device, int flag)
Checks the communication parameters.
HRESULT(* dn_set_timeout)(int sock, uint32_t timeout)
#define ODDPARITY
A definition for serial communication setting.
HRESULT(* dn_clear)(int sock, uint32_t timeout)
HRESULT(* dn_recv)(int sock, char *buf, uint32_t len_buf, uint32_t *len_recved, uint32_t timeout, void *arg)
HRESULT parse_conn_param_serial(const char *opt, struct CONN_PARAM_COM *param)
Parses serial connection parameters.
#define EVENPARITY
A definition for serial communication setting.
void memcpy_be(void *dst, const void *src, uint32_t len)
Orders to big endian.
static uint32_t htonl(uint32_t hostlong)
#define E_HANDLE
Failed because the handle is invalid.
int parse_conn_type(const char *opt)
Parses and returns the connection type.
#define E_INVALIDARG
Failed because some arguments are invalid.
HRESULT(* dn_close)(int *sock)
#define DNGetLastError()
A macro that gets last OS error.
static uint32_t inet_addr(const char *addr)
#define E_OUTOFMEMORY
Failed because there is no enough memory space.
#define DISP_E_OVERFLOW
Failed because out of range.
#define NOPARITY
A definition for serial communication setting.
A type definition for Ethernet connection parameters.
#define ONESTOPBIT
A definition for serial communication setting.
HRESULT check_timeout(int sock, uint32_t timeout)
Checks the communication timeout.
A type definition for common communication parameters.
static uint16_t htons(uint16_t hostshort)
HRESULT(* dn_open)(void *param, int *sock)
static int is_numeric(const char *src)
Checks the argument is numeric or not.
#define FD_SET(fd, fdsetp)
A type definition for serial connection parameters.
static int select(int __nfds, fd_set *__restrict __readfds, fd_set *__restrict __writefds, fd_set *__restrict __exceptfds, struct timeval *__restrict __timeout)
HRESULT parse_conn_param_ether(const char *opt, struct CONN_PARAM_ETH *param)
Parses Ethernet connection parameters.
void memcpy_le(void *dst, const void *src, uint32_t len)
Orders to little endian.
#define E_TIMEOUT
Failed because the communication timed out.
HRESULT(* dn_send)(int sock, const char *buf, uint32_t len_buf, void *arg)
#define OSERR2HRESULT(err)
A macro that returns HREUSLT(0x8091) which means OS error.
#define TWOSTOPBITS
A definition for serial communication setting.