Skip to content

Commit 0eebdca

Browse files
committed
Add rules for AF_INET and AF_INET6 macros
1 parent 1b8fd85 commit 0eebdca

4 files changed

Lines changed: 54 additions & 42 deletions

File tree

rules/socket/src.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,11 @@ ssize_t f19(int sockfd, const void *buf, size_t len, int flags,
8585
const struct sockaddr *dest_addr, socklen_t addrlen) {
8686
return sendto(sockfd, buf, len, flags, dest_addr, addrlen);
8787
}
88+
89+
int f20() {
90+
return AF_INET;
91+
}
92+
93+
int f21() {
94+
return AF_INET6;
95+
}

rules/socket/tgt_unsafe.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,11 @@ unsafe fn f19(
9494
) -> isize {
9595
libc::sendto(a0, a1, a2, a3, a4, a5)
9696
}
97+
98+
unsafe fn f20() -> i32 {
99+
libc::AF_INET
100+
}
101+
102+
unsafe fn f21() -> i32 {
103+
libc::AF_INET6
104+
}

tests/unit/out/refcount/inet_pton_ntop.rs

Lines changed: 30 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ fn main_0() -> i32 {
1414
(0..16).map(|_| <u8>::default()).collect::<Box<[u8]>>(),
1515
));
1616
assert!(
17-
(((if 2 == libc::AF_INET {
17+
(((if libc::AF_INET == libc::AF_INET {
1818
match Ptr::from_string_literal(b"1.2.3.4")
1919
.to_rust_string()
2020
.parse::<std::net::Ipv4Addr>()
@@ -32,7 +32,7 @@ fn main_0() -> i32 {
3232
}
3333
Err(_) => 0,
3434
}
35-
} else if 2 == libc::AF_INET6 {
35+
} else if libc::AF_INET == libc::AF_INET6 {
3636
match Ptr::from_string_literal(b"1.2.3.4")
3737
.to_rust_string()
3838
.parse::<std::net::Ipv6Addr>()
@@ -66,7 +66,7 @@ fn main_0() -> i32 {
6666
!= 0)
6767
);
6868
assert!(
69-
(((if 2 == libc::AF_INET {
69+
(((if libc::AF_INET == libc::AF_INET {
7070
match Ptr::from_string_literal(b"999.1.1.1")
7171
.to_rust_string()
7272
.parse::<std::net::Ipv4Addr>()
@@ -84,7 +84,7 @@ fn main_0() -> i32 {
8484
}
8585
Err(_) => 0,
8686
}
87-
} else if 2 == libc::AF_INET6 {
87+
} else if libc::AF_INET == libc::AF_INET6 {
8888
match Ptr::from_string_literal(b"999.1.1.1")
8989
.to_rust_string()
9090
.parse::<std::net::Ipv6Addr>()
@@ -108,7 +108,7 @@ fn main_0() -> i32 {
108108
!= 0)
109109
);
110110
assert!(
111-
(((if 2 == libc::AF_INET {
111+
(((if libc::AF_INET == libc::AF_INET {
112112
match Ptr::from_string_literal(b"not an ip")
113113
.to_rust_string()
114114
.parse::<std::net::Ipv4Addr>()
@@ -126,7 +126,7 @@ fn main_0() -> i32 {
126126
}
127127
Err(_) => 0,
128128
}
129-
} else if 2 == libc::AF_INET6 {
129+
} else if libc::AF_INET == libc::AF_INET6 {
130130
match Ptr::from_string_literal(b"not an ip")
131131
.to_rust_string()
132132
.parse::<std::net::Ipv6Addr>()
@@ -150,7 +150,7 @@ fn main_0() -> i32 {
150150
!= 0)
151151
);
152152
assert!(
153-
(((if 10 == libc::AF_INET {
153+
(((if libc::AF_INET6 == libc::AF_INET {
154154
match Ptr::from_string_literal(b"::1")
155155
.to_rust_string()
156156
.parse::<std::net::Ipv4Addr>()
@@ -168,7 +168,7 @@ fn main_0() -> i32 {
168168
}
169169
Err(_) => 0,
170170
}
171-
} else if 10 == libc::AF_INET6 {
171+
} else if libc::AF_INET6 == libc::AF_INET6 {
172172
match Ptr::from_string_literal(b"::1")
173173
.to_rust_string()
174174
.parse::<std::net::Ipv6Addr>()
@@ -197,7 +197,7 @@ fn main_0() -> i32 {
197197
!= 0)
198198
);
199199
assert!(
200-
(((if 10 == libc::AF_INET {
200+
(((if libc::AF_INET6 == libc::AF_INET {
201201
match Ptr::from_string_literal(b"2001:db8::5")
202202
.to_rust_string()
203203
.parse::<std::net::Ipv4Addr>()
@@ -215,7 +215,7 @@ fn main_0() -> i32 {
215215
}
216216
Err(_) => 0,
217217
}
218-
} else if 10 == libc::AF_INET6 {
218+
} else if libc::AF_INET6 == libc::AF_INET6 {
219219
match Ptr::from_string_literal(b"2001:db8::5")
220220
.to_rust_string()
221221
.parse::<std::net::Ipv6Addr>()
@@ -251,8 +251,8 @@ fn main_0() -> i32 {
251251
let four: Value<Box<[u8]>> = Rc::new(RefCell::new(Box::new([10_u8, 0_u8, 0_u8, 1_u8])));
252252
assert!(
253253
((({
254-
let mut __p1 = {
255-
let __text = if 2 == libc::AF_INET {
254+
let mut __it1 = {
255+
let __text = if libc::AF_INET == libc::AF_INET {
256256
let mut __b = [0u8; 4];
257257
for __i in 0..4 {
258258
__b[__i] = ((four.as_pointer() as Ptr<u8>) as Ptr<u8>)
@@ -262,7 +262,7 @@ fn main_0() -> i32 {
262262
.read();
263263
}
264264
Some(std::net::Ipv4Addr::from(__b).to_string())
265-
} else if 2 == libc::AF_INET6 {
265+
} else if libc::AF_INET == libc::AF_INET6 {
266266
let mut __b = [0u8; 16];
267267
for __i in 0..16 {
268268
__b[__i] = ((four.as_pointer() as Ptr<u8>) as Ptr<u8>)
@@ -290,19 +290,17 @@ fn main_0() -> i32 {
290290
_ => Ptr::null(),
291291
}
292292
}
293-
.clone();
294-
let mut __p2 = Ptr::from_string_literal(b"10.0.0.1").clone();
293+
.to_c_string_iterator();
294+
let mut __it2 = Ptr::from_string_literal(b"10.0.0.1").to_c_string_iterator();
295295
loop {
296-
let __c1 = __p1.read();
297-
let __c2 = __p2.read();
296+
let __c1 = __it1.next();
297+
let __c2 = __it2.next();
298298
if __c1 != __c2 {
299-
break (__c1 as i32) - (__c2 as i32);
299+
break (__c1.unwrap_or(0) as i32) - (__c2.unwrap_or(0) as i32);
300300
}
301-
if __c1 == 0 {
301+
if __c1.is_none() {
302302
break 0;
303303
}
304-
__p1 += 1;
305-
__p2 += 1;
306304
}
307305
} == 0) as i32)
308306
!= 0)
@@ -328,8 +326,8 @@ fn main_0() -> i32 {
328326
(*sixteen.borrow_mut())[(15) as usize] = 1_u8;
329327
assert!(
330328
((({
331-
let mut __p1 = {
332-
let __text = if 10 == libc::AF_INET {
329+
let mut __it1 = {
330+
let __text = if libc::AF_INET6 == libc::AF_INET {
333331
let mut __b = [0u8; 4];
334332
for __i in 0..4 {
335333
__b[__i] = ((sixteen.as_pointer() as Ptr<u8>) as Ptr<u8>)
@@ -339,7 +337,7 @@ fn main_0() -> i32 {
339337
.read();
340338
}
341339
Some(std::net::Ipv4Addr::from(__b).to_string())
342-
} else if 10 == libc::AF_INET6 {
340+
} else if libc::AF_INET6 == libc::AF_INET6 {
343341
let mut __b = [0u8; 16];
344342
for __i in 0..16 {
345343
__b[__i] = ((sixteen.as_pointer() as Ptr<u8>) as Ptr<u8>)
@@ -367,26 +365,24 @@ fn main_0() -> i32 {
367365
_ => Ptr::null(),
368366
}
369367
}
370-
.clone();
371-
let mut __p2 = Ptr::from_string_literal(b"::1").clone();
368+
.to_c_string_iterator();
369+
let mut __it2 = Ptr::from_string_literal(b"::1").to_c_string_iterator();
372370
loop {
373-
let __c1 = __p1.read();
374-
let __c2 = __p2.read();
371+
let __c1 = __it1.next();
372+
let __c2 = __it2.next();
375373
if __c1 != __c2 {
376-
break (__c1 as i32) - (__c2 as i32);
374+
break (__c1.unwrap_or(0) as i32) - (__c2.unwrap_or(0) as i32);
377375
}
378-
if __c1 == 0 {
376+
if __c1.is_none() {
379377
break 0;
380378
}
381-
__p1 += 1;
382-
__p2 += 1;
383379
}
384380
} == 0) as i32)
385381
!= 0)
386382
);
387383
assert!(
388384
(((({
389-
let __text = if 2 == libc::AF_INET {
385+
let __text = if libc::AF_INET == libc::AF_INET {
390386
let mut __b = [0u8; 4];
391387
for __i in 0..4 {
392388
__b[__i] = ((four.as_pointer() as Ptr<u8>) as Ptr<u8>)
@@ -396,7 +392,7 @@ fn main_0() -> i32 {
396392
.read();
397393
}
398394
Some(std::net::Ipv4Addr::from(__b).to_string())
399-
} else if 2 == libc::AF_INET6 {
395+
} else if libc::AF_INET == libc::AF_INET6 {
400396
let mut __b = [0u8; 16];
401397
for __i in 0..16 {
402398
__b[__i] = ((four.as_pointer() as Ptr<u8>) as Ptr<u8>)

tests/unit/out/unsafe/inet_pton_ntop.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ unsafe fn main_0() -> i32 {
1919
fn inet_pton(af: i32, src: *const libc::c_char, dst: *mut ::libc::c_void) -> i32;
2020
}
2121
inet_pton(
22-
2,
22+
libc::AF_INET,
2323
(c"1.2.3.4".as_ptr().cast_mut()).cast_const(),
2424
(buf.as_mut_ptr() as *mut u8 as *mut ::libc::c_void),
2525
)
@@ -41,7 +41,7 @@ unsafe fn main_0() -> i32 {
4141
fn inet_pton(af: i32, src: *const libc::c_char, dst: *mut ::libc::c_void) -> i32;
4242
}
4343
inet_pton(
44-
2,
44+
libc::AF_INET,
4545
(c"999.1.1.1".as_ptr().cast_mut()).cast_const(),
4646
(buf.as_mut_ptr() as *mut u8 as *mut ::libc::c_void),
4747
)
@@ -54,7 +54,7 @@ unsafe fn main_0() -> i32 {
5454
fn inet_pton(af: i32, src: *const libc::c_char, dst: *mut ::libc::c_void) -> i32;
5555
}
5656
inet_pton(
57-
2,
57+
libc::AF_INET,
5858
(c"not an ip".as_ptr().cast_mut()).cast_const(),
5959
(buf.as_mut_ptr() as *mut u8 as *mut ::libc::c_void),
6060
)
@@ -67,7 +67,7 @@ unsafe fn main_0() -> i32 {
6767
fn inet_pton(af: i32, src: *const libc::c_char, dst: *mut ::libc::c_void) -> i32;
6868
}
6969
inet_pton(
70-
10,
70+
libc::AF_INET6,
7171
(c"::1".as_ptr().cast_mut()).cast_const(),
7272
(buf.as_mut_ptr() as *mut u8 as *mut ::libc::c_void),
7373
)
@@ -85,7 +85,7 @@ unsafe fn main_0() -> i32 {
8585
fn inet_pton(af: i32, src: *const libc::c_char, dst: *mut ::libc::c_void) -> i32;
8686
}
8787
inet_pton(
88-
10,
88+
libc::AF_INET6,
8989
(c"2001:db8::5".as_ptr().cast_mut()).cast_const(),
9090
(buf.as_mut_ptr() as *mut u8 as *mut ::libc::c_void),
9191
)
@@ -113,7 +113,7 @@ unsafe fn main_0() -> i32 {
113113
) -> *const libc::c_char;
114114
}
115115
inet_ntop(
116-
2,
116+
libc::AF_INET,
117117
(four.as_mut_ptr() as *const u8 as *const ::libc::c_void),
118118
text.as_mut_ptr(),
119119
(::std::mem::size_of::<[libc::c_char; 64]>() as u32),
@@ -140,7 +140,7 @@ unsafe fn main_0() -> i32 {
140140
) -> *const libc::c_char;
141141
}
142142
inet_ntop(
143-
10,
143+
libc::AF_INET6,
144144
(sixteen.as_mut_ptr() as *const u8 as *const ::libc::c_void),
145145
text.as_mut_ptr(),
146146
(::std::mem::size_of::<[libc::c_char; 64]>() as u32),
@@ -161,7 +161,7 @@ unsafe fn main_0() -> i32 {
161161
) -> *const libc::c_char;
162162
}
163163
inet_ntop(
164-
2,
164+
libc::AF_INET,
165165
(four.as_mut_ptr() as *const u8 as *const ::libc::c_void),
166166
text.as_mut_ptr(),
167167
4_u32,

0 commit comments

Comments
 (0)