Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F4498212
net.c
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
net.c
View Options
// stub: minimal node:net implementation (isIP, isIPv4, isIPv6)
// just enough for vite to resolve the module and validate hostnames
#include
<string.h>
#ifdef _WIN32
#include
<winsock2.h>
#include
<ws2tcpip.h>
#else
#include
<arpa/inet.h>
#endif
#include
"ant.h"
#include
"internal.h"
// IWYU pragma: keep
static
ant_value_t
net_isIP
(
ant_t
*
js
,
ant_value_t
*
args
,
int
nargs
)
{
if
(
nargs
<
1
)
return
js_mknum
(
0
);
size_t
len
;
const
char
*
host
=
js_getstr
(
js
,
args
[
0
],
&
len
);
if
(
!
host
)
return
js_mknum
(
0
);
struct
in_addr
addr4
;
struct
in6_addr
addr6
;
if
(
inet_pton
(
AF_INET
,
host
,
&
addr4
)
==
1
)
return
js_mknum
(
4
);
if
(
inet_pton
(
AF_INET6
,
host
,
&
addr6
)
==
1
)
return
js_mknum
(
6
);
return
js_mknum
(
0
);
}
static
ant_value_t
net_isIPv4
(
ant_t
*
js
,
ant_value_t
*
args
,
int
nargs
)
{
if
(
nargs
<
1
)
return
js_false
;
size_t
len
;
const
char
*
host
=
js_getstr
(
js
,
args
[
0
],
&
len
);
if
(
!
host
)
return
js_false
;
struct
in_addr
addr
;
return
inet_pton
(
AF_INET
,
host
,
&
addr
)
==
1
?
js_true
:
js_false
;
}
static
ant_value_t
net_isIPv6
(
ant_t
*
js
,
ant_value_t
*
args
,
int
nargs
)
{
if
(
nargs
<
1
)
return
js_false
;
size_t
len
;
const
char
*
host
=
js_getstr
(
js
,
args
[
0
],
&
len
);
if
(
!
host
)
return
js_false
;
struct
in6_addr
addr
;
return
inet_pton
(
AF_INET6
,
host
,
&
addr
)
==
1
?
js_true
:
js_false
;
}
ant_value_t
net_library
(
ant_t
*
js
)
{
ant_value_t
lib
=
js_mkobj
(
js
);
js_set
(
js
,
lib
,
"isIP"
,
js_mkfun
(
net_isIP
));
js_set
(
js
,
lib
,
"isIPv4"
,
js_mkfun
(
net_isIPv4
));
js_set
(
js
,
lib
,
"isIPv6"
,
js_mkfun
(
net_isIPv6
));
return
lib
;
}
File Metadata
Details
Attached
Mime Type
text/x-c
Expires
Sun, May 3, 7:33 AM (15 h, 11 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
536280
Default Alt Text
net.c (1 KB)
Attached To
Mode
rANT Ant
Attached
Detach File
Event Timeline
Log In to Comment