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

Function ql_syscall_sendto

qiling/os/posix/syscall/socket.py:821–882  ·  view source on GitHub ↗
(ql: Qiling, sockfd: int, buf: int, length: int, flags: int, addr: int, addrlen: int)

Source from the content-addressed store, hash-verified

819
820
821def ql_syscall_sendto(ql: Qiling, sockfd: int, buf: int, length: int, flags: int, addr: int, addrlen: int):
822 sock = get_opened_socket(ql.os, sockfd)
823
824 if isinstance(sock, int):
825 return sock
826
827 # if sendto is used on a connection-mode socket, the arguments addr and addrlen are ignored.
828 # also, calling sendto(sockfd, buf, length, flags, NULL, 0) is equivalent to send(sockfd, buf, length, flags)
829 if sock.socktype in (SOCK_STREAM, SOCK_SEQPACKET) or (addr == 0 and addrlen == 0):
830 return ql_syscall_send(ql, sockfd, buf, length, flags)
831
832 tmp_buf = ql.mem.read(buf, length)
833
834 ql.log.debug("sendto() CONTENT:")
835 ql.log.debug("%s" % tmp_buf)
836
837 data = ql.mem.read(addr, addrlen)
838
839 abits = ql.arch.bits
840 endian = ql.arch.endian
841
842 sockaddr = make_sockaddr(abits, endian)
843 sockaddr_obj = sockaddr.from_buffer(data)
844
845 sa_family = sockaddr_obj.sa_family
846
847 dest = None
848 regreturn = 0
849
850 if sa_family == AF_UNIX:
851 hpath, vpath = ql_unix_socket_path(ql, data[2:])
852
853 ql.log.debug(f'Sending {len(tmp_buf):d} bytes to {vpath}')
854 dest = hpath
855
856 elif sa_family == AF_INET:
857 sockaddr = make_sockaddr_in(abits, endian)
858 sockaddr_obj = sockaddr.from_buffer(data)
859
860 port = ntohs(ql, sockaddr_obj.sin_port)
861 host = inet_ntoa(sockaddr_obj.sin_addr.s_addr)
862
863 ql.log.debug(f'Sending {len(tmp_buf):d} bytes to {host}:{port}')
864 dest = (host, port)
865
866 elif sa_family == AF_INET6 and ql.os.ipv6:
867 sockaddr_in6 = make_sockaddr_in6(abits, endian)
868 sockaddr_obj = sockaddr_in6.from_buffer(data)
869
870 port = ntohs(ql, sockaddr_obj.sin6_port)
871 host = inet6_ntoa(sockaddr_obj.sin6_addr.s6_addr)
872
873 ql.log.debug(f'Sending to {host}:{port}')
874 dest = (host, port)
875
876 if dest is not None:
877 try:
878 regreturn = sock.sendto(tmp_buf, flags, dest)

Callers

nothing calls this directly

Calls 11

get_opened_socketFunction · 0.85
ql_syscall_sendFunction · 0.85
make_sockaddrFunction · 0.85
ql_unix_socket_pathFunction · 0.85
ntohsFunction · 0.85
inet_ntoaFunction · 0.85
inet6_ntoaFunction · 0.85
sendtoMethod · 0.80
make_sockaddr_inFunction · 0.50
make_sockaddr_in6Function · 0.50
readMethod · 0.45

Tested by

no test coverage detected