MCPcopy Create free account
hub / github.com/qilingframework/qiling / ql_syscall_accept

Function ql_syscall_accept

qiling/os/posix/syscall/socket.py:590–662  ·  view source on GitHub ↗
(ql: Qiling, sockfd: int, addr: int, addrlenptr: int)

Source from the content-addressed store, hash-verified

588
589
590def ql_syscall_accept(ql: Qiling, sockfd: int, addr: int, addrlenptr: int):
591 sock = get_opened_socket(ql.os, sockfd)
592
593 if isinstance(sock, int):
594 return sock
595
596 try:
597 conn, address = sock.accept()
598 except ConnectionError:
599 return -1
600
601 if (conn is None) or (address is None):
602 return -1
603
604 idx = next((i for i in range(NR_OPEN) if ql.os.fd[i] is None), -1)
605
606 if idx == -1:
607 return -EMFILE
608
609 ql.os.fd[idx] = conn
610
611 if addr:
612 addrlen = ql.mem.read_ptr(addrlenptr) if addrlenptr else 0
613
614 abits = ql.arch.bits
615 endian = ql.arch.endian
616
617 obj = None
618
619 if conn.family == AF_UNIX:
620 hpath = address
621 vpath = ql.os.path.host_to_virtual_path(hpath)
622
623 if addrlen:
624 # addrlen indicates the total obj size allowed to be written.
625 # that already includes the family field (2) and the path null
626 # terminator (1)
627 vpath = vpath[:addrlen - 2 - 1]
628
629 sockaddr_un = make_sockaddr_un(abits, endian, len(vpath) + 1)
630
631 obj = sockaddr_un()
632 obj.sun_family = AF_UNIX
633 obj.sun_path = vpath.encode() + b'\x00'
634
635 elif conn.family == AF_INET:
636 sockaddr_in = make_sockaddr_in(abits, endian)
637 host, port = address
638
639 obj = sockaddr_in()
640 obj.sin_family = AF_INET
641 obj.sin_port = htons(ql, port)
642 obj.sin_addr.s_addr = inet_aton(str(host))
643
644 elif conn.family == AF_INET6 and ql.os.ipv6:
645 sockaddr_in6 = make_sockaddr_in6(abits, endian)
646 host, port = address
647

Callers

nothing calls this directly

Calls 15

get_opened_socketFunction · 0.85
make_sockaddr_unFunction · 0.85
sockaddr_unClass · 0.85
htonsFunction · 0.85
inet_atonFunction · 0.85
inet6_atonFunction · 0.85
acceptMethod · 0.80
read_ptrMethod · 0.80
host_to_virtual_pathMethod · 0.80
sizeofMethod · 0.80
save_toMethod · 0.80
write_ptrMethod · 0.80

Tested by

no test coverage detected