| 1 |
use crate::prelude::*; |
| 2 |
|
| 3 |
pub type sa_family_t = c_ushort; |
| 4 |
pub type in_port_t = c_ushort; |
| 5 |
pub type in_addr_t = c_uint; |
| 6 |
|
| 7 |
pub type socklen_t = c_uint; |
| 8 |
|
| 9 |
s! { |
| 10 |
#[repr(align(16))] |
| 11 |
pub struct sockaddr { |
| 12 |
pub sa_family: sa_family_t, |
| 13 |
pub sa_data: [c_char; 0], |
| 14 |
} |
| 15 |
|
| 16 |
pub struct in_addr { |
| 17 |
pub s_addr: in_addr_t, |
| 18 |
} |
| 19 |
|
| 20 |
#[repr(align(16))] |
| 21 |
pub struct sockaddr_in { |
| 22 |
pub sin_family: sa_family_t, |
| 23 |
pub sin_port: in_port_t, |
| 24 |
pub sin_addr: in_addr, |
| 25 |
} |
| 26 |
|
| 27 |
#[repr(align(4))] |
| 28 |
pub struct in6_addr { |
| 29 |
pub s6_addr: [c_uchar; 16], |
| 30 |
} |
| 31 |
|
| 32 |
#[repr(align(16))] |
| 33 |
pub struct sockaddr_in6 { |
| 34 |
pub sin6_family: sa_family_t, |
| 35 |
pub sin6_port: in_port_t, |
| 36 |
pub sin6_flowinfo: c_uint, |
| 37 |
pub sin6_addr: in6_addr, |
| 38 |
pub sin6_scope_id: c_uint, |
| 39 |
} |
| 40 |
|
| 41 |
#[repr(align(16))] |
| 42 |
pub struct sockaddr_storage { |
| 43 |
pub ss_family: sa_family_t, |
| 44 |
pub __ss_data: [c_char; 32], |
| 45 |
} |
| 46 |
|
| 47 |
pub struct addrinfo { |
| 48 |
pub ai_flags: c_int, |
| 49 |
pub ai_family: c_int, |
| 50 |
pub ai_socktype: c_int, |
| 51 |
pub ai_protocol: c_int, |
| 52 |
pub ai_addrlen: socklen_t, |
| 53 |
pub ai_addr: *mut sockaddr, |
| 54 |
pub ai_canonname: *mut c_char, |
| 55 |
pub ai_next: *mut addrinfo, |
| 56 |
} |
| 57 |
|
| 58 |
pub struct ip_mreq { |
| 59 |
pub imr_multiaddr: in_addr, |
| 60 |
pub imr_interface: in_addr, |
| 61 |
} |
| 62 |
|
| 63 |
pub struct ipv6_mreq { |
| 64 |
pub ipv6mr_multiaddr: in6_addr, |
| 65 |
pub ipv6mr_interface: c_uint, |
| 66 |
} |
| 67 |
|
| 68 |
pub struct linger { |
| 69 |
pub l_onoff: c_int, |
| 70 |
pub l_linger: c_int, |
| 71 |
} |
| 72 |
} |
| 73 |
|
| 74 |
pub const SHUT_RD: c_int = 1 << 0; |
| 75 |
pub const SHUT_WR: c_int = 1 << 1; |
| 76 |
pub const SHUT_RDWR: c_int = SHUT_RD | SHUT_WR; |
| 77 |
|
| 78 |
pub const MSG_NOSIGNAL: c_int = 0x4000; |
| 79 |
pub const MSG_PEEK: c_int = 0x0002; |
| 80 |
|
| 81 |
pub const SO_REUSEADDR: c_int = 2; |
| 82 |
pub const SO_TYPE: c_int = 3; |
| 83 |
pub const SO_ERROR: c_int = 4; |
| 84 |
pub const SO_BROADCAST: c_int = 6; |
| 85 |
pub const SO_SNDBUF: c_int = 7; |
| 86 |
pub const SO_RCVBUF: c_int = 8; |
| 87 |
pub const SO_KEEPALIVE: c_int = 9; |
| 88 |
pub const SO_LINGER: c_int = 13; |
| 89 |
pub const SO_ACCEPTCONN: c_int = 30; |
| 90 |
pub const SO_PROTOCOL: c_int = 38; |
| 91 |
pub const SO_DOMAIN: c_int = 39; |
| 92 |
pub const SO_RCVTIMEO: c_int = 66; |
| 93 |
pub const SO_SNDTIMEO: c_int = 67; |
| 94 |
|
| 95 |
pub const SOCK_DGRAM: c_int = 5; |
| 96 |
pub const SOCK_STREAM: c_int = 6; |
| 97 |
pub const SOCK_NONBLOCK: c_int = 0x00004000; |
| 98 |
|
| 99 |
pub const SOL_SOCKET: c_int = 0x7fffffff; |
| 100 |
|
| 101 |
pub const AF_UNSPEC: c_int = 0; |
| 102 |
pub const AF_INET: c_int = 1; |
| 103 |
pub const AF_INET6: c_int = 2; |
| 104 |
|
| 105 |
pub const IPPROTO_IP: c_int = 0; |
| 106 |
pub const IPPROTO_TCP: c_int = 6; |
| 107 |
pub const IPPROTO_UDP: c_int = 17; |
| 108 |
pub const IPPROTO_IPV6: c_int = 41; |
| 109 |
|
| 110 |
pub const IP_TTL: c_int = 2; |
| 111 |
pub const IP_MULTICAST_TTL: c_int = 33; |
| 112 |
pub const IP_MULTICAST_LOOP: c_int = 34; |
| 113 |
pub const IP_ADD_MEMBERSHIP: c_int = 35; |
| 114 |
pub const IP_DROP_MEMBERSHIP: c_int = 36; |
| 115 |
|
| 116 |
pub const IPV6_UNICAST_HOPS: c_int = 16; |
| 117 |
pub const IPV6_MULTICAST_LOOP: c_int = 19; |
| 118 |
pub const IPV6_JOIN_GROUP: c_int = 20; |
| 119 |
pub const IPV6_LEAVE_GROUP: c_int = 21; |
| 120 |
pub const IPV6_V6ONLY: c_int = 26; |
| 121 |
|
| 122 |
pub const IPV6_ADD_MEMBERSHIP: c_int = IPV6_JOIN_GROUP; |
| 123 |
pub const IPV6_DROP_MEMBERSHIP: c_int = IPV6_LEAVE_GROUP; |
| 124 |
|
| 125 |
pub const TCP_NODELAY: c_int = 1; |
| 126 |
pub const TCP_KEEPIDLE: c_int = 4; |
| 127 |
pub const TCP_KEEPINTVL: c_int = 5; |
| 128 |
pub const TCP_KEEPCNT: c_int = 6; |
| 129 |
|
| 130 |
pub const EAI_SYSTEM: c_int = -11; |
| 131 |
|
| 132 |
extern "C" { |
| 133 |
pub fn socket(domain: c_int, type_: c_int, protocol: c_int) -> c_int; |
| 134 |
pub fn connect(fd: c_int, name: *const sockaddr, addrlen: socklen_t) -> c_int; |
| 135 |
pub fn bind(socket: c_int, addr: *const sockaddr, addrlen: socklen_t) -> c_int; |
| 136 |
pub fn listen(socket: c_int, backlog: c_int) -> c_int; |
| 137 |
pub fn accept(socket: c_int, addr: *mut sockaddr, addrlen: *mut socklen_t) -> c_int; |
| 138 |
pub fn accept4( |
| 139 |
socket: c_int, |
| 140 |
addr: *mut sockaddr, |
| 141 |
addrlen: *mut socklen_t, |
| 142 |
flags: c_int, |
| 143 |
) -> c_int; |
| 144 |
|
| 145 |
pub fn getsockname(socket: c_int, addr: *mut sockaddr, addrlen: *mut socklen_t) -> c_int; |
| 146 |
pub fn getpeername(socket: c_int, addr: *mut sockaddr, addrlen: *mut socklen_t) -> c_int; |
| 147 |
|
| 148 |
pub fn sendto( |
| 149 |
socket: c_int, |
| 150 |
buffer: *const c_void, |
| 151 |
length: size_t, |
| 152 |
flags: c_int, |
| 153 |
addr: *const sockaddr, |
| 154 |
addrlen: socklen_t, |
| 155 |
) -> ssize_t; |
| 156 |
pub fn recvfrom( |
| 157 |
socket: c_int, |
| 158 |
buffer: *mut c_void, |
| 159 |
length: size_t, |
| 160 |
flags: c_int, |
| 161 |
addr: *mut sockaddr, |
| 162 |
addrlen: *mut socklen_t, |
| 163 |
) -> ssize_t; |
| 164 |
|
| 165 |
pub fn getsockopt( |
| 166 |
sockfd: c_int, |
| 167 |
level: c_int, |
| 168 |
optname: c_int, |
| 169 |
optval: *mut c_void, |
| 170 |
optlen: *mut socklen_t, |
| 171 |
) -> c_int; |
| 172 |
pub fn setsockopt( |
| 173 |
sockfd: c_int, |
| 174 |
level: c_int, |
| 175 |
optname: c_int, |
| 176 |
optval: *const c_void, |
| 177 |
optlen: socklen_t, |
| 178 |
) -> c_int; |
| 179 |
|
| 180 |
pub fn getaddrinfo( |
| 181 |
host: *const c_char, |
| 182 |
serv: *const c_char, |
| 183 |
hint: *const addrinfo, |
| 184 |
res: *mut *mut addrinfo, |
| 185 |
) -> c_int; |
| 186 |
pub fn freeaddrinfo(p: *mut addrinfo); |
| 187 |
pub fn gai_strerror(ecode: c_int) -> *const c_char; |
| 188 |
} |