@@ -8,7 +8,7 @@ use errno::{SysResult, SysError, from_ffi};
8
8
pub use self :: linux:: * ;
9
9
10
10
mod ffi {
11
- use libc:: { c_char, c_int} ;
11
+ use libc:: { c_char, c_int, size_t } ;
12
12
pub use libc:: { close, read, write} ;
13
13
14
14
extern {
@@ -29,6 +29,14 @@ mod ffi {
29
29
// run the current process in the background
30
30
// doc: http://man7.org/linux/man-pages/man3/daemon.3.html
31
31
pub fn daemon ( nochdir : c_int , noclose : c_int ) -> c_int ;
32
+
33
+ // sets the hostname to the value given
34
+ // doc: http://man7.org/linux/man-pages/man2/gethostname.2.html
35
+ pub fn gethostname ( name : * mut c_char , len : size_t ) -> c_int ;
36
+
37
+ // gets the hostname
38
+ // doc: http://man7.org/linux/man-pages/man2/gethostname.2.html
39
+ pub fn sethostname ( name : * const c_char , len : size_t ) -> c_int ;
32
40
}
33
41
}
34
42
@@ -102,6 +110,22 @@ pub fn daemon(nochdir: bool, noclose: bool) -> SysResult<()> {
102
110
from_ffi ( res)
103
111
}
104
112
113
+ pub fn sethostname ( name : & [ u8 ] ) -> SysResult < ( ) > {
114
+ let ptr = name. as_ptr ( ) as * const c_char ;
115
+ let len = name. len ( ) as u64 ;
116
+
117
+ let res = unsafe { ffi:: sethostname ( ptr, len) } ;
118
+ from_ffi ( res)
119
+ }
120
+
121
+ pub fn gethostname ( name : & mut [ u8 ] ) -> SysResult < ( ) > {
122
+ let ptr = name. as_mut_ptr ( ) as * mut c_char ;
123
+ let len = name. len ( ) as u64 ;
124
+
125
+ let res = unsafe { ffi:: gethostname ( ptr, len) } ;
126
+ from_ffi ( res)
127
+ }
128
+
105
129
pub fn close ( fd : Fd ) -> SysResult < ( ) > {
106
130
let res = unsafe { ffi:: close ( fd) } ;
107
131
from_ffi ( res)
0 commit comments