在comm/jni/ifaddrs.c的getNetlinkResponse函数中下面的语句有bug:
if((pid_t)l_hdr->nlmsg_pid != l_pid || (int)l_hdr->nlmsg_seq != p_socket)
{
continue;
}
netlink的文档上说, nlmsg_pid与process id并没有1:1的对应关系。
nlmsg_seq and nlmsg_pid are used to track messages. nlmsg_pid shows the origin of the message. Note that there isn't a 1:1 relationship between nlmsg_pid and the PID of the process if the message originated from a netlink socket. See the ADDRESS FORMATS section for further information.
https://linux.die.net/man/7/netlink
nlmsg_pid 的值实际上是bind的时候kernel为socket自动分配的nl_pid。
nl_pid is the unicast address of netlink socket. It's always 0 if the destination is in the kernel. For a user-space process, nl_pid is usually the PID of the process owning the destination socket. However, nl_pid identifies a netlink socket, not a process. If a process owns several netlink sockets, then nl_pid can only be equal to the process ID for at most one socket. There are two ways to assign nl_pid to a netlink socket. If the application sets nl_pid before calling bind(2), then it is up to the application to make sure that nl_pid is unique. If the application sets it to 0, the kernel takes care of assigning it. The kernel assigns the process ID to the first netlink socket the process opens and assigns a unique nl_pid to every netlink socket that the process subsequently creates.
https://linux.die.net/man/7/netlink
所以,对于不同的netlink socket, nlmsg_pid是不同的,我们不能把它和process id比较。