Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
relibc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Peter Limkilde Svendsen
relibc
Commits
b36ae4ca
Commit
b36ae4ca
authored
1 month ago
by
Peter Limkilde Svendsen
Browse files
Options
Downloads
Patches
Plain Diff
Reorder functions alphabetically
parent
5ec734a6
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/header/arpa_inet/mod.rs
+98
-98
98 additions, 98 deletions
src/header/arpa_inet/mod.rs
with
98 additions
and
98 deletions
src/header/arpa_inet/mod.rs
+
98
−
98
View file @
b36ae4ca
...
...
@@ -32,104 +32,6 @@ pub extern "C" fn htons(hostshort: uint16_t) -> uint16_t {
hostshort
.to_be
()
}
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/htonl.html>.
#[no_mangle]
pub
extern
"C"
fn
ntohl
(
netlong
:
uint32_t
)
->
uint32_t
{
u32
::
from_be
(
netlong
)
}
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/htonl.html>.
#[no_mangle]
pub
extern
"C"
fn
ntohs
(
netshort
:
uint16_t
)
->
uint16_t
{
u16
::
from_be
(
netshort
)
}
/// Non-POSIX, see <https://www.man7.org/linux/man-pages/man3/inet_aton.3.html>.
#[no_mangle]
pub
unsafe
extern
"C"
fn
inet_aton
(
cp
:
*
const
c_char
,
inp
:
*
mut
in_addr
)
->
c_int
{
// TODO: octal/hex
unsafe
{
inet_pton
(
AF_INET
,
cp
,
inp
as
*
mut
c_void
)
}
}
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/inet_addr.html>.
///
/// # Deprecation
/// The `inet_ntoa()` function was marked obsolescent in the Open Group Base
/// Specifications Issue 8.
#[deprecated]
#[no_mangle]
pub
unsafe
extern
"C"
fn
inet_ntoa
(
addr
:
in_addr
)
->
*
const
c_char
{
static
mut
NTOA_ADDR
:
[
c_char
;
16
]
=
[
0
;
16
];
unsafe
{
inet_ntop
(
AF_INET
,
&
addr
as
*
const
in_addr
as
*
const
c_void
,
NTOA_ADDR
.as_mut_ptr
(),
16
,
)
}
}
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/inet_ntop.html>.
#[no_mangle]
pub
unsafe
extern
"C"
fn
inet_pton
(
domain
:
c_int
,
src
:
*
const
c_char
,
dest
:
*
mut
c_void
)
->
c_int
{
if
domain
!=
AF_INET
{
platform
::
ERRNO
.set
(
EAFNOSUPPORT
);
-
1
}
else
{
let
s_addr
=
unsafe
{
slice
::
from_raw_parts_mut
(
&
mut
(
*
(
dest
as
*
mut
in_addr
))
.s_addr
as
*
mut
_
as
*
mut
u8
,
4
,
)
};
let
src_cstr
=
unsafe
{
CStr
::
from_ptr
(
src
)
};
let
mut
octets
=
unsafe
{
str
::
from_utf8_unchecked
(
src_cstr
.to_bytes
())
.split
(
'.'
)
};
for
i
in
0
..
4
{
if
let
Some
(
n
)
=
octets
.next
()
.and_then
(|
x
|
u8
::
from_str
(
x
)
.ok
())
{
s_addr
[
i
]
=
n
;
}
else
{
return
0
;
}
}
if
octets
.next
()
==
None
{
1
// Success
}
else
{
0
}
}
}
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/inet_ntop.html>.
#[no_mangle]
pub
unsafe
extern
"C"
fn
inet_ntop
(
domain
:
c_int
,
src
:
*
const
c_void
,
dest
:
*
mut
c_char
,
size
:
socklen_t
,
)
->
*
const
c_char
{
if
domain
!=
AF_INET
{
platform
::
ERRNO
.set
(
EAFNOSUPPORT
);
ptr
::
null
()
}
else
if
size
<
16
{
platform
::
ERRNO
.set
(
ENOSPC
);
ptr
::
null
()
}
else
{
let
s_addr
=
unsafe
{
slice
::
from_raw_parts
(
&
(
*
(
src
as
*
const
in_addr
))
.s_addr
as
*
const
_
as
*
const
u8
,
4
,
)
};
let
addr
=
format!
(
"{}.{}.{}.{}
\0
"
,
s_addr
[
0
],
s_addr
[
1
],
s_addr
[
2
],
s_addr
[
3
]);
unsafe
{
ptr
::
copy
(
addr
.as_ptr
()
as
*
const
c_char
,
dest
,
addr
.len
());
}
dest
}
}
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/inet_addr.html>.
///
/// # Deprecated
...
...
@@ -147,6 +49,13 @@ pub unsafe extern "C" fn inet_addr(cp: *const c_char) -> in_addr_t {
}
}
/// Non-POSIX, see <https://www.man7.org/linux/man-pages/man3/inet_aton.3.html>.
#[no_mangle]
pub
unsafe
extern
"C"
fn
inet_aton
(
cp
:
*
const
c_char
,
inp
:
*
mut
in_addr
)
->
c_int
{
// TODO: octal/hex
unsafe
{
inet_pton
(
AF_INET
,
cp
,
inp
as
*
mut
c_void
)
}
}
/// See <https://pubs.opengroup.org/onlinepubs/7908799/xns/inet_lnaof.html>.
///
/// # Deprecation
...
...
@@ -212,3 +121,94 @@ pub extern "C" fn inet_netof(input: in_addr) -> in_addr_t {
pub
unsafe
extern
"C"
fn
inet_network
(
cp
:
*
mut
c_char
)
->
in_addr_t
{
ntohl
(
unsafe
{
inet_addr
(
cp
)
})
}
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/inet_addr.html>.
///
/// # Deprecation
/// The `inet_ntoa()` function was marked obsolescent in the Open Group Base
/// Specifications Issue 8.
#[deprecated]
#[no_mangle]
pub
unsafe
extern
"C"
fn
inet_ntoa
(
addr
:
in_addr
)
->
*
const
c_char
{
static
mut
NTOA_ADDR
:
[
c_char
;
16
]
=
[
0
;
16
];
unsafe
{
inet_ntop
(
AF_INET
,
&
addr
as
*
const
in_addr
as
*
const
c_void
,
NTOA_ADDR
.as_mut_ptr
(),
16
,
)
}
}
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/inet_ntop.html>.
#[no_mangle]
pub
unsafe
extern
"C"
fn
inet_ntop
(
domain
:
c_int
,
src
:
*
const
c_void
,
dest
:
*
mut
c_char
,
size
:
socklen_t
,
)
->
*
const
c_char
{
if
domain
!=
AF_INET
{
platform
::
ERRNO
.set
(
EAFNOSUPPORT
);
ptr
::
null
()
}
else
if
size
<
16
{
platform
::
ERRNO
.set
(
ENOSPC
);
ptr
::
null
()
}
else
{
let
s_addr
=
unsafe
{
slice
::
from_raw_parts
(
&
(
*
(
src
as
*
const
in_addr
))
.s_addr
as
*
const
_
as
*
const
u8
,
4
,
)
};
let
addr
=
format!
(
"{}.{}.{}.{}
\0
"
,
s_addr
[
0
],
s_addr
[
1
],
s_addr
[
2
],
s_addr
[
3
]);
unsafe
{
ptr
::
copy
(
addr
.as_ptr
()
as
*
const
c_char
,
dest
,
addr
.len
());
}
dest
}
}
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/inet_ntop.html>.
#[no_mangle]
pub
unsafe
extern
"C"
fn
inet_pton
(
domain
:
c_int
,
src
:
*
const
c_char
,
dest
:
*
mut
c_void
)
->
c_int
{
if
domain
!=
AF_INET
{
platform
::
ERRNO
.set
(
EAFNOSUPPORT
);
-
1
}
else
{
let
s_addr
=
unsafe
{
slice
::
from_raw_parts_mut
(
&
mut
(
*
(
dest
as
*
mut
in_addr
))
.s_addr
as
*
mut
_
as
*
mut
u8
,
4
,
)
};
let
src_cstr
=
unsafe
{
CStr
::
from_ptr
(
src
)
};
let
mut
octets
=
unsafe
{
str
::
from_utf8_unchecked
(
src_cstr
.to_bytes
())
.split
(
'.'
)
};
for
i
in
0
..
4
{
if
let
Some
(
n
)
=
octets
.next
()
.and_then
(|
x
|
u8
::
from_str
(
x
)
.ok
())
{
s_addr
[
i
]
=
n
;
}
else
{
return
0
;
}
}
if
octets
.next
()
==
None
{
1
// Success
}
else
{
0
}
}
}
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/htonl.html>.
#[no_mangle]
pub
extern
"C"
fn
ntohl
(
netlong
:
uint32_t
)
->
uint32_t
{
u32
::
from_be
(
netlong
)
}
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/htonl.html>.
#[no_mangle]
pub
extern
"C"
fn
ntohs
(
netshort
:
uint16_t
)
->
uint16_t
{
u16
::
from_be
(
netshort
)
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment