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