Lines Matching full:libc
41 /// Convert a std::net::Ipv4Addr into the libc form.
43 pub(crate) const fn ipv4addr_to_libc(addr: net::Ipv4Addr) -> libc::in_addr { in ipv4addr_to_libc()
44 static_assertions::assert_eq_size!(net::Ipv4Addr, libc::in_addr); in ipv4addr_to_libc()
52 /// Convert a std::net::Ipv6Addr into the libc form.
54 pub(crate) const fn ipv6addr_to_libc(addr: &net::Ipv6Addr) -> libc::in6_addr { in ipv6addr_to_libc()
55 static_assertions::assert_eq_size!(net::Ipv6Addr, libc::in6_addr); in ipv6addr_to_libc()
56 // Safe because both are Newtype wrappers around the same libc type in ipv6addr_to_libc()
74 Unix = libc::AF_UNIX,
76 Inet = libc::AF_INET,
78 Inet6 = libc::AF_INET6,
82 Netlink = libc::AF_NETLINK,
92 Packet = libc::AF_PACKET,
96 System = libc::AF_SYSTEM,
100 Ax25 = libc::AF_AX25,
102 Ipx = libc::AF_IPX,
104 AppleTalk = libc::AF_APPLETALK,
109 NetRom = libc::AF_NETROM,
116 Bridge = libc::AF_BRIDGE,
120 AtmPvc = libc::AF_ATMPVC,
124 X25 = libc::AF_X25,
130 Rose = libc::AF_ROSE,
133 Decnet = libc::AF_DECnet,
137 NetBeui = libc::AF_NETBEUI,
142 Security = libc::AF_SECURITY,
146 Key = libc::AF_KEY,
150 Ash = libc::AF_ASH,
154 Econet = libc::AF_ECONET,
158 AtmSvc = libc::AF_ATMSVC,
162 Rds = libc::AF_RDS,
165 Sna = libc::AF_SNA,
169 Irda = libc::AF_IRDA,
173 Pppox = libc::AF_PPPOX,
178 Wanpipe = libc::AF_WANPIPE,
182 Llc = libc::AF_LLC,
186 Ib = libc::AF_IB,
190 Mpls = libc::AF_MPLS,
194 Can = libc::AF_CAN,
198 Tipc = libc::AF_TIPC,
207 Bluetooth = libc::AF_BLUETOOTH,
212 Iucv = libc::AF_IUCV,
216 RxRpc = libc::AF_RXRPC,
224 Isdn = libc::AF_ISDN,
228 Phonet = libc::AF_PHONET,
232 Ieee802154 = libc::AF_IEEE802154,
237 Caif = libc::AF_CAIF,
241 Alg = libc::AF_ALG,
245 Nfc = libc::AF_NFC,
249 Vsock = libc::AF_VSOCK,
260 ImpLink = libc::AF_IMPLINK,
271 Pup = libc::AF_PUP,
282 Chaos = libc::AF_CHAOS,
291 Ns = libc::AF_NS,
302 Iso = libc::AF_ISO,
313 Datakit = libc::AF_DATAKIT,
324 Ccitt = libc::AF_CCITT,
335 Dli = libc::AF_DLI,
346 Lat = libc::AF_LAT,
357 Hylink = libc::AF_HYLINK,
369 Link = libc::AF_LINK,
380 Coip = libc::AF_COIP,
391 Cnt = libc::AF_CNT,
402 Natm = libc::AF_NATM,
406 Unspec = libc::AF_UNSPEC,
410 /// Create a new `AddressFamily` from an integer value retrieved from `libc`, usually from
417 libc::AF_UNIX => Some(AddressFamily::Unix), in from_i32()
418 libc::AF_INET => Some(AddressFamily::Inet), in from_i32()
419 libc::AF_INET6 => Some(AddressFamily::Inet6), in from_i32()
421 libc::AF_NETLINK => Some(AddressFamily::Netlink), in from_i32()
423 libc::AF_SYSTEM => Some(AddressFamily::System), in from_i32()
425 libc::AF_PACKET => Some(AddressFamily::Packet), in from_i32()
435 libc::AF_LINK => Some(AddressFamily::Link), in from_i32()
437 libc::AF_VSOCK => Some(AddressFamily::Vsock), in from_i32()
453 V4(libc::sockaddr_in),
454 V6(libc::sockaddr_in6),
464 InetAddr::V4(libc::sockaddr_in {
469 sin_len: mem::size_of::<libc::sockaddr_in>() as u8,
477 InetAddr::V6(libc::sockaddr_in6 {
482 sin6_len: mem::size_of::<libc::sockaddr_in6>() as u8,
498 InetAddr::V4(libc::sockaddr_in {
506 InetAddr::V6(libc::sockaddr_in6 {
636 pub struct Ipv4Addr(pub libc::in_addr);
648 Ipv4Addr(libc::in_addr { s_addr: ip })
659 Ipv4Addr(libc::in_addr { s_addr: libc::INADDR_ANY })
694 pub struct Ipv6Addr(pub libc::in6_addr);
718 Ipv6Addr(libc::in6_addr{s6_addr: to_u8_array!(a,b,c,d,e,f,g,h)})
750 sun: libc::sockaddr_un,
778 unsafe fn get(sun: &'a libc::sockaddr_un, sun_len: u8) -> Self { in get()
779 assert!(sun_len as usize >= offset_of!(libc::sockaddr_un, sun_path)); in get()
781 sun_len as usize - offset_of!(libc::sockaddr_un, sun_path); in get()
816 let mut ret = libc::sockaddr_un { in new()
828 + offset_of!(libc::sockaddr_un, sun_path)) in new()
863 let mut ret = libc::sockaddr_un { in new_abstract()
872 (path.len() + 1 + offset_of!(libc::sockaddr_un, sun_path)) in new_abstract()
892 let ret = libc::sockaddr_un { in new_unnamed()
897 let sun_len: u8 = offset_of!(libc::sockaddr_un, sun_path).try_into().unwrap(); in new_unnamed()
914 sun: libc::sockaddr_un, in from_raw_parts()
969 self.sun_len() as usize - offset_of!(libc::sockaddr_un, sun_path) in path_len()
973 pub fn as_ptr(&self) -> *const libc::sockaddr_un { in as_ptr()
978 pub fn as_mut_ptr(&mut self) -> *mut libc::sockaddr_un { in as_mut_ptr()
1006 fn len(&self) -> libc::socklen_t { in len()
1011 addr: *const libc::sockaddr, in from_raw()
1012 len: Option<libc::socklen_t>, in from_raw()
1018 if (l as usize) < offset_of!(libc::sockaddr_un, sun_path) in from_raw()
1019 || l > u8::MAX as libc::socklen_t in from_raw()
1024 if (*addr).sa_family as i32 != libc::AF_UNIX { in from_raw()
1027 let mut su: libc::sockaddr_un = mem::zeroed(); in from_raw()
1028 let sup = &mut su as *mut libc::sockaddr_un as *mut u8; in from_raw()
1036 mem::size_of::<libc::sockaddr_un>() as libc::socklen_t in from_raw()
1039 let su_len = len.unwrap_or((*addr).sa_len as libc::socklen_t); in from_raw()
1046 fn size() -> libc::socklen_t in size()
1050 mem::size_of::<libc::sockaddr_un>() as libc::socklen_t in size()
1054 impl AsRef<libc::sockaddr_un> for UnixAddr {
1055 fn as_ref(&self) -> &libc::sockaddr_un { in as_ref()
1099 /// Most implementors also implement `AsRef<libc::XXX>` to access their
1104 fn as_ptr(&self) -> *const libc::sockaddr { in as_ptr()
1105 self as *const Self as *const libc::sockaddr in as_ptr() constant
1116 /// `libc::sockaddr`. For example, `libc::sockaddr_in`,
1117 /// `libc::sockaddr_in6`, etc.
1130 addr: *const libc::sockaddr, in from_raw()
1131 len: Option<libc::socklen_t>, in from_raw()
1155 (*(self as *const Self as *const libc::sockaddr)).sa_family as i32 in family() constant
1171 fn len(&self) -> libc::socklen_t {
1176 (*(self as *const Self as *const libc::sockaddr)).sa_len
1185 fn len(&self) -> libc::socklen_t {
1189 mem::size_of_val(self) as libc::socklen_t
1195 fn size() -> libc::socklen_t in size()
1199 mem::size_of::<Self>() as libc::socklen_t in size()
1204 fn as_mut_ptr(&mut self) -> *mut libc::sockaddr { in as_mut_ptr()
1214 fn as_ptr(&self) -> *const libc::sockaddr { in as_ptr()
1219 _: *const libc::sockaddr, in from_raw()
1220 _: Option<libc::socklen_t>, in from_raw()
1232 fn len(&self) -> libc::socklen_t { in len()
1239 // doesn't allow direct access to the libc fields, which we need. So we
1244 pub struct SockaddrIn(libc::sockaddr_in);
1250 pub const fn ip(&self) -> libc::in_addr_t { in ip()
1256 Self(libc::sockaddr_in { in new()
1269 sin_addr: libc::in_addr { in new()
1288 addr: *const libc::sockaddr, in from_raw()
1289 len: Option<libc::socklen_t>, in from_raw()
1295 if l != mem::size_of::<libc::sockaddr_in>() as libc::socklen_t { in from_raw()
1299 if (*addr).sa_family as i32 != libc::AF_INET { in from_raw()
1307 impl AsRef<libc::sockaddr_in> for SockaddrIn {
1308 fn as_ref(&self) -> &libc::sockaddr_in { in as_ref()
1333 Self(libc::sockaddr_in { in from()
1344 sin_len: mem::size_of::<libc::sockaddr_in>() as u8, in from()
1376 pub struct SockaddrIn6(libc::sockaddr_in6);
1407 addr: *const libc::sockaddr, in from_raw()
1408 len: Option<libc::socklen_t>, in from_raw()
1414 if l != mem::size_of::<libc::sockaddr_in6>() as libc::socklen_t { in from_raw()
1418 if (*addr).sa_family as i32 != libc::AF_INET6 { in from_raw()
1426 impl AsRef<libc::sockaddr_in6> for SockaddrIn6 {
1427 fn as_ref(&self) -> &libc::sockaddr_in6 { in as_ref()
1451 Self(libc::sockaddr_in6 { in from()
1462 sin6_len: mem::size_of::<libc::sockaddr_in6>() as u8, in from()
1533 ss: libc::sockaddr_storage,
1542 addr: *const libc::sockaddr, in from_raw()
1543 l: Option<libc::socklen_t>, in from_raw()
1553 if ulen < offset_of!(libc::sockaddr, sa_data) in from_raw()
1554 || ulen > mem::size_of::<libc::sockaddr_storage>() in from_raw()
1558 let mut ss: libc::sockaddr_storage = mem::zeroed(); in from_raw()
1559 let ssp = &mut ss as *mut libc::sockaddr_storage as *mut u8; in from_raw()
1567 if i32::from(ss.ss_family) == libc::AF_UNIX { in from_raw()
1570 … (*(&mut ss as *mut libc::sockaddr_storage as *mut UnixAddr)).sun_len = len as u8; in from_raw()
1580 libc::AF_ALG => { in from_raw()
1584 libc::AF_INET => { in from_raw()
1588 libc::AF_INET6 => { in from_raw()
1602 libc::AF_LINK => { in from_raw()
1606 libc::AF_NETLINK => { in from_raw()
1615 libc::AF_PACKET => { in from_raw()
1622 libc::AF_SYSTEM => { in from_raw()
1626 libc::AF_VSOCK => { in from_raw()
1640 fn len(&self) -> libc::socklen_t { in len()
1645 None => mem::size_of_val(self) as libc::socklen_t in len()
1661 && self.len() >= mem::size_of::<$libc_ty>() as libc::socklen_t
1673 && self.len() >= mem::size_of::<$libc_ty>() as libc::socklen_t
1694 let p = unsafe{ &self.ss as *const libc::sockaddr_storage }; in as_unix_addr()
1706 len < offset_of!(libc::sockaddr_un, sun_path) || in as_unix_addr()
1707 len > mem::size_of::<libc::sockaddr_un>() { in as_unix_addr()
1723 let p = unsafe{ &self.ss as *const libc::sockaddr_storage }; in as_unix_addr_mut()
1735 len < offset_of!(libc::sockaddr_un, sun_path) || in as_unix_addr_mut()
1736 len > mem::size_of::<libc::sockaddr_un>() { in as_unix_addr_mut()
1745 AddressFamily::Alg, libc::sockaddr_alg, alg}
1755 AddressFamily::Packet, libc::sockaddr_ll, dl}
1769 AddressFamily::Link, libc::sockaddr_dl, dl}
1774 AddressFamily::Inet, libc::sockaddr_in, sin}
1779 AddressFamily::Inet6, libc::sockaddr_in6, sin6}
1783 AddressFamily::Netlink, libc::sockaddr_nl, nl}
1788 AddressFamily::System, libc::sockaddr_ctl, sctl}
1793 AddressFamily::Vsock, libc::sockaddr_vm, vsock}
1811 libc::AF_ALG => self.alg.fmt(f), in fmt()
1813 libc::AF_INET => self.sin.fmt(f), in fmt()
1815 libc::AF_INET6 => self.sin6.fmt(f), in fmt()
1826 libc::AF_LINK => self.dl.fmt(f), in fmt()
1828 libc::AF_NETLINK => self.nl.fmt(f), in fmt()
1835 libc::AF_PACKET => self.dl.fmt(f), in fmt()
1838 libc::AF_SYSTEM => self.sctl.fmt(f), in fmt()
1839 libc::AF_UNIX => self.su.fmt(f), in fmt()
1841 libc::AF_VSOCK => self.vsock.fmt(f), in fmt()
1885 libc::AF_ALG => self.alg.hash(s), in hash()
1887 libc::AF_INET => self.sin.hash(s), in hash()
1889 libc::AF_INET6 => self.sin6.hash(s), in hash()
1900 libc::AF_LINK => self.dl.hash(s), in hash()
1902 libc::AF_NETLINK => self.nl.hash(s), in hash()
1909 libc::AF_PACKET => self.dl.hash(s), in hash()
1912 libc::AF_SYSTEM => self.sctl.hash(s), in hash()
1913 libc::AF_UNIX => self.su.hash(s), in hash()
1915 libc::AF_VSOCK => self.vsock.hash(s), in hash()
1927 (libc::AF_ALG, libc::AF_ALG) => self.alg == other.alg, in eq()
1929 (libc::AF_INET, libc::AF_INET) => self.sin == other.sin, in eq()
1931 (libc::AF_INET6, libc::AF_INET6) => self.sin6 == other.sin6, in eq()
1942 (libc::AF_LINK, libc::AF_LINK) => self.dl == other.dl, in eq()
1944 (libc::AF_NETLINK, libc::AF_NETLINK) => self.nl == other.nl, in eq()
1951 (libc::AF_PACKET, libc::AF_PACKET) => self.dl == other.dl, in eq()
1954 (libc::AF_SYSTEM, libc::AF_SYSTEM) => self.sctl == other.sctl, in eq()
1955 (libc::AF_UNIX, libc::AF_UNIX) => self.su == other.su, in eq()
1957 (libc::AF_VSOCK, libc::AF_VSOCK) => self.vsock == other.vsock, in eq()
1974 fn as_mut_ptr(&mut self) -> *mut libc::sockaddr { in as_mut_ptr()
1975 self as *mut Self as *mut libc::sockaddr in as_mut_ptr()
2106 /// Creates a `SockAddr` struct from libc's sockaddr.
2118 addr: *const libc::sockaddr, in from_libc_sockaddr()
2179 /// Conversion from nix's SockAddr type to the underlying libc sockaddr type.
2181 /// This is useful for interfacing with other libc functions that don't yet have nix wrappers.
2186 pub fn as_ffi_pair(&self) -> (&libc::sockaddr, libc::socklen_t) { in as_ffi_pair()
2192 &*(addr as *const libc::sockaddr_in in as_ffi_pair() constant
2193 as *const libc::sockaddr) in as_ffi_pair() constant
2195 mem::size_of_val(addr) as libc::socklen_t, in as_ffi_pair()
2201 &*(addr as *const libc::sockaddr_in6 in as_ffi_pair() constant
2202 as *const libc::sockaddr) in as_ffi_pair() constant
2204 mem::size_of_val(addr) as libc::socklen_t, in as_ffi_pair()
2209 &*(&unix_addr.sun as *const libc::sockaddr_un in as_ffi_pair() constant
2210 as *const libc::sockaddr) in as_ffi_pair() constant
2212 unix_addr.sun_len() as libc::socklen_t, in as_ffi_pair()
2218 &*(sa as *const libc::sockaddr_nl as *const libc::sockaddr) in as_ffi_pair() constant
2220 mem::size_of_val(sa) as libc::socklen_t, in as_ffi_pair()
2226 &*(sa as *const libc::sockaddr_alg as *const libc::sockaddr) in as_ffi_pair() constant
2228 mem::size_of_val(sa) as libc::socklen_t, in as_ffi_pair()
2237 &*(sa as *const libc::sockaddr_ctl as *const libc::sockaddr) in as_ffi_pair() constant
2239 mem::size_of_val(sa) as libc::socklen_t, in as_ffi_pair()
2246 &*(addr as *const libc::sockaddr_ll in as_ffi_pair() constant
2247 as *const libc::sockaddr) in as_ffi_pair() constant
2249 mem::size_of_val(addr) as libc::socklen_t, in as_ffi_pair()
2264 &*(addr as *const libc::sockaddr_dl in as_ffi_pair() constant
2265 as *const libc::sockaddr) in as_ffi_pair() constant
2267 mem::size_of_val(addr) as libc::socklen_t, in as_ffi_pair()
2273 &*(sa as *const libc::sockaddr_vm as *const libc::sockaddr) in as_ffi_pair() constant
2275 mem::size_of_val(sa) as libc::socklen_t, in as_ffi_pair()
2325 addr: *const libc::sockaddr, in from_raw()
2326 _len: Option<libc::socklen_t>, in from_raw()
2337 use libc::{sa_family_t, sockaddr_nl};
2375 addr: *const libc::sockaddr, in from_raw()
2376 len: Option<libc::socklen_t>, in from_raw()
2382 if l != mem::size_of::<libc::sockaddr_nl>() as libc::socklen_t { in from_raw()
2386 if (*addr).sa_family as i32 != libc::AF_NETLINK { in from_raw()
2393 impl AsRef<libc::sockaddr_nl> for NetlinkAddr {
2394 fn as_ref(&self) -> &libc::sockaddr_nl { in as_ref()
2410 use libc::{c_char, sockaddr_alg, AF_ALG};
2423 addr: *const libc::sockaddr, in from_raw()
2424 l: Option<libc::socklen_t>, in from_raw()
2430 if l != mem::size_of::<libc::sockaddr_alg>() as libc::socklen_t in from_raw()
2435 if (*addr).sa_family as i32 != libc::AF_ALG { in from_raw()
2442 impl AsRef<libc::sockaddr_alg> for AlgAddr {
2443 fn as_ref(&self) -> &libc::sockaddr_alg { in as_ref()
2535 use libc::{self, c_uchar};
2541 // FIXME: Move type into `libc`
2563 pub struct SysControlAddr(pub(in super::super) libc::sockaddr_ctl);
2567 unsafe fn from_raw(addr: *const libc::sockaddr, len: Option<libc::socklen_t>)
2571 if l != mem::size_of::<libc::sockaddr_ctl>() as libc::socklen_t {
2575 if (*addr).sa_family as i32 != libc::AF_SYSTEM {
2582 impl AsRef<libc::sockaddr_ctl> for SysControlAddr {
2583 fn as_ref(&self) -> &libc::sockaddr_ctl {
2592 let addr = libc::sockaddr_ctl {
2593 sc_len: mem::size_of::<libc::sockaddr_ctl>() as c_uchar,
2595 ss_sysaddr: libc::AF_SYS_CONTROL as u16,
2649 pub struct LinkAddr(pub(in super::super) libc::sockaddr_ll);
2708 unsafe fn from_raw(addr: *const libc::sockaddr,
2709 len: Option<libc::socklen_t>)
2713 if l != mem::size_of::<libc::sockaddr_ll>() as libc::socklen_t {
2717 if (*addr).sa_family as i32 != libc::AF_PACKET {
2724 impl AsRef<libc::sockaddr_ll> for LinkAddr {
2725 fn as_ref(&self) -> &libc::sockaddr_ll {
2752 pub struct LinkAddr(pub(in super::super) libc::sockaddr_dl);
2832 unsafe fn from_raw(addr: *const libc::sockaddr,
2833 len: Option<libc::socklen_t>)
2837 if l != mem::size_of::<libc::sockaddr_dl>() as libc::socklen_t {
2841 if (*addr).sa_family as i32 != libc::AF_LINK {
2848 impl AsRef<libc::sockaddr_dl> for LinkAddr {
2849 fn as_ref(&self) -> &libc::sockaddr_dl {
2862 use libc::{sa_family_t, sockaddr_vm};
2878 addr: *const libc::sockaddr, in from_raw()
2879 len: Option<libc::socklen_t>, in from_raw()
2885 if l != mem::size_of::<libc::sockaddr_vm>() as libc::socklen_t { in from_raw()
2889 if (*addr).sa_family as i32 != libc::AF_VSOCK { in from_raw()
2896 impl AsRef<libc::sockaddr_vm> for VsockAddr {
2897 fn as_ref(&self) -> &libc::sockaddr_vm { in as_ref()
3008 let la = LinkAddr(libc::sockaddr_dl { in test_datalink_display()
3037 let sa = bytes.0.as_ptr() as *const libc::sockaddr; in linux_loopback() constant
3053 let sa = bytes.as_ptr() as *const libc::sockaddr; in macos_loopback() constant
3074 let sa = ptr as *const libc::sockaddr; in macos_tap() constant
3093 let sa = ptr as *const libc::sockaddr; in illumos_tap() constant
3121 let l = mem::size_of::<libc::sockaddr_dl>(); in size()
3127 let l = mem::size_of::<libc::sockaddr_ll>(); in size()
3146 mem::size_of::<libc::sockaddr_in>(), in size()
3166 mem::size_of::<libc::sockaddr_in6>(), in size()
3190 let ptr = ua.as_ptr() as *const libc::sockaddr; in from_sockaddr_un_named() constant
3202 let ptr = ua.as_ptr() as *const libc::sockaddr; in from_sockaddr_un_abstract_named() constant
3213 let ptr = ua.as_ptr() as *const libc::sockaddr; in from_sockaddr_un_abstract_unnamed() constant
3242 mem::size_of::<libc::sockaddr_un>(), in size()