#!/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
+SO_PEERCRED = 17 # DO - NOT - TOUCH
GPIO.setmode(GPIO.BOARD)
# ******** definitions *********
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