libip: skip ipv6 loopback address (thanks mischief)
This commit is contained in:
parent
de349cf9b0
commit
7a54873252
1 changed files with 20 additions and 7 deletions
|
@ -14,6 +14,12 @@ static uchar loopbackmask[IPaddrlen] = {
|
|||
0xff, 0xff, 0xff, 0xff,
|
||||
0xff, 0, 0, 0
|
||||
};
|
||||
static uchar loopback6[IPaddrlen] = {
|
||||
0, 0, 0, 0,
|
||||
0, 0, 0, 0,
|
||||
0, 0, 0, 0,
|
||||
0, 0, 0, 1
|
||||
};
|
||||
|
||||
// find first ip addr that isn't the friggin loopback address
|
||||
// unless there are no others
|
||||
|
@ -28,14 +34,21 @@ myipaddr(uchar *ip, char *net)
|
|||
ifc = readipifc(net, ifc, -1);
|
||||
for(nifc = ifc; nifc; nifc = nifc->next)
|
||||
for(lifc = nifc->lifc; lifc; lifc = lifc->next){
|
||||
maskip(lifc->ip, loopbackmask, mynet);
|
||||
if(ipcmp(mynet, loopbacknet) == 0){
|
||||
/* unspecified */
|
||||
if(ipcmp(lifc->ip, IPnoaddr) == 0)
|
||||
continue;
|
||||
}
|
||||
if(ipcmp(lifc->ip, IPnoaddr) != 0){
|
||||
ipmove(ip, lifc->ip);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ipv6 loopback */
|
||||
if(ipcmp(lifc->ip, loopback6) == 0)
|
||||
continue;
|
||||
|
||||
/* ipv4 loopback */
|
||||
maskip(lifc->ip, loopbackmask, mynet);
|
||||
if(ipcmp(mynet, loopbacknet) == 0)
|
||||
continue;
|
||||
|
||||
ipmove(ip, lifc->ip);
|
||||
return 0;
|
||||
}
|
||||
ipmove(ip, IPnoaddr);
|
||||
return -1;
|
||||
|
|
Loading…
Reference in a new issue