Created
October 8, 2014 05:03
-
-
Save wolfhechel/24b1242ea55c7938c772 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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