在 Ad-hoc 网络中使用多播套接字会出现:[Errno 19] No such device

Using multicast socket in Ad-hoc network yelds: [Errno 19] No such device

我想在 ad-hoc 网络拓扑中创建多播套接字连接。 我在 python 中有一个 client/server 实现,它在正常网络配置上运行良好,这意味着具有 Internet 连接的标准网络配置。
这是客户端连接器的代码,"subscriber":

if __name__ == "__main__":
    multicast_group = '224.0.0.1'
    server_address = ('', 10000)

    # Create the socket
    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

    # Bind to the server address
    sock.bind(server_address)

    # Tell the operating system to add the socket to the multicast group
    # on all interfaces.
    group = socket.inet_aton(multicast_group)
    mreq = struct.pack('4sL', group, socket.INADDR_ANY)
    sock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq)

在正常的互联网连接网络中,这工作正常,但在临时网络拓扑中, 这会引发错误:

File "main.py" line 33
setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq)
File "usr/lib/python2.7/socket.py", line 228, in meth
return getattr(self.__sock, name)(*args)
socket.error: [Error 19] No such device

知道发生了什么事吗?
谢谢

一个可行的解决方案是手动设置套接字使用的网络接口:

sock.setsockopt(socket.SOL_SOCKET, 25, 'bat0')

并添加成员到组和主机名:

group = socket.inet_aton(multicast_group)
intf = socket.gethostbyname(socket.gethostname())

sock.setsockopt(socket.SOL_IP, socket.IP_ADD_MEMBERSHIP, group + socket.inet_aton(intf))