redrust/
anet.rs

1
2extern crate c2rust_bitfields;
3extern crate libc;
4extern crate core;
5extern "C" {
6    pub type sockaddr_x25;
7    pub type sockaddr_ns;
8    pub type sockaddr_iso;
9    pub type sockaddr_ipx;
10    pub type sockaddr_inarp;
11    pub type sockaddr_eon;
12    pub type sockaddr_dl;
13    pub type sockaddr_ax25;
14    pub type sockaddr_at;
15    fn socket(
16        __domain: libc::c_int,
17        __type: libc::c_int,
18        __protocol: libc::c_int,
19    ) -> libc::c_int;
20    fn bind(
21        __fd: libc::c_int,
22        __addr: __CONST_SOCKADDR_ARG,
23        __len: socklen_t,
24    ) -> libc::c_int;
25    fn getsockname(
26        __fd: libc::c_int,
27        __addr: __SOCKADDR_ARG,
28        __len: *mut socklen_t,
29    ) -> libc::c_int;
30    fn connect(
31        __fd: libc::c_int,
32        __addr: __CONST_SOCKADDR_ARG,
33        __len: socklen_t,
34    ) -> libc::c_int;
35    fn getpeername(
36        __fd: libc::c_int,
37        __addr: __SOCKADDR_ARG,
38        __len: *mut socklen_t,
39    ) -> libc::c_int;
40    fn setsockopt(
41        __fd: libc::c_int,
42        __level: libc::c_int,
43        __optname: libc::c_int,
44        __optval: *const libc::c_void,
45        __optlen: socklen_t,
46    ) -> libc::c_int;
47    fn listen(__fd: libc::c_int, __n: libc::c_int) -> libc::c_int;
48    fn accept4(
49        __fd: libc::c_int,
50        __addr: __SOCKADDR_ARG,
51        __addr_len: *mut socklen_t,
52        __flags: libc::c_int,
53    ) -> libc::c_int;
54    fn chmod(__file: *const libc::c_char, __mode: __mode_t) -> libc::c_int;
55    fn memset(
56        _: *mut libc::c_void,
57        _: libc::c_int,
58        _: libc::c_ulong,
59    ) -> *mut libc::c_void;
60    fn strncpy(
61        _: *mut libc::c_char,
62        _: *const libc::c_char,
63        _: libc::c_ulong,
64    ) -> *mut libc::c_char;
65    fn strcmp(_: *const libc::c_char, _: *const libc::c_char) -> libc::c_int;
66    fn strchr(_: *const libc::c_char, _: libc::c_int) -> *mut libc::c_char;
67    fn strlen(_: *const libc::c_char) -> libc::c_ulong;
68    fn strerror(_: libc::c_int) -> *mut libc::c_char;
69    fn inet_ntop(
70        __af: libc::c_int,
71        __cp: *const libc::c_void,
72        __buf: *mut libc::c_char,
73        __len: socklen_t,
74    ) -> *const libc::c_char;
75    fn close(__fd: libc::c_int) -> libc::c_int;
76    fn pipe(__pipedes: *mut libc::c_int) -> libc::c_int;
77    fn pipe2(__pipedes: *mut libc::c_int, __flags: libc::c_int) -> libc::c_int;
78    fn fcntl(__fd: libc::c_int, __cmd: libc::c_int, _: ...) -> libc::c_int;
79    fn getaddrinfo(
80        __name: *const libc::c_char,
81        __service: *const libc::c_char,
82        __req: *const addrinfo,
83        __pai: *mut *mut addrinfo,
84    ) -> libc::c_int;
85    fn freeaddrinfo(__ai: *mut addrinfo);
86    fn gai_strerror(__ecode: libc::c_int) -> *const libc::c_char;
87    fn __errno_location() -> *mut libc::c_int;
88    fn snprintf(
89        _: *mut libc::c_char,
90        _: libc::c_ulong,
91        _: *const libc::c_char,
92        _: ...
93    ) -> libc::c_int;
94    fn vsnprintf(
95        _: *mut libc::c_char,
96        _: libc::c_ulong,
97        _: *const libc::c_char,
98        _: core::ffi::VaList,
99    ) -> libc::c_int;
100}
101pub type __builtin_va_list = __va_list;
102#[derive(Copy, Clone)]
103#[repr(C)]
104pub struct __va_list {
105    pub __stack: *mut libc::c_void,
106    pub __gr_top: *mut libc::c_void,
107    pub __vr_top: *mut libc::c_void,
108    pub __gr_offs: libc::c_int,
109    pub __vr_offs: libc::c_int,
110}
111pub type __uint8_t = libc::c_uchar;
112pub type __uint16_t = libc::c_ushort;
113pub type __uint32_t = libc::c_uint;
114pub type __mode_t = libc::c_uint;
115pub type __time_t = libc::c_long;
116pub type __suseconds_t = libc::c_long;
117pub type __socklen_t = libc::c_uint;
118pub type mode_t = __mode_t;
119pub type size_t = libc::c_ulong;
120#[derive(Copy, Clone)]
121#[repr(C)]
122pub struct timeval {
123    pub tv_sec: __time_t,
124    pub tv_usec: __suseconds_t,
125}
126pub type socklen_t = __socklen_t;
127pub type __socket_type = libc::c_uint;
128pub const SOCK_NONBLOCK: __socket_type = 2048;
129pub const SOCK_CLOEXEC: __socket_type = 524288;
130pub const SOCK_PACKET: __socket_type = 10;
131pub const SOCK_DCCP: __socket_type = 6;
132pub const SOCK_SEQPACKET: __socket_type = 5;
133pub const SOCK_RDM: __socket_type = 4;
134pub const SOCK_RAW: __socket_type = 3;
135pub const SOCK_DGRAM: __socket_type = 2;
136pub const SOCK_STREAM: __socket_type = 1;
137pub type sa_family_t = libc::c_ushort;
138#[derive(Copy, Clone)]
139#[repr(C)]
140pub struct sockaddr {
141    pub sa_family: sa_family_t,
142    pub sa_data: [libc::c_char; 14],
143}
144#[derive(Copy, Clone)]
145#[repr(C)]
146pub struct sockaddr_storage {
147    pub ss_family: sa_family_t,
148    pub __ss_padding: [libc::c_char; 118],
149    pub __ss_align: libc::c_ulong,
150}
151#[derive(Copy, Clone)]
152#[repr(C)]
153pub union __SOCKADDR_ARG {
154    pub __sockaddr__: *mut sockaddr,
155    pub __sockaddr_at__: *mut sockaddr_at,
156    pub __sockaddr_ax25__: *mut sockaddr_ax25,
157    pub __sockaddr_dl__: *mut sockaddr_dl,
158    pub __sockaddr_eon__: *mut sockaddr_eon,
159    pub __sockaddr_in__: *mut sockaddr_in,
160    pub __sockaddr_in6__: *mut sockaddr_in6,
161    pub __sockaddr_inarp__: *mut sockaddr_inarp,
162    pub __sockaddr_ipx__: *mut sockaddr_ipx,
163    pub __sockaddr_iso__: *mut sockaddr_iso,
164    pub __sockaddr_ns__: *mut sockaddr_ns,
165    pub __sockaddr_un__: *mut sockaddr_un,
166    pub __sockaddr_x25__: *mut sockaddr_x25,
167}
168#[derive(Copy, Clone)]
169#[repr(C)]
170pub struct sockaddr_un {
171    pub sun_family: sa_family_t,
172    pub sun_path: [libc::c_char; 108],
173}
174#[derive(Copy, Clone)]
175#[repr(C)]
176pub struct sockaddr_in6 {
177    pub sin6_family: sa_family_t,
178    pub sin6_port: in_port_t,
179    pub sin6_flowinfo: uint32_t,
180    pub sin6_addr: in6_addr,
181    pub sin6_scope_id: uint32_t,
182}
183pub type uint32_t = __uint32_t;
184#[derive(Copy, Clone)]
185#[repr(C)]
186pub struct in6_addr {
187    pub __in6_u: C2RustUnnamed,
188}
189#[derive(Copy, Clone)]
190#[repr(C)]
191pub union C2RustUnnamed {
192    pub __u6_addr8: [uint8_t; 16],
193    pub __u6_addr16: [uint16_t; 8],
194    pub __u6_addr32: [uint32_t; 4],
195}
196pub type uint16_t = __uint16_t;
197pub type uint8_t = __uint8_t;
198pub type in_port_t = uint16_t;
199#[derive(Copy, Clone)]
200#[repr(C)]
201pub struct sockaddr_in {
202    pub sin_family: sa_family_t,
203    pub sin_port: in_port_t,
204    pub sin_addr: in_addr,
205    pub sin_zero: [libc::c_uchar; 8],
206}
207#[derive(Copy, Clone)]
208#[repr(C)]
209pub struct in_addr {
210    pub s_addr: in_addr_t,
211}
212pub type in_addr_t = uint32_t;
213#[derive(Copy, Clone)]
214#[repr(C)]
215pub union __CONST_SOCKADDR_ARG {
216    pub __sockaddr__: *const sockaddr,
217    pub __sockaddr_at__: *const sockaddr_at,
218    pub __sockaddr_ax25__: *const sockaddr_ax25,
219    pub __sockaddr_dl__: *const sockaddr_dl,
220    pub __sockaddr_eon__: *const sockaddr_eon,
221    pub __sockaddr_in__: *const sockaddr_in,
222    pub __sockaddr_in6__: *const sockaddr_in6,
223    pub __sockaddr_inarp__: *const sockaddr_inarp,
224    pub __sockaddr_ipx__: *const sockaddr_ipx,
225    pub __sockaddr_iso__: *const sockaddr_iso,
226    pub __sockaddr_ns__: *const sockaddr_ns,
227    pub __sockaddr_un__: *const sockaddr_un,
228    pub __sockaddr_x25__: *const sockaddr_x25,
229}
230pub type C2RustUnnamed_0 = libc::c_uint;
231pub const IPPROTO_MAX: C2RustUnnamed_0 = 256;
232pub const IPPROTO_RAW: C2RustUnnamed_0 = 255;
233pub const IPPROTO_MPLS: C2RustUnnamed_0 = 137;
234pub const IPPROTO_UDPLITE: C2RustUnnamed_0 = 136;
235pub const IPPROTO_SCTP: C2RustUnnamed_0 = 132;
236pub const IPPROTO_COMP: C2RustUnnamed_0 = 108;
237pub const IPPROTO_PIM: C2RustUnnamed_0 = 103;
238pub const IPPROTO_ENCAP: C2RustUnnamed_0 = 98;
239pub const IPPROTO_BEETPH: C2RustUnnamed_0 = 94;
240pub const IPPROTO_MTP: C2RustUnnamed_0 = 92;
241pub const IPPROTO_AH: C2RustUnnamed_0 = 51;
242pub const IPPROTO_ESP: C2RustUnnamed_0 = 50;
243pub const IPPROTO_GRE: C2RustUnnamed_0 = 47;
244pub const IPPROTO_RSVP: C2RustUnnamed_0 = 46;
245pub const IPPROTO_IPV6: C2RustUnnamed_0 = 41;
246pub const IPPROTO_DCCP: C2RustUnnamed_0 = 33;
247pub const IPPROTO_TP: C2RustUnnamed_0 = 29;
248pub const IPPROTO_IDP: C2RustUnnamed_0 = 22;
249pub const IPPROTO_UDP: C2RustUnnamed_0 = 17;
250pub const IPPROTO_PUP: C2RustUnnamed_0 = 12;
251pub const IPPROTO_EGP: C2RustUnnamed_0 = 8;
252pub const IPPROTO_TCP: C2RustUnnamed_0 = 6;
253pub const IPPROTO_IPIP: C2RustUnnamed_0 = 4;
254pub const IPPROTO_IGMP: C2RustUnnamed_0 = 2;
255pub const IPPROTO_ICMP: C2RustUnnamed_0 = 1;
256pub const IPPROTO_IP: C2RustUnnamed_0 = 0;
257#[derive(Copy, Clone)]
258#[repr(C)]
259pub struct addrinfo {
260    pub ai_flags: libc::c_int,
261    pub ai_family: libc::c_int,
262    pub ai_socktype: libc::c_int,
263    pub ai_protocol: libc::c_int,
264    pub ai_addrlen: socklen_t,
265    pub ai_addr: *mut sockaddr,
266    pub ai_canonname: *mut libc::c_char,
267    pub ai_next: *mut addrinfo,
268}
269pub type va_list = __builtin_va_list;
270#[inline]
271unsafe extern "C" fn __bswap_16(mut __bsx: __uint16_t) -> __uint16_t {
272    return (__bsx as libc::c_int >> 8 as libc::c_int & 0xff as libc::c_int
273        | (__bsx as libc::c_int & 0xff as libc::c_int) << 8 as libc::c_int)
274        as __uint16_t;
275}
276unsafe extern "C" fn anetSetError(
277    mut err: *mut libc::c_char,
278    mut fmt: *const libc::c_char,
279    mut args: ...
280) {
281    let mut ap: core::ffi::VaListImpl;
282    if err.is_null() {
283        return;
284    }
285    ap = args.clone();
286    vsnprintf(err, 256 as libc::c_int as libc::c_ulong, fmt, ap.as_va_list());
287}
288#[no_mangle]
289pub unsafe extern "C" fn anetSetBlock(
290    mut err: *mut libc::c_char,
291    mut fd: libc::c_int,
292    mut non_block: libc::c_int,
293) -> libc::c_int {
294    let mut flags: libc::c_int = 0;
295    flags = fcntl(fd, 3 as libc::c_int);
296    if flags == -(1 as libc::c_int) {
297        anetSetError(
298            err,
299            b"fcntl(F_GETFL): %s\0" as *const u8 as *const libc::c_char,
300            strerror(*__errno_location()),
301        );
302        return -(1 as libc::c_int);
303    }
304    if (flags & 0o4000 as libc::c_int != 0) as libc::c_int
305        == (non_block != 0) as libc::c_int
306    {
307        return 0 as libc::c_int;
308    }
309    if non_block != 0 {
310        flags |= 0o4000 as libc::c_int;
311    } else {
312        flags &= !(0o4000 as libc::c_int);
313    }
314    if fcntl(fd, 4 as libc::c_int, flags) == -(1 as libc::c_int) {
315        anetSetError(
316            err,
317            b"fcntl(F_SETFL,O_NONBLOCK): %s\0" as *const u8 as *const libc::c_char,
318            strerror(*__errno_location()),
319        );
320        return -(1 as libc::c_int);
321    }
322    return 0 as libc::c_int;
323}
324#[no_mangle]
325pub unsafe extern "C" fn anetNonBlock(
326    mut err: *mut libc::c_char,
327    mut fd: libc::c_int,
328) -> libc::c_int {
329    return anetSetBlock(err, fd, 1 as libc::c_int);
330}
331#[no_mangle]
332pub unsafe extern "C" fn anetBlock(
333    mut err: *mut libc::c_char,
334    mut fd: libc::c_int,
335) -> libc::c_int {
336    return anetSetBlock(err, fd, 0 as libc::c_int);
337}
338#[no_mangle]
339pub unsafe extern "C" fn anetCloexec(mut fd: libc::c_int) -> libc::c_int {
340    let mut r: libc::c_int = 0;
341    let mut flags: libc::c_int = 0;
342    loop {
343        r = fcntl(fd, 1 as libc::c_int);
344        if !(r == -(1 as libc::c_int) && *__errno_location() == 4 as libc::c_int) {
345            break;
346        }
347    }
348    if r == -(1 as libc::c_int) || r & 1 as libc::c_int != 0 {
349        return r;
350    }
351    flags = r | 1 as libc::c_int;
352    loop {
353        r = fcntl(fd, 2 as libc::c_int, flags);
354        if !(r == -(1 as libc::c_int) && *__errno_location() == 4 as libc::c_int) {
355            break;
356        }
357    }
358    return r;
359}
360#[no_mangle]
361pub unsafe extern "C" fn anetKeepAlive(
362    mut err: *mut libc::c_char,
363    mut fd: libc::c_int,
364    mut interval: libc::c_int,
365) -> libc::c_int {
366    let mut val: libc::c_int = 1 as libc::c_int;
367    if setsockopt(
368        fd,
369        1 as libc::c_int,
370        9 as libc::c_int,
371        &mut val as *mut libc::c_int as *const libc::c_void,
372        core::mem::size_of::<libc::c_int>() as libc::c_ulong as socklen_t,
373    ) == -(1 as libc::c_int)
374    {
375        anetSetError(
376            err,
377            b"setsockopt SO_KEEPALIVE: %s\0" as *const u8 as *const libc::c_char,
378            strerror(*__errno_location()),
379        );
380        return -(1 as libc::c_int);
381    }
382    val = interval;
383    if setsockopt(
384        fd,
385        IPPROTO_TCP as libc::c_int,
386        4 as libc::c_int,
387        &mut val as *mut libc::c_int as *const libc::c_void,
388        core::mem::size_of::<libc::c_int>() as libc::c_ulong as socklen_t,
389    ) < 0 as libc::c_int
390    {
391        anetSetError(
392            err,
393            b"setsockopt TCP_KEEPIDLE: %s\n\0" as *const u8 as *const libc::c_char,
394            strerror(*__errno_location()),
395        );
396        return -(1 as libc::c_int);
397    }
398    val = interval / 3 as libc::c_int;
399    if val == 0 as libc::c_int {
400        val = 1 as libc::c_int;
401    }
402    if setsockopt(
403        fd,
404        IPPROTO_TCP as libc::c_int,
405        5 as libc::c_int,
406        &mut val as *mut libc::c_int as *const libc::c_void,
407        core::mem::size_of::<libc::c_int>() as libc::c_ulong as socklen_t,
408    ) < 0 as libc::c_int
409    {
410        anetSetError(
411            err,
412            b"setsockopt TCP_KEEPINTVL: %s\n\0" as *const u8 as *const libc::c_char,
413            strerror(*__errno_location()),
414        );
415        return -(1 as libc::c_int);
416    }
417    val = 3 as libc::c_int;
418    if setsockopt(
419        fd,
420        IPPROTO_TCP as libc::c_int,
421        6 as libc::c_int,
422        &mut val as *mut libc::c_int as *const libc::c_void,
423        core::mem::size_of::<libc::c_int>() as libc::c_ulong as socklen_t,
424    ) < 0 as libc::c_int
425    {
426        anetSetError(
427            err,
428            b"setsockopt TCP_KEEPCNT: %s\n\0" as *const u8 as *const libc::c_char,
429            strerror(*__errno_location()),
430        );
431        return -(1 as libc::c_int);
432    }
433    return 0 as libc::c_int;
434}
435unsafe extern "C" fn anetSetTcpNoDelay(
436    mut err: *mut libc::c_char,
437    mut fd: libc::c_int,
438    mut val: libc::c_int,
439) -> libc::c_int {
440    if setsockopt(
441        fd,
442        IPPROTO_TCP as libc::c_int,
443        1 as libc::c_int,
444        &mut val as *mut libc::c_int as *const libc::c_void,
445        core::mem::size_of::<libc::c_int>() as libc::c_ulong as socklen_t,
446    ) == -(1 as libc::c_int)
447    {
448        anetSetError(
449            err,
450            b"setsockopt TCP_NODELAY: %s\0" as *const u8 as *const libc::c_char,
451            strerror(*__errno_location()),
452        );
453        return -(1 as libc::c_int);
454    }
455    return 0 as libc::c_int;
456}
457#[no_mangle]
458pub unsafe extern "C" fn anetEnableTcpNoDelay(
459    mut err: *mut libc::c_char,
460    mut fd: libc::c_int,
461) -> libc::c_int {
462    return anetSetTcpNoDelay(err, fd, 1 as libc::c_int);
463}
464#[no_mangle]
465pub unsafe extern "C" fn anetDisableTcpNoDelay(
466    mut err: *mut libc::c_char,
467    mut fd: libc::c_int,
468) -> libc::c_int {
469    return anetSetTcpNoDelay(err, fd, 0 as libc::c_int);
470}
471#[no_mangle]
472pub unsafe extern "C" fn anetSendTimeout(
473    mut err: *mut libc::c_char,
474    mut fd: libc::c_int,
475    mut ms: libc::c_longlong,
476) -> libc::c_int {
477    let mut tv: timeval = timeval { tv_sec: 0, tv_usec: 0 };
478    tv.tv_sec = (ms / 1000 as libc::c_int as libc::c_longlong) as __time_t;
479    tv
480        .tv_usec = (ms % 1000 as libc::c_int as libc::c_longlong
481        * 1000 as libc::c_int as libc::c_longlong) as __suseconds_t;
482    if setsockopt(
483        fd,
484        1 as libc::c_int,
485        21 as libc::c_int,
486        &mut tv as *mut timeval as *const libc::c_void,
487        core::mem::size_of::<timeval>() as libc::c_ulong as socklen_t,
488    ) == -(1 as libc::c_int)
489    {
490        anetSetError(
491            err,
492            b"setsockopt SO_SNDTIMEO: %s\0" as *const u8 as *const libc::c_char,
493            strerror(*__errno_location()),
494        );
495        return -(1 as libc::c_int);
496    }
497    return 0 as libc::c_int;
498}
499#[no_mangle]
500pub unsafe extern "C" fn anetRecvTimeout(
501    mut err: *mut libc::c_char,
502    mut fd: libc::c_int,
503    mut ms: libc::c_longlong,
504) -> libc::c_int {
505    let mut tv: timeval = timeval { tv_sec: 0, tv_usec: 0 };
506    tv.tv_sec = (ms / 1000 as libc::c_int as libc::c_longlong) as __time_t;
507    tv
508        .tv_usec = (ms % 1000 as libc::c_int as libc::c_longlong
509        * 1000 as libc::c_int as libc::c_longlong) as __suseconds_t;
510    if setsockopt(
511        fd,
512        1 as libc::c_int,
513        20 as libc::c_int,
514        &mut tv as *mut timeval as *const libc::c_void,
515        core::mem::size_of::<timeval>() as libc::c_ulong as socklen_t,
516    ) == -(1 as libc::c_int)
517    {
518        anetSetError(
519            err,
520            b"setsockopt SO_RCVTIMEO: %s\0" as *const u8 as *const libc::c_char,
521            strerror(*__errno_location()),
522        );
523        return -(1 as libc::c_int);
524    }
525    return 0 as libc::c_int;
526}
527#[no_mangle]
528pub unsafe extern "C" fn anetResolve(
529    mut err: *mut libc::c_char,
530    mut host: *mut libc::c_char,
531    mut ipbuf: *mut libc::c_char,
532    mut ipbuf_len: size_t,
533    mut flags: libc::c_int,
534) -> libc::c_int {
535    let mut hints: addrinfo = addrinfo {
536        ai_flags: 0,
537        ai_family: 0,
538        ai_socktype: 0,
539        ai_protocol: 0,
540        ai_addrlen: 0,
541        ai_addr: 0 as *mut sockaddr,
542        ai_canonname: 0 as *mut libc::c_char,
543        ai_next: 0 as *mut addrinfo,
544    };
545    let mut info: *mut addrinfo = 0 as *mut addrinfo;
546    let mut rv: libc::c_int = 0;
547    memset(
548        &mut hints as *mut addrinfo as *mut libc::c_void,
549        0 as libc::c_int,
550        core::mem::size_of::<addrinfo>() as libc::c_ulong,
551    );
552    if flags & (1 as libc::c_int) << 0 as libc::c_int != 0 {
553        hints.ai_flags = 0x4 as libc::c_int;
554    }
555    hints.ai_family = 0 as libc::c_int;
556    hints.ai_socktype = SOCK_STREAM as libc::c_int;
557    rv = getaddrinfo(host, 0 as *const libc::c_char, &mut hints, &mut info);
558    if rv != 0 as libc::c_int {
559        anetSetError(err, b"%s\0" as *const u8 as *const libc::c_char, gai_strerror(rv));
560        return -(1 as libc::c_int);
561    }
562    if (*info).ai_family == 2 as libc::c_int {
563        let mut sa: *mut sockaddr_in = (*info).ai_addr as *mut sockaddr_in;
564        inet_ntop(
565            2 as libc::c_int,
566            &mut (*sa).sin_addr as *mut in_addr as *const libc::c_void,
567            ipbuf,
568            ipbuf_len as socklen_t,
569        );
570    } else {
571        let mut sa_0: *mut sockaddr_in6 = (*info).ai_addr as *mut sockaddr_in6;
572        inet_ntop(
573            10 as libc::c_int,
574            &mut (*sa_0).sin6_addr as *mut in6_addr as *const libc::c_void,
575            ipbuf,
576            ipbuf_len as socklen_t,
577        );
578    }
579    freeaddrinfo(info);
580    return 0 as libc::c_int;
581}
582unsafe extern "C" fn anetSetReuseAddr(
583    mut err: *mut libc::c_char,
584    mut fd: libc::c_int,
585) -> libc::c_int {
586    let mut yes: libc::c_int = 1 as libc::c_int;
587    if setsockopt(
588        fd,
589        1 as libc::c_int,
590        2 as libc::c_int,
591        &mut yes as *mut libc::c_int as *const libc::c_void,
592        core::mem::size_of::<libc::c_int>() as libc::c_ulong as socklen_t,
593    ) == -(1 as libc::c_int)
594    {
595        anetSetError(
596            err,
597            b"setsockopt SO_REUSEADDR: %s\0" as *const u8 as *const libc::c_char,
598            strerror(*__errno_location()),
599        );
600        return -(1 as libc::c_int);
601    }
602    return 0 as libc::c_int;
603}
604unsafe extern "C" fn anetCreateSocket(
605    mut err: *mut libc::c_char,
606    mut domain: libc::c_int,
607) -> libc::c_int {
608    let mut s: libc::c_int = 0;
609    s = socket(domain, SOCK_STREAM as libc::c_int, 0 as libc::c_int);
610    if s == -(1 as libc::c_int) {
611        anetSetError(
612            err,
613            b"creating socket: %s\0" as *const u8 as *const libc::c_char,
614            strerror(*__errno_location()),
615        );
616        return -(1 as libc::c_int);
617    }
618    if anetSetReuseAddr(err, s) == -(1 as libc::c_int) {
619        close(s);
620        return -(1 as libc::c_int);
621    }
622    return s;
623}
624unsafe extern "C" fn anetTcpGenericConnect(
625    mut err: *mut libc::c_char,
626    mut addr: *const libc::c_char,
627    mut port: libc::c_int,
628    mut source_addr: *const libc::c_char,
629    mut flags: libc::c_int,
630) -> libc::c_int {
631    let mut current_block: u64;
632    let mut s: libc::c_int = -(1 as libc::c_int);
633    let mut rv: libc::c_int = 0;
634    let mut portstr: [libc::c_char; 6] = [0; 6];
635    let mut hints: addrinfo = addrinfo {
636        ai_flags: 0,
637        ai_family: 0,
638        ai_socktype: 0,
639        ai_protocol: 0,
640        ai_addrlen: 0,
641        ai_addr: 0 as *mut sockaddr,
642        ai_canonname: 0 as *mut libc::c_char,
643        ai_next: 0 as *mut addrinfo,
644    };
645    let mut servinfo: *mut addrinfo = 0 as *mut addrinfo;
646    let mut bservinfo: *mut addrinfo = 0 as *mut addrinfo;
647    let mut p: *mut addrinfo = 0 as *mut addrinfo;
648    let mut b: *mut addrinfo = 0 as *mut addrinfo;
649    snprintf(
650        portstr.as_mut_ptr(),
651        core::mem::size_of::<[libc::c_char; 6]>() as libc::c_ulong,
652        b"%d\0" as *const u8 as *const libc::c_char,
653        port,
654    );
655    memset(
656        &mut hints as *mut addrinfo as *mut libc::c_void,
657        0 as libc::c_int,
658        core::mem::size_of::<addrinfo>() as libc::c_ulong,
659    );
660    hints.ai_family = 0 as libc::c_int;
661    hints.ai_socktype = SOCK_STREAM as libc::c_int;
662    rv = getaddrinfo(addr, portstr.as_mut_ptr(), &mut hints, &mut servinfo);
663    if rv != 0 as libc::c_int {
664        anetSetError(err, b"%s\0" as *const u8 as *const libc::c_char, gai_strerror(rv));
665        return -(1 as libc::c_int);
666    }
667    p = servinfo;
668    loop {
669        if p.is_null() {
670            current_block = 4068382217303356765;
671            break;
672        }
673        s = socket((*p).ai_family, (*p).ai_socktype, (*p).ai_protocol);
674        if !(s == -(1 as libc::c_int)) {
675            if anetSetReuseAddr(err, s) == -(1 as libc::c_int) {
676                current_block = 18230845023186363638;
677                break;
678            }
679            if flags & 1 as libc::c_int != 0 && anetNonBlock(err, s) != 0 as libc::c_int
680            {
681                current_block = 18230845023186363638;
682                break;
683            }
684            if !source_addr.is_null() {
685                let mut bound: libc::c_int = 0 as libc::c_int;
686                rv = getaddrinfo(
687                    source_addr,
688                    0 as *const libc::c_char,
689                    &mut hints,
690                    &mut bservinfo,
691                );
692                if rv != 0 as libc::c_int {
693                    anetSetError(
694                        err,
695                        b"%s\0" as *const u8 as *const libc::c_char,
696                        gai_strerror(rv),
697                    );
698                    current_block = 18230845023186363638;
699                    break;
700                } else {
701                    b = bservinfo;
702                    while !b.is_null() {
703                        if bind(
704                            s,
705                            __CONST_SOCKADDR_ARG {
706                                __sockaddr__: (*b).ai_addr,
707                            },
708                            (*b).ai_addrlen,
709                        ) != -(1 as libc::c_int)
710                        {
711                            bound = 1 as libc::c_int;
712                            break;
713                        } else {
714                            b = (*b).ai_next;
715                        }
716                    }
717                    freeaddrinfo(bservinfo);
718                    if bound == 0 {
719                        anetSetError(
720                            err,
721                            b"bind: %s\0" as *const u8 as *const libc::c_char,
722                            strerror(*__errno_location()),
723                        );
724                        current_block = 18230845023186363638;
725                        break;
726                    }
727                }
728            }
729            if !(connect(
730                s,
731                __CONST_SOCKADDR_ARG {
732                    __sockaddr__: (*p).ai_addr,
733                },
734                (*p).ai_addrlen,
735            ) == -(1 as libc::c_int))
736            {
737                current_block = 12152712920694627287;
738                break;
739            }
740            if *__errno_location() == 115 as libc::c_int && flags & 1 as libc::c_int != 0
741            {
742                current_block = 12152712920694627287;
743                break;
744            }
745            close(s);
746            s = -(1 as libc::c_int);
747        }
748        p = (*p).ai_next;
749    }
750    match current_block {
751        4068382217303356765 => {
752            if p.is_null() {
753                anetSetError(
754                    err,
755                    b"creating socket: %s\0" as *const u8 as *const libc::c_char,
756                    strerror(*__errno_location()),
757                );
758            }
759            current_block = 18230845023186363638;
760        }
761        _ => {}
762    }
763    match current_block {
764        18230845023186363638 => {
765            if s != -(1 as libc::c_int) {
766                close(s);
767                s = -(1 as libc::c_int);
768            }
769        }
770        _ => {}
771    }
772    freeaddrinfo(servinfo);
773    if s == -(1 as libc::c_int) && !source_addr.is_null()
774        && flags & 2 as libc::c_int != 0
775    {
776        return anetTcpGenericConnect(err, addr, port, 0 as *const libc::c_char, flags)
777    } else {
778        return s
779    };
780}
781#[no_mangle]
782pub unsafe extern "C" fn anetTcpNonBlockConnect(
783    mut err: *mut libc::c_char,
784    mut addr: *const libc::c_char,
785    mut port: libc::c_int,
786) -> libc::c_int {
787    return anetTcpGenericConnect(
788        err,
789        addr,
790        port,
791        0 as *const libc::c_char,
792        1 as libc::c_int,
793    );
794}
795#[no_mangle]
796pub unsafe extern "C" fn anetTcpNonBlockBestEffortBindConnect(
797    mut err: *mut libc::c_char,
798    mut addr: *const libc::c_char,
799    mut port: libc::c_int,
800    mut source_addr: *const libc::c_char,
801) -> libc::c_int {
802    return anetTcpGenericConnect(
803        err,
804        addr,
805        port,
806        source_addr,
807        1 as libc::c_int | 2 as libc::c_int,
808    );
809}
810#[no_mangle]
811pub unsafe extern "C" fn anetUnixGenericConnect(
812    mut err: *mut libc::c_char,
813    mut path: *const libc::c_char,
814    mut flags: libc::c_int,
815) -> libc::c_int {
816    let mut s: libc::c_int = 0;
817    let mut sa: sockaddr_un = sockaddr_un {
818        sun_family: 0,
819        sun_path: [0; 108],
820    };
821    s = anetCreateSocket(err, 1 as libc::c_int);
822    if s == -(1 as libc::c_int) {
823        return -(1 as libc::c_int);
824    }
825    sa.sun_family = 1 as libc::c_int as sa_family_t;
826    strncpy(
827        (sa.sun_path).as_mut_ptr(),
828        path,
829        (core::mem::size_of::<[libc::c_char; 108]>() as libc::c_ulong)
830            .wrapping_sub(1 as libc::c_int as libc::c_ulong),
831    );
832    if flags & 1 as libc::c_int != 0 {
833        if anetNonBlock(err, s) != 0 as libc::c_int {
834            close(s);
835            return -(1 as libc::c_int);
836        }
837    }
838    if connect(
839        s,
840        __CONST_SOCKADDR_ARG {
841            __sockaddr__: &mut sa as *mut sockaddr_un as *mut sockaddr,
842        },
843        core::mem::size_of::<sockaddr_un>() as libc::c_ulong as socklen_t,
844    ) == -(1 as libc::c_int)
845    {
846        if *__errno_location() == 115 as libc::c_int && flags & 1 as libc::c_int != 0 {
847            return s;
848        }
849        anetSetError(
850            err,
851            b"connect: %s\0" as *const u8 as *const libc::c_char,
852            strerror(*__errno_location()),
853        );
854        close(s);
855        return -(1 as libc::c_int);
856    }
857    return s;
858}
859unsafe extern "C" fn anetListen(
860    mut err: *mut libc::c_char,
861    mut s: libc::c_int,
862    mut sa: *mut sockaddr,
863    mut len: socklen_t,
864    mut backlog: libc::c_int,
865) -> libc::c_int {
866    if bind(
867        s,
868        __CONST_SOCKADDR_ARG {
869            __sockaddr__: sa,
870        },
871        len,
872    ) == -(1 as libc::c_int)
873    {
874        anetSetError(
875            err,
876            b"bind: %s\0" as *const u8 as *const libc::c_char,
877            strerror(*__errno_location()),
878        );
879        close(s);
880        return -(1 as libc::c_int);
881    }
882    if listen(s, backlog) == -(1 as libc::c_int) {
883        anetSetError(
884            err,
885            b"listen: %s\0" as *const u8 as *const libc::c_char,
886            strerror(*__errno_location()),
887        );
888        close(s);
889        return -(1 as libc::c_int);
890    }
891    return 0 as libc::c_int;
892}
893unsafe extern "C" fn anetV6Only(
894    mut err: *mut libc::c_char,
895    mut s: libc::c_int,
896) -> libc::c_int {
897    let mut yes: libc::c_int = 1 as libc::c_int;
898    if setsockopt(
899        s,
900        IPPROTO_IPV6 as libc::c_int,
901        26 as libc::c_int,
902        &mut yes as *mut libc::c_int as *const libc::c_void,
903        core::mem::size_of::<libc::c_int>() as libc::c_ulong as socklen_t,
904    ) == -(1 as libc::c_int)
905    {
906        anetSetError(
907            err,
908            b"setsockopt: %s\0" as *const u8 as *const libc::c_char,
909            strerror(*__errno_location()),
910        );
911        return -(1 as libc::c_int);
912    }
913    return 0 as libc::c_int;
914}
915unsafe extern "C" fn _anetTcpServer(
916    mut err: *mut libc::c_char,
917    mut port: libc::c_int,
918    mut bindaddr: *mut libc::c_char,
919    mut af: libc::c_int,
920    mut backlog: libc::c_int,
921) -> libc::c_int {
922    let mut current_block: u64;
923    let mut s: libc::c_int = -(1 as libc::c_int);
924    let mut rv: libc::c_int = 0;
925    let mut _port: [libc::c_char; 6] = [0; 6];
926    let mut hints: addrinfo = addrinfo {
927        ai_flags: 0,
928        ai_family: 0,
929        ai_socktype: 0,
930        ai_protocol: 0,
931        ai_addrlen: 0,
932        ai_addr: 0 as *mut sockaddr,
933        ai_canonname: 0 as *mut libc::c_char,
934        ai_next: 0 as *mut addrinfo,
935    };
936    let mut servinfo: *mut addrinfo = 0 as *mut addrinfo;
937    let mut p: *mut addrinfo = 0 as *mut addrinfo;
938    snprintf(
939        _port.as_mut_ptr(),
940        6 as libc::c_int as libc::c_ulong,
941        b"%d\0" as *const u8 as *const libc::c_char,
942        port,
943    );
944    memset(
945        &mut hints as *mut addrinfo as *mut libc::c_void,
946        0 as libc::c_int,
947        core::mem::size_of::<addrinfo>() as libc::c_ulong,
948    );
949    hints.ai_family = af;
950    hints.ai_socktype = SOCK_STREAM as libc::c_int;
951    hints.ai_flags = 0x1 as libc::c_int;
952    if !bindaddr.is_null()
953        && strcmp(b"*\0" as *const u8 as *const libc::c_char, bindaddr) == 0
954    {
955        bindaddr = 0 as *mut libc::c_char;
956    }
957    if af == 10 as libc::c_int && !bindaddr.is_null()
958        && strcmp(b"::*\0" as *const u8 as *const libc::c_char, bindaddr) == 0
959    {
960        bindaddr = 0 as *mut libc::c_char;
961    }
962    rv = getaddrinfo(bindaddr, _port.as_mut_ptr(), &mut hints, &mut servinfo);
963    if rv != 0 as libc::c_int {
964        anetSetError(err, b"%s\0" as *const u8 as *const libc::c_char, gai_strerror(rv));
965        return -(1 as libc::c_int);
966    }
967    p = servinfo;
968    loop {
969        if p.is_null() {
970            current_block = 15976848397966268834;
971            break;
972        }
973        s = socket((*p).ai_family, (*p).ai_socktype, (*p).ai_protocol);
974        if s == -(1 as libc::c_int) {
975            p = (*p).ai_next;
976        } else {
977            if af == 10 as libc::c_int && anetV6Only(err, s) == -(1 as libc::c_int) {
978                current_block = 11020516886334953311;
979                break;
980            }
981            if anetSetReuseAddr(err, s) == -(1 as libc::c_int) {
982                current_block = 11020516886334953311;
983                break;
984            }
985            if anetListen(err, s, (*p).ai_addr, (*p).ai_addrlen, backlog)
986                == -(1 as libc::c_int)
987            {
988                s = -(1 as libc::c_int);
989            }
990            current_block = 15244307943444686946;
991            break;
992        }
993    }
994    match current_block {
995        15976848397966268834 => {
996            if p.is_null() {
997                anetSetError(
998                    err,
999                    b"unable to bind socket, errno: %d\0" as *const u8
1000                        as *const libc::c_char,
1001                    *__errno_location(),
1002                );
1003                current_block = 11020516886334953311;
1004            } else {
1005                current_block = 11020516886334953311;
1006            }
1007        }
1008        _ => {}
1009    }
1010    match current_block {
1011        11020516886334953311 => {
1012            if s != -(1 as libc::c_int) {
1013                close(s);
1014            }
1015            s = -(1 as libc::c_int);
1016        }
1017        _ => {}
1018    }
1019    freeaddrinfo(servinfo);
1020    return s;
1021}
1022#[no_mangle]
1023pub unsafe extern "C" fn anetTcpServer(
1024    mut err: *mut libc::c_char,
1025    mut port: libc::c_int,
1026    mut bindaddr: *mut libc::c_char,
1027    mut backlog: libc::c_int,
1028) -> libc::c_int {
1029    return _anetTcpServer(err, port, bindaddr, 2 as libc::c_int, backlog);
1030}
1031#[no_mangle]
1032pub unsafe extern "C" fn anetTcp6Server(
1033    mut err: *mut libc::c_char,
1034    mut port: libc::c_int,
1035    mut bindaddr: *mut libc::c_char,
1036    mut backlog: libc::c_int,
1037) -> libc::c_int {
1038    return _anetTcpServer(err, port, bindaddr, 10 as libc::c_int, backlog);
1039}
1040#[no_mangle]
1041pub unsafe extern "C" fn anetUnixServer(
1042    mut err: *mut libc::c_char,
1043    mut path: *mut libc::c_char,
1044    mut perm: mode_t,
1045    mut backlog: libc::c_int,
1046) -> libc::c_int {
1047    let mut s: libc::c_int = 0;
1048    let mut sa: sockaddr_un = sockaddr_un {
1049        sun_family: 0,
1050        sun_path: [0; 108],
1051    };
1052    if strlen(path)
1053        > (core::mem::size_of::<[libc::c_char; 108]>() as libc::c_ulong)
1054            .wrapping_sub(1 as libc::c_int as libc::c_ulong)
1055    {
1056        anetSetError(
1057            err,
1058            b"unix socket path too long (%zu), must be under %zu\0" as *const u8
1059                as *const libc::c_char,
1060            strlen(path),
1061            core::mem::size_of::<[libc::c_char; 108]>() as libc::c_ulong,
1062        );
1063        return -(1 as libc::c_int);
1064    }
1065    s = anetCreateSocket(err, 1 as libc::c_int);
1066    if s == -(1 as libc::c_int) {
1067        return -(1 as libc::c_int);
1068    }
1069    memset(
1070        &mut sa as *mut sockaddr_un as *mut libc::c_void,
1071        0 as libc::c_int,
1072        core::mem::size_of::<sockaddr_un>() as libc::c_ulong,
1073    );
1074    sa.sun_family = 1 as libc::c_int as sa_family_t;
1075    strncpy(
1076        (sa.sun_path).as_mut_ptr(),
1077        path,
1078        (core::mem::size_of::<[libc::c_char; 108]>() as libc::c_ulong)
1079            .wrapping_sub(1 as libc::c_int as libc::c_ulong),
1080    );
1081    if anetListen(
1082        err,
1083        s,
1084        &mut sa as *mut sockaddr_un as *mut sockaddr,
1085        core::mem::size_of::<sockaddr_un>() as libc::c_ulong as socklen_t,
1086        backlog,
1087    ) == -(1 as libc::c_int)
1088    {
1089        return -(1 as libc::c_int);
1090    }
1091    if perm != 0 {
1092        chmod((sa.sun_path).as_mut_ptr(), perm);
1093    }
1094    return s;
1095}
1096unsafe extern "C" fn anetGenericAccept(
1097    mut err: *mut libc::c_char,
1098    mut s: libc::c_int,
1099    mut sa: *mut sockaddr,
1100    mut len: *mut socklen_t,
1101) -> libc::c_int {
1102    let mut fd: libc::c_int = 0;
1103    loop {
1104        fd = accept4(
1105            s,
1106            __SOCKADDR_ARG { __sockaddr__: sa },
1107            len,
1108            SOCK_NONBLOCK as libc::c_int | SOCK_CLOEXEC as libc::c_int,
1109        );
1110        if !(fd == -(1 as libc::c_int) && *__errno_location() == 4 as libc::c_int) {
1111            break;
1112        }
1113    }
1114    if fd == -(1 as libc::c_int) {
1115        anetSetError(
1116            err,
1117            b"accept: %s\0" as *const u8 as *const libc::c_char,
1118            strerror(*__errno_location()),
1119        );
1120        return -(1 as libc::c_int);
1121    }
1122    return fd;
1123}
1124#[no_mangle]
1125pub unsafe extern "C" fn anetTcpAccept(
1126    mut err: *mut libc::c_char,
1127    mut serversock: libc::c_int,
1128    mut ip: *mut libc::c_char,
1129    mut ip_len: size_t,
1130    mut port: *mut libc::c_int,
1131) -> libc::c_int {
1132    let mut fd: libc::c_int = 0;
1133    let mut sa: sockaddr_storage = sockaddr_storage {
1134        ss_family: 0,
1135        __ss_padding: [0; 118],
1136        __ss_align: 0,
1137    };
1138    let mut salen: socklen_t = core::mem::size_of::<sockaddr_storage>()
1139        as libc::c_ulong as socklen_t;
1140    fd = anetGenericAccept(
1141        err,
1142        serversock,
1143        &mut sa as *mut sockaddr_storage as *mut sockaddr,
1144        &mut salen,
1145    );
1146    if fd == -(1 as libc::c_int) {
1147        return -(1 as libc::c_int);
1148    }
1149    if sa.ss_family as libc::c_int == 2 as libc::c_int {
1150        let mut s: *mut sockaddr_in = &mut sa as *mut sockaddr_storage
1151            as *mut sockaddr_in;
1152        if !ip.is_null() {
1153            inet_ntop(
1154                2 as libc::c_int,
1155                &mut (*s).sin_addr as *mut in_addr as *mut libc::c_void,
1156                ip,
1157                ip_len as socklen_t,
1158            );
1159        }
1160        if !port.is_null() {
1161            *port = __bswap_16((*s).sin_port) as libc::c_int;
1162        }
1163    } else {
1164        let mut s_0: *mut sockaddr_in6 = &mut sa as *mut sockaddr_storage
1165            as *mut sockaddr_in6;
1166        if !ip.is_null() {
1167            inet_ntop(
1168                10 as libc::c_int,
1169                &mut (*s_0).sin6_addr as *mut in6_addr as *mut libc::c_void,
1170                ip,
1171                ip_len as socklen_t,
1172            );
1173        }
1174        if !port.is_null() {
1175            *port = __bswap_16((*s_0).sin6_port) as libc::c_int;
1176        }
1177    }
1178    return fd;
1179}
1180#[no_mangle]
1181pub unsafe extern "C" fn anetUnixAccept(
1182    mut err: *mut libc::c_char,
1183    mut s: libc::c_int,
1184) -> libc::c_int {
1185    let mut fd: libc::c_int = 0;
1186    let mut sa: sockaddr_un = sockaddr_un {
1187        sun_family: 0,
1188        sun_path: [0; 108],
1189    };
1190    let mut salen: socklen_t = core::mem::size_of::<sockaddr_un>() as libc::c_ulong
1191        as socklen_t;
1192    fd = anetGenericAccept(
1193        err,
1194        s,
1195        &mut sa as *mut sockaddr_un as *mut sockaddr,
1196        &mut salen,
1197    );
1198    if fd == -(1 as libc::c_int) {
1199        return -(1 as libc::c_int);
1200    }
1201    return fd;
1202}
1203#[no_mangle]
1204pub unsafe extern "C" fn anetFdToString(
1205    mut fd: libc::c_int,
1206    mut ip: *mut libc::c_char,
1207    mut ip_len: size_t,
1208    mut port: *mut libc::c_int,
1209    mut fd_to_str_type: libc::c_int,
1210) -> libc::c_int {
1211    let mut current_block: u64;
1212    let mut sa: sockaddr_storage = sockaddr_storage {
1213        ss_family: 0,
1214        __ss_padding: [0; 118],
1215        __ss_align: 0,
1216    };
1217    let mut salen: socklen_t = core::mem::size_of::<sockaddr_storage>()
1218        as libc::c_ulong as socklen_t;
1219    if fd_to_str_type == 0 as libc::c_int {
1220        if getpeername(
1221            fd,
1222            __SOCKADDR_ARG {
1223                __sockaddr__: &mut sa as *mut sockaddr_storage as *mut sockaddr,
1224            },
1225            &mut salen,
1226        ) == -(1 as libc::c_int)
1227        {
1228            current_block = 3946958208285236138;
1229        } else {
1230            current_block = 7502529970979898288;
1231        }
1232    } else if getsockname(
1233        fd,
1234        __SOCKADDR_ARG {
1235            __sockaddr__: &mut sa as *mut sockaddr_storage as *mut sockaddr,
1236        },
1237        &mut salen,
1238    ) == -(1 as libc::c_int)
1239    {
1240        current_block = 3946958208285236138;
1241    } else {
1242        current_block = 7502529970979898288;
1243    }
1244    match current_block {
1245        7502529970979898288 => {
1246            if sa.ss_family as libc::c_int == 2 as libc::c_int {
1247                let mut s: *mut sockaddr_in = &mut sa as *mut sockaddr_storage
1248                    as *mut sockaddr_in;
1249                if !ip.is_null() {
1250                    if (inet_ntop(
1251                        2 as libc::c_int,
1252                        &mut (*s).sin_addr as *mut in_addr as *mut libc::c_void,
1253                        ip,
1254                        ip_len as socklen_t,
1255                    ))
1256                        .is_null()
1257                    {
1258                        current_block = 3946958208285236138;
1259                    } else {
1260                        current_block = 17216689946888361452;
1261                    }
1262                } else {
1263                    current_block = 17216689946888361452;
1264                }
1265                match current_block {
1266                    3946958208285236138 => {}
1267                    _ => {
1268                        if !port.is_null() {
1269                            *port = __bswap_16((*s).sin_port) as libc::c_int;
1270                        }
1271                        current_block = 11307063007268554308;
1272                    }
1273                }
1274            } else if sa.ss_family as libc::c_int == 10 as libc::c_int {
1275                let mut s_0: *mut sockaddr_in6 = &mut sa as *mut sockaddr_storage
1276                    as *mut sockaddr_in6;
1277                if !ip.is_null() {
1278                    if (inet_ntop(
1279                        10 as libc::c_int,
1280                        &mut (*s_0).sin6_addr as *mut in6_addr as *mut libc::c_void,
1281                        ip,
1282                        ip_len as socklen_t,
1283                    ))
1284                        .is_null()
1285                    {
1286                        current_block = 3946958208285236138;
1287                    } else {
1288                        current_block = 3512920355445576850;
1289                    }
1290                } else {
1291                    current_block = 3512920355445576850;
1292                }
1293                match current_block {
1294                    3946958208285236138 => {}
1295                    _ => {
1296                        if !port.is_null() {
1297                            *port = __bswap_16((*s_0).sin6_port) as libc::c_int;
1298                        }
1299                        current_block = 11307063007268554308;
1300                    }
1301                }
1302            } else if sa.ss_family as libc::c_int == 1 as libc::c_int {
1303                if !ip.is_null() {
1304                    let mut res: libc::c_int = snprintf(
1305                        ip,
1306                        ip_len,
1307                        b"/unixsocket\0" as *const u8 as *const libc::c_char,
1308                    );
1309                    if res < 0 as libc::c_int
1310                        || res as libc::c_uint as libc::c_ulong >= ip_len
1311                    {
1312                        current_block = 3946958208285236138;
1313                    } else {
1314                        current_block = 12124785117276362961;
1315                    }
1316                } else {
1317                    current_block = 12124785117276362961;
1318                }
1319                match current_block {
1320                    3946958208285236138 => {}
1321                    _ => {
1322                        if !port.is_null() {
1323                            *port = 0 as libc::c_int;
1324                        }
1325                        current_block = 11307063007268554308;
1326                    }
1327                }
1328            } else {
1329                current_block = 3946958208285236138;
1330            }
1331            match current_block {
1332                3946958208285236138 => {}
1333                _ => return 0 as libc::c_int,
1334            }
1335        }
1336        _ => {}
1337    }
1338    if !ip.is_null() {
1339        if ip_len >= 2 as libc::c_int as libc::c_ulong {
1340            *ip.offset(0 as libc::c_int as isize) = '?' as i32 as libc::c_char;
1341            *ip.offset(1 as libc::c_int as isize) = '\0' as i32 as libc::c_char;
1342        } else if ip_len == 1 as libc::c_int as libc::c_ulong {
1343            *ip.offset(0 as libc::c_int as isize) = '\0' as i32 as libc::c_char;
1344        }
1345    }
1346    if !port.is_null() {
1347        *port = 0 as libc::c_int;
1348    }
1349    return -(1 as libc::c_int);
1350}
1351#[no_mangle]
1352pub unsafe extern "C" fn anetFormatAddr(
1353    mut buf: *mut libc::c_char,
1354    mut buf_len: size_t,
1355    mut ip: *mut libc::c_char,
1356    mut port: libc::c_int,
1357) -> libc::c_int {
1358    return snprintf(
1359        buf,
1360        buf_len,
1361        if !(strchr(ip, ':' as i32)).is_null() {
1362            b"[%s]:%d\0" as *const u8 as *const libc::c_char
1363        } else {
1364            b"%s:%d\0" as *const u8 as *const libc::c_char
1365        },
1366        ip,
1367        port,
1368    );
1369}
1370#[no_mangle]
1371pub unsafe extern "C" fn anetFormatFdAddr(
1372    mut fd: libc::c_int,
1373    mut buf: *mut libc::c_char,
1374    mut buf_len: size_t,
1375    mut fd_to_str_type: libc::c_int,
1376) -> libc::c_int {
1377    let mut ip: [libc::c_char; 46] = [0; 46];
1378    let mut port: libc::c_int = 0;
1379    anetFdToString(
1380        fd,
1381        ip.as_mut_ptr(),
1382        core::mem::size_of::<[libc::c_char; 46]>() as libc::c_ulong,
1383        &mut port,
1384        fd_to_str_type,
1385    );
1386    return anetFormatAddr(buf, buf_len, ip.as_mut_ptr(), port);
1387}
1388#[no_mangle]
1389pub unsafe extern "C" fn anetPipe(
1390    mut fds: *mut libc::c_int,
1391    mut read_flags: libc::c_int,
1392    mut write_flags: libc::c_int,
1393) -> libc::c_int {
1394    let mut current_block: u64;
1395    let mut pipe_flags: libc::c_int = 0 as libc::c_int;
1396    pipe_flags = 0o2000000 as libc::c_int | read_flags & write_flags;
1397    if pipe2(fds, pipe_flags) != 0 {
1398        if *__errno_location() != 38 as libc::c_int
1399            && *__errno_location() != 22 as libc::c_int
1400        {
1401            return -(1 as libc::c_int);
1402        }
1403        pipe_flags = 0 as libc::c_int;
1404    } else {
1405        if 0o2000000 as libc::c_int | read_flags
1406            == 0o2000000 as libc::c_int | write_flags
1407        {
1408            return 0 as libc::c_int;
1409        }
1410        read_flags &= !pipe_flags;
1411        write_flags &= !pipe_flags;
1412    }
1413    if pipe_flags == 0 as libc::c_int && pipe(fds) != 0 {
1414        return -(1 as libc::c_int);
1415    }
1416    if read_flags & 0o2000000 as libc::c_int != 0 {
1417        if fcntl(
1418            *fds.offset(0 as libc::c_int as isize),
1419            2 as libc::c_int,
1420            1 as libc::c_int,
1421        ) != 0
1422        {
1423            current_block = 17977527455243449991;
1424        } else {
1425            current_block = 7746791466490516765;
1426        }
1427    } else {
1428        current_block = 7746791466490516765;
1429    }
1430    match current_block {
1431        7746791466490516765 => {
1432            if write_flags & 0o2000000 as libc::c_int != 0 {
1433                if fcntl(
1434                    *fds.offset(1 as libc::c_int as isize),
1435                    2 as libc::c_int,
1436                    1 as libc::c_int,
1437                ) != 0
1438                {
1439                    current_block = 17977527455243449991;
1440                } else {
1441                    current_block = 13586036798005543211;
1442                }
1443            } else {
1444                current_block = 13586036798005543211;
1445            }
1446            match current_block {
1447                17977527455243449991 => {}
1448                _ => {
1449                    read_flags &= !(0o2000000 as libc::c_int);
1450                    if read_flags != 0 {
1451                        if fcntl(
1452                            *fds.offset(0 as libc::c_int as isize),
1453                            4 as libc::c_int,
1454                            read_flags,
1455                        ) != 0
1456                        {
1457                            current_block = 17977527455243449991;
1458                        } else {
1459                            current_block = 17407779659766490442;
1460                        }
1461                    } else {
1462                        current_block = 17407779659766490442;
1463                    }
1464                    match current_block {
1465                        17977527455243449991 => {}
1466                        _ => {
1467                            write_flags &= !(0o2000000 as libc::c_int);
1468                            if write_flags != 0 {
1469                                if fcntl(
1470                                    *fds.offset(1 as libc::c_int as isize),
1471                                    4 as libc::c_int,
1472                                    write_flags,
1473                                ) != 0
1474                                {
1475                                    current_block = 17977527455243449991;
1476                                } else {
1477                                    current_block = 6009453772311597924;
1478                                }
1479                            } else {
1480                                current_block = 6009453772311597924;
1481                            }
1482                            match current_block {
1483                                17977527455243449991 => {}
1484                                _ => return 0 as libc::c_int,
1485                            }
1486                        }
1487                    }
1488                }
1489            }
1490        }
1491        _ => {}
1492    }
1493    close(*fds.offset(0 as libc::c_int as isize));
1494    close(*fds.offset(1 as libc::c_int as isize));
1495    return -(1 as libc::c_int);
1496}
1497#[no_mangle]
1498pub unsafe extern "C" fn anetSetSockMarkId(
1499    mut err: *mut libc::c_char,
1500    mut fd: libc::c_int,
1501    mut id: uint32_t,
1502) -> libc::c_int {
1503    if setsockopt(
1504        fd,
1505        1 as libc::c_int,
1506        36 as libc::c_int,
1507        &mut id as *mut uint32_t as *mut libc::c_void,
1508        core::mem::size_of::<uint32_t>() as libc::c_ulong as socklen_t,
1509    ) == -(1 as libc::c_int)
1510    {
1511        anetSetError(
1512            err,
1513            b"setsockopt: %s\0" as *const u8 as *const libc::c_char,
1514            strerror(*__errno_location()),
1515        );
1516        return -(1 as libc::c_int);
1517    }
1518    return 0 as libc::c_int;
1519}