mirror of
https://github.com/vanhoefm/fragattacks.git
synced 2024-11-28 10:18:21 -05:00
wpaspy: Convert to/from str to bytes as needed for python3
The control interface commands use mostly ASCII or UTF-8 strings, so convert input/output to strings/bytes as needed for the socket operations with python3. Signed-off-by: Jouni Malinen <j@w1.fi>
This commit is contained in:
parent
04fa9fc7fd
commit
3a833d95b3
@ -52,7 +52,7 @@ class Ctrl:
|
||||
break
|
||||
self.s = socket.socket(af, socktype)
|
||||
self.s.settimeout(5)
|
||||
self.s.sendto("GET_COOKIE", sockaddr)
|
||||
self.s.sendto(b"GET_COOKIE", sockaddr)
|
||||
reply, server = self.s.recvfrom(4096)
|
||||
self.cookie = reply
|
||||
self.port = port
|
||||
@ -81,13 +81,24 @@ class Ctrl:
|
||||
self.started = False
|
||||
|
||||
def request(self, cmd, timeout=10):
|
||||
if type(cmd) == str:
|
||||
try:
|
||||
cmd2 = cmd.encode()
|
||||
cmd = cmd2
|
||||
except UnicodeDecodeError as e:
|
||||
pass
|
||||
if self.udp:
|
||||
self.s.sendto(self.cookie + cmd, self.sockaddr)
|
||||
else:
|
||||
self.s.send(cmd)
|
||||
[r, w, e] = select.select([self.s], [], [], timeout)
|
||||
if r:
|
||||
return self.s.recv(4096)
|
||||
res = self.s.recv(4096).decode()
|
||||
try:
|
||||
r = str(res)
|
||||
except UnicodeDecodeError as e:
|
||||
r = res
|
||||
return r
|
||||
raise Exception("Timeout on waiting response")
|
||||
|
||||
def attach(self):
|
||||
@ -127,5 +138,9 @@ class Ctrl:
|
||||
return False
|
||||
|
||||
def recv(self):
|
||||
res = self.s.recv(4096)
|
||||
return res
|
||||
res = self.s.recv(4096).decode()
|
||||
try:
|
||||
r = str(res)
|
||||
except UnicodeDecodeError as e:
|
||||
r = res
|
||||
return r
|
||||
|
Loading…
Reference in New Issue
Block a user