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
58bb5a96
Commit
58bb5a96
authored
6 months ago
by
Peter Limkilde Svendsen
Committed by
Jeremy Soller
6 months ago
Browse files
Options
Downloads
Patches
Plain Diff
Use unsafe blocks in arpa/inet.h implementation
parent
3da3ff11
No related branches found
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
+31
-20
31 additions, 20 deletions
src/header/arpa_inet/mod.rs
with
31 additions
and
20 deletions
src/header/arpa_inet/mod.rs
+
31
−
20
View file @
58bb5a96
//! arpa/inet implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xns/arpainet.h.html
//! arpa/inet implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xns/arpainet.h.html
// TODO: set this for entire crate when possible
#![deny(unsafe_op_in_unsafe_fn)]
use
core
::{
use
core
::{
ptr
,
slice
,
ptr
,
slice
,
str
::{
self
,
FromStr
},
str
::{
self
,
FromStr
},
...
@@ -38,19 +41,21 @@ pub extern "C" fn ntohs(netshort: uint16_t) -> uint16_t {
...
@@ -38,19 +41,21 @@ pub extern "C" fn ntohs(netshort: uint16_t) -> uint16_t {
#[no_mangle]
#[no_mangle]
pub
unsafe
extern
"C"
fn
inet_aton
(
cp
:
*
const
c_char
,
inp
:
*
mut
in_addr
)
->
c_int
{
pub
unsafe
extern
"C"
fn
inet_aton
(
cp
:
*
const
c_char
,
inp
:
*
mut
in_addr
)
->
c_int
{
// TODO: octal/hex
// TODO: octal/hex
inet_pton
(
AF_INET
,
cp
,
inp
as
*
mut
c_void
)
unsafe
{
inet_pton
(
AF_INET
,
cp
,
inp
as
*
mut
c_void
)
}
}
}
#[no_mangle]
#[no_mangle]
pub
unsafe
extern
"C"
fn
inet_ntoa
(
addr
:
in_addr
)
->
*
const
c_char
{
pub
unsafe
extern
"C"
fn
inet_ntoa
(
addr
:
in_addr
)
->
*
const
c_char
{
static
mut
NTOA_ADDR
:
[
c_char
;
16
]
=
[
0
;
16
];
static
mut
NTOA_ADDR
:
[
c_char
;
16
]
=
[
0
;
16
];
inet_ntop
(
unsafe
{
AF_INET
,
inet_ntop
(
&
addr
as
*
const
in_addr
as
*
const
c_void
,
AF_INET
,
NTOA_ADDR
.as_mut_ptr
(),
&
addr
as
*
const
in_addr
as
*
const
c_void
,
16
,
NTOA_ADDR
.as_mut_ptr
(),
)
16
,
)
}
}
}
#[no_mangle]
#[no_mangle]
...
@@ -59,12 +64,14 @@ pub unsafe extern "C" fn inet_pton(domain: c_int, src: *const c_char, dest: *mut
...
@@ -59,12 +64,14 @@ pub unsafe extern "C" fn inet_pton(domain: c_int, src: *const c_char, dest: *mut
platform
::
ERRNO
.set
(
EAFNOSUPPORT
);
platform
::
ERRNO
.set
(
EAFNOSUPPORT
);
-
1
-
1
}
else
{
}
else
{
let
s_addr
=
slice
::
from_raw_parts_mut
(
let
s_addr
=
unsafe
{
&
mut
(
*
(
dest
as
*
mut
in_addr
))
.s_addr
as
*
mut
_
as
*
mut
u8
,
slice
::
from_raw_parts_mut
(
4
,
&
mut
(
*
(
dest
as
*
mut
in_addr
))
.s_addr
as
*
mut
_
as
*
mut
u8
,
);
4
,
let
src_cstr
=
CStr
::
from_ptr
(
src
);
)
let
mut
octets
=
str
::
from_utf8_unchecked
(
src_cstr
.to_bytes
())
.split
(
'.'
);
};
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
{
for
i
in
0
..
4
{
if
let
Some
(
n
)
=
octets
.next
()
.and_then
(|
x
|
u8
::
from_str
(
x
)
.ok
())
{
if
let
Some
(
n
)
=
octets
.next
()
.and_then
(|
x
|
u8
::
from_str
(
x
)
.ok
())
{
s_addr
[
i
]
=
n
;
s_addr
[
i
]
=
n
;
...
@@ -94,12 +101,16 @@ pub unsafe extern "C" fn inet_ntop(
...
@@ -94,12 +101,16 @@ pub unsafe extern "C" fn inet_ntop(
platform
::
ERRNO
.set
(
ENOSPC
);
platform
::
ERRNO
.set
(
ENOSPC
);
ptr
::
null
()
ptr
::
null
()
}
else
{
}
else
{
let
s_addr
=
slice
::
from_raw_parts
(
let
s_addr
=
unsafe
{
&
(
*
(
src
as
*
const
in_addr
))
.s_addr
as
*
const
_
as
*
const
u8
,
slice
::
from_raw_parts
(
4
,
&
(
*
(
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
]);
let
addr
=
format!
(
"{}.{}.{}.{}
\0
"
,
s_addr
[
0
],
s_addr
[
1
],
s_addr
[
2
],
s_addr
[
3
]);
ptr
::
copy
(
addr
.as_ptr
()
as
*
const
c_char
,
dest
,
addr
.len
());
unsafe
{
ptr
::
copy
(
addr
.as_ptr
()
as
*
const
c_char
,
dest
,
addr
.len
());
}
dest
dest
}
}
}
}
...
@@ -108,7 +119,7 @@ pub unsafe extern "C" fn inet_ntop(
...
@@ -108,7 +119,7 @@ pub unsafe extern "C" fn inet_ntop(
pub
unsafe
extern
"C"
fn
inet_addr
(
cp
:
*
const
c_char
)
->
in_addr_t
{
pub
unsafe
extern
"C"
fn
inet_addr
(
cp
:
*
const
c_char
)
->
in_addr_t
{
let
mut
val
:
in_addr
=
in_addr
{
s_addr
:
0
};
let
mut
val
:
in_addr
=
in_addr
{
s_addr
:
0
};
if
inet_aton
(
cp
,
&
mut
val
)
>
0
{
if
unsafe
{
inet_aton
(
cp
,
&
mut
val
)
}
>
0
{
val
.s_addr
val
.s_addr
}
else
{
}
else
{
INADDR_NONE
INADDR_NONE
...
@@ -154,5 +165,5 @@ pub extern "C" fn inet_netof(input: in_addr) -> in_addr_t {
...
@@ -154,5 +165,5 @@ pub extern "C" fn inet_netof(input: in_addr) -> in_addr_t {
#[no_mangle]
#[no_mangle]
pub
unsafe
extern
"C"
fn
inet_network
(
cp
:
*
mut
c_char
)
->
in_addr_t
{
pub
unsafe
extern
"C"
fn
inet_network
(
cp
:
*
mut
c_char
)
->
in_addr_t
{
ntohl
(
inet_addr
(
cp
))
ntohl
(
unsafe
{
inet_addr
(
cp
)
}
)
}
}
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