我正在尝试在 Mac 上运行以下函数并且它正在抛出
struct.pack('iL', bytes, names.buffer_info()[0])
IOError: [Errno 102] Operation not supported on socket
它在linux上工作得很好。谁能告诉我发生了什么事?
代码:
def _get_interface_list():
max_iface = 32 # Maximum number of interfaces(Aribtrary)
bytes = max_iface * 32
is_32bit = (8 * struct.calcsize("P")) == 32 # Set Architecture
struct_size = 32 if is_32bit else 40
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
names = array.array('B', '\0' * bytes)
outbytes = struct.unpack('iL', fcntl.ioctl(
s.fileno(),
0x8912, # SIOCGIFCONF
struct.pack('iL', bytes, names.buffer_info()[0])
))[0]
namestr = names.tostring()
return namestr