1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
%% options
copyright owner = Dirk Krause
copyright year = 2015-xxxx
license = bsd
%% module
#include "dk4sock.h"
#include "dk4rec24.h"
$!trace-include
int
dk4socket_wc_inet_pton(
void *pAddr,
size_t szAddr,
int afam,
const wchar_t *src,
dk4_er_t *erp
)
{
#if DK4_ON_WINDOWS && DK4_HAVE_INET_PTON
int back = DK4_SOCKET_RESULT_FAILED;
int res;
if ((NULL != pAddr) && (NULL != src) && (0 < szAddr)) {
dk4socket_error_reset();
res = InetPtonW(afam, src, pAddr);
if (0 < res) {
back = DK4_SOCKET_RESULT_SUCCESS;
} else {
if (0 > res) {
dk4socket_error_report(erp, DK4_E_SOCKET_INET_PTON);
} else {
dk4error_set_simple_error_code(erp, DK4_E_SYNTAX);
}
}
} else {
dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS);
}
return back;
#else
char buf[128];
int back = DK4_SOCKET_RESULT_FAILED;
if ((NULL != pAddr) && (NULL != src) && (0 < szAddr)) {
if (0 != dk4recode_wchar_t_to_char(buf, sizeof(buf), src, erp)) {
back = dk4socket_c8_inet_pton(pAddr, szAddr, afam, buf, erp);
}
} else {
dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS);
}
return back;
#endif
}
|