libip: skip ipv6 loopback address (thanks mischief)

This commit is contained in:
cinap_lenrek 2014-12-26 09:34:30 +01:00
parent de349cf9b0
commit 7a54873252

View file

@ -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;