github.com/google/syzkaller@v0.0.0-20240517125934-c0f1611a36d6/sys/darwin/socket.txt (about)

     1  # Copyright 2021 syzkaller project authors. All rights reserved.
     2  # Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
     3  
     4  # TODO: due to autobind a socket can bind to port 0, that will result in a random port which is not reproducible
     5  
     6  include <sys/types.h>
     7  include <sys/socket.h>
     8  include <sys/sockio.h>
     9  include <netinet/in.h>
    10  
    11  resource sock[fd]
    12  type sock_port proc[20000, 4, int16be]
    13  
    14  socket(domain flags[socket_domain], type flags[socket_type], proto int8) sock
    15  socketpair(domain flags[socket_domain], type flags[socket_type], proto int8, fds ptr[out, sock_pair])
    16  bind(fd sock, addr ptr[in, sockaddr_storage], addrlen len[addr])
    17  connect(fd sock, addr ptr[in, sockaddr_storage], addrlen len[addr])
    18  accept(fd sock, peer ptr[out, sockaddr_storage, opt], peerlen ptr[inout, len[peer, int32]]) sock
    19  sendto(fd sock, buf buffer[in], len len[buf], f flags[send_flags], addr ptr[in, sockaddr_storage, opt], addrlen len[addr])
    20  recvfrom(fd sock, buf buffer[out], len len[buf], f flags[recv_flags], addr ptr[in, sockaddr_storage, opt], addrlen len[addr])
    21  getsockname(fd sock, addr ptr[out, sockaddr_storage], addrlen ptr[inout, len[addr, int32]])
    22  getpeername(fd sock, peer ptr[out, sockaddr_storage], peerlen ptr[inout, len[peer, int32]])
    23  
    24  sendmsg(fd sock, msg ptr[in, send_msghdr], f flags[send_flags])
    25  recvmsg(fd sock, msg ptr[inout, recv_msghdr], f flags[recv_flags])
    26  
    27  listen(fd sock, backlog int32)
    28  shutdown(fd sock, how flags[shutdown_flags])
    29  
    30  getsockopt(fd sock, level int32, optname int32, optval buffer[out], optlen ptr[inout, len[optval, int32]])
    31  setsockopt(fd sock, level int32, optname int32, optval buffer[in], optlen len[optval])
    32  
    33  socket_domain = AF_UNIX, AF_INET, AF_APPLETALK, AF_IPX, AF_INET6
    34  socket_type = SOCK_STREAM, SOCK_DGRAM, SOCK_RAW, SOCK_RDM, SOCK_SEQPACKET
    35  shutdown_flags = SHUT_RD, SHUT_WR
    36  send_flags = MSG_OOB, MSG_DONTROUTE, MSG_EOR, MSG_DONTWAIT, MSG_EOF
    37  recv_flags = MSG_OOB, MSG_PEEK, MSG_WAITALL, MSG_DONTWAIT
    38  
    39  cmsg_levels = SOL_SOCKET, IPPROTO_IP, IPPROTO_IPV6, IPPROTO_ICMP, IPPROTO_ICMPV6, IPPROTO_SCTP, IPPROTO_TCP, IPPROTO_UDP
    40  
    41  sock_pair {
    42  	fd0	sock
    43  	fd1	sock
    44  }
    45  
    46  # This sockaddr type corresponds to the sockaddr_storage type and is 128 bytes size.
    47  sockaddr_storage [
    48  	un	sockaddr_un
    49  	in	sockaddr_in
    50  	in6	sockaddr_in6
    51  ] [varlen]
    52  
    53  send_msghdr {
    54  	msg_name	ptr[in, sockaddr_storage, opt]
    55  	msg_namelen	len[msg_name, int32]
    56  	msg_iov		ptr[in, array[iovec_in]]
    57  	msg_iovlen	len[msg_iov, intptr]
    58  	msg_control	ptr[in, array[cmsghdr]]
    59  	msg_controllen	bytesize[msg_control, intptr]
    60  	msg_flags	const[0, int32]
    61  }
    62  
    63  recv_msghdr {
    64  	msg_name	ptr[out, sockaddr_storage, opt]
    65  	msg_namelen	len[msg_name, int32]
    66  	msg_iov		ptr[in, array[iovec_out]]
    67  	msg_iovlen	len[msg_iov, intptr]
    68  	msg_control	buffer[out]
    69  	msg_controllen	len[msg_control, intptr]
    70  	msg_flags	const[0, int32]
    71  }
    72  
    73  cmsghdr {
    74  	cmsg_len	len[parent, intptr]
    75  	cmsg_level	flags[cmsg_levels, int32]
    76  	cmsg_type	int32
    77  	data		array[int8]
    78  } [align[PTR_SIZE]]
    79  
    80  # Socket options
    81  
    82  getsockopt$sock_int(fd sock, level const[SOL_SOCKET], optname flags[sockopt_opt_sock_int], optval ptr[out, int32], optlen ptr[inout, len[optval, int32]])
    83  setsockopt$sock_int(fd sock, level const[SOL_SOCKET], optname flags[sockopt_opt_sock_int], optval ptr[in, int32], optlen len[optval])
    84  getsockopt$sock_linger(fd sock, level const[SOL_SOCKET], optname const[SO_LINGER], optval ptr[out, linger], optlen ptr[inout, len[optval, int32]])
    85  setsockopt$sock_linger(fd sock, level const[SOL_SOCKET], optname const[SO_LINGER], optval ptr[in, linger], optlen len[optval])
    86  getsockopt$sock_timeval(fd sock, level const[SOL_SOCKET], optname flags[sockopt_opt_sock_timeval], optval ptr[out, timeval], optlen ptr[inout, len[optval, int32]])
    87  setsockopt$sock_timeval(fd sock, level const[SOL_SOCKET], optname flags[sockopt_opt_sock_timeval], optval ptr[in, timeval], optlen len[optval])
    88  sockopt_opt_sock_int = SO_BROADCAST, SO_DEBUG, SO_DONTROUTE, SO_DONTTRUNC, SO_ERROR, SO_KEEPALIVE, SO_LABEL, SO_LINGER, SO_LINGER_SEC, SO_NETSVC_MARKING_LEVEL, SO_NET_SERVICE_TYPE, SO_NKE, SO_NOADDRERR, SO_NOSIGPIPE, SO_NOTIFYCONFLICT, SO_NP_EXTENSIONS, SO_NREAD, SO_NUMRCVPKT, SO_NWRITE, SO_OOBINLINE, SO_PEERLABEL, SO_RANDOMPORT, SO_RCVBUF, SO_RCVLOWAT, SO_REUSEADDR, SO_REUSEPORT, SO_REUSESHAREUID, SO_SNDBUF, SO_SNDLOWAT, SO_TIMESTAMP, SO_TIMESTAMP_MONOTONIC, SO_TYPE, SO_UPCALLCLOSEWAIT, SO_USELOOPBACK, SO_WANTMORE, SO_WANTOOBFLAG
    89  sockopt_opt_sock_timeval = SO_RCVTIMEO, SO_SNDTIMEO