File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -316,10 +316,10 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
316316 flags
317317 ) ;
318318 }
319- if protocol != 0 {
319+ if protocol != 0 && protocol != this . eval_libc_i32 ( "IPPROTO_TCP" ) {
320320 throw_unsup_format ! (
321321 "socket: socket protocol {protocol} is unsupported, \
322- only 0 is allowed"
322+ only IPPROTO_TCP and 0 are allowed"
323323 ) ;
324324 }
325325
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ const TEST_BYTES: &[u8] = b"these are some test bytes!";
1616
1717fn main ( ) {
1818 test_create_close ( ) ;
19+ test_create_close_tcp ( ) ;
1920 test_bind_ipv4 ( ) ;
2021 test_bind_ipv4_reuseaddr ( ) ;
2122 test_set_reuseaddr_invalid_len ( ) ;
@@ -59,6 +60,21 @@ fn test_create_close() {
5960 unsafe { errno_check ( libc:: close ( sockfd) ) } ;
6061}
6162
63+ /// Test creating a socket and then closing it afterwards but we explicitly
64+ /// specify that the TCP protocol should be used.
65+ fn test_create_close_tcp ( ) {
66+ let sockfd = unsafe {
67+ errno_result ( libc:: socket ( libc:: AF_INET , libc:: SOCK_STREAM , libc:: IPPROTO_TCP ) ) . unwrap ( )
68+ } ;
69+
70+ let flags = unsafe { errno_result ( libc:: fcntl ( sockfd, libc:: F_GETFL , 0 ) ) . unwrap ( ) } ;
71+
72+ // Ensure that socket is initially blocking.
73+ assert_eq ! ( flags & libc:: O_NONBLOCK , 0 ) ;
74+
75+ unsafe { errno_check ( libc:: close ( sockfd) ) } ;
76+ }
77+
6278fn test_bind_ipv4 ( ) {
6379 let sockfd =
6480 unsafe { errno_result ( libc:: socket ( libc:: AF_INET , libc:: SOCK_STREAM , 0 ) ) . unwrap ( ) } ;
You can’t perform that action at this time.
0 commit comments