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

Function ql_syscall_connect

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

Source from the content-addressed store, hash-verified

255
256
257def ql_syscall_connect(ql: Qiling, sockfd: int, addr: int, addrlen: int):
258 sock = get_opened_socket(ql.os, sockfd)
259
260 if isinstance(sock, int):
261 return sock
262
263 data = ql.mem.read(addr, addrlen)
264
265 abits = ql.arch.bits
266 endian = ql.arch.endian
267
268 sockaddr = make_sockaddr(abits, endian)
269 sockaddr_obj = sockaddr.from_buffer(data)
270
271 if sock.family != sockaddr_obj.sa_family:
272 return -1
273
274 if sock.family == AF_UNIX:
275 hpath, vpath = ql_unix_socket_path(ql, data[2:])
276
277 # TODO: support connecting to fs_mapped unix sockets
278 ql.log.debug(f'Connecting to "{vpath}"')
279 dest = hpath
280
281 elif sock.family == AF_INET:
282 sockaddr_in = make_sockaddr_in(abits, endian)
283 sockaddr_obj = sockaddr_in.from_buffer(data)
284
285 port = ntohs(ql, sockaddr_obj.sin_port)
286 host = inet_htoa(ql, sockaddr_obj.sin_addr.s_addr)
287
288 ql.log.debug(f'Connecting to {host}:{port}')
289 dest = (host, port)
290
291 elif sock.family == AF_INET6 and ql.os.ipv6:
292 sockaddr_in6 = make_sockaddr_in6(abits, endian)
293 sockaddr_obj = sockaddr_in6.from_buffer(data)
294
295 port = ntohs(ql, sockaddr_obj.sin6_port)
296 host = inet6_htoa(ql, sockaddr_obj.sin6_addr.s6_addr)
297
298 ql.log.debug(f'Connecting to {host}:{port}')
299 dest = (host, port)
300
301 else:
302 return -EAFNOSUPPORT
303
304 try:
305 sock.connect(dest)
306 except (ConnectionError, FileNotFoundError) as ex:
307 return -ex.errno
308
309 return 0
310
311
312def ql_syscall_getsockopt(ql: Qiling, sockfd: int, level: int, optname: int, optval_addr: int, optlen_addr: int):

Callers

nothing calls this directly

Calls 10

get_opened_socketFunction · 0.85
make_sockaddrFunction · 0.85
ql_unix_socket_pathFunction · 0.85
ntohsFunction · 0.85
inet_htoaFunction · 0.85
inet6_htoaFunction · 0.85
make_sockaddr_inFunction · 0.50
make_sockaddr_in6Function · 0.50
readMethod · 0.45
connectMethod · 0.45

Tested by

no test coverage detected