You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
607 B
Python

#!/usr/bin/env python3
import socket
import sys
import array
skname = sys.argv[1]
sk = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
sk.bind(skname)
sk.listen()
clsock, _addrinfo = sk.accept()
#clsock.setsockopt(socket.SOL_SOCKET, socket.SO????
passwd = open('/etc/passwd')
clsock.sendmsg([b'hi!'],
[(socket.SOL_SOCKET, socket.SCM_RIGHTS, array.array('i', [passwd.fileno()]))],
)
print('-------------------')
data, anc, _flags, _addr = clsock.recvmsg(100, 100)
print(data.decode())
_level, _type, fdarr = anc[0]
arr = array.array('i')
arr.frombytes(fdarr)
f = open(arr[0])
print(next(f))
sk.close()