projects
/
saartuer.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
bc0d1ae
)
tuerd: Get peer information from socket
author
Ralf Jung
<post@ralfj.de>
Mon, 16 Sep 2013 14:11:21 +0000
(16:11 +0200)
committer
Ralf Jung
<post@ralfj.de>
Mon, 16 Sep 2013 14:11:21 +0000
(16:11 +0200)
tuerd
patch
|
blob
|
history
diff --git
a/tuerd
b/tuerd
index 5884d131e1b0d26b0bd67a9f107879a1d907087b..f679fa896c2bc1ab75f9c28155630f06ad783507 100755
(executable)
--- a/
tuerd
+++ b/
tuerd
@@
-1,7
+1,8
@@
#!/usr/bin/python3
#!/usr/bin/python3
-import time, socket, os, stat, atexit, errno
+import time, socket, os, stat, atexit, errno
, struct
from datetime import datetime
import RPi.GPIO as GPIO
from datetime import datetime
import RPi.GPIO as GPIO
+SO_PEERCRED = 17 # DO - NOT - TOUCH
GPIO.setmode(GPIO.BOARD)
# ******** definitions *********
GPIO.setmode(GPIO.BOARD)
# ******** definitions *********
@@
-89,7
+90,8
@@
sock.listen(1)
while True:
# accept connections
conn, addr = sock.accept()
while True:
# accept connections
conn, addr = sock.accept()
- # TODO: use addr to determine the client for logging
+ # get peer information (TODO use it for logging)
+ (pid, uid, gid) = (struct.unpack('3i', conn.getsockopt(socket.SOL_SOCKET, SO_PEERCRED, struct.calcsize('3i'))))
# get some data from the client (enough to hold any valid command)
data = conn.recv (32)
# log the command
# get some data from the client (enough to hold any valid command)
data = conn.recv (32)
# log the command