Basic test/demo scripts for fd passing
parent
004f990be6
commit
73d45e4fac
@ -0,0 +1,24 @@
|
||||
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()
|
@ -0,0 +1,20 @@
|
||||
import socket
|
||||
import sys
|
||||
import array
|
||||
skname = sys.argv[1]
|
||||
|
||||
sk = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
||||
sk.connect(skname)
|
||||
data, anc, _flags, _addr = sk.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))
|
||||
input('reply?')
|
||||
protos = open('/etc/protocols')
|
||||
sk.sendmsg([b'hello!'],
|
||||
[(socket.SOL_SOCKET, socket.SCM_RIGHTS, array.array('i', [protos.fileno()]))],
|
||||
)
|
||||
sk.close()
|
Loading…
Reference in New Issue