Skip to content

Instantly share code, notes, and snippets.

@wolfhechel
Created October 8, 2014 05:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wolfhechel/24b1242ea55c7938c772 to your computer and use it in GitHub Desktop.
Save wolfhechel/24b1242ea55c7938c772 to your computer and use it in GitHub Desktop.
import socket
import os
def make_local_sock_path(sock: socket.socket):
return '/tmp/wpa_ctrl_{}-{}'.format(os.getpid(), sock.fileno())
def prepare_wpa_ctrl_socket(ctrl_path: str, local_sock_path=make_local_sock_path):
sock = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM, 0)
bind_path = local_sock_path(sock)
sock.bind(bind_path)
try:
sock.connect(ctrl_path)
except socket.error:
sock.close()
os.unlink(bind_path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment