mirror of
https://github.com/tuxbox-neutrino/neutrino.git
synced 2025-08-29 16:31:11 +02:00
libnet: avoid type-punning compiler warning
This commit is contained in:
@@ -157,24 +157,27 @@ void netGetDefaultRoute( char *ip )
|
|||||||
{
|
{
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
char interface[9];
|
char interface[9];
|
||||||
unsigned char destination[4];
|
uint32_t destination;
|
||||||
unsigned char gateway[4];
|
uint32_t gw;
|
||||||
|
uint8_t gateway[4];
|
||||||
char zeile[256];
|
char zeile[256];
|
||||||
|
|
||||||
*ip = 0 ;
|
*ip = 0 ;
|
||||||
fp = fopen("/proc/net/route","r");
|
fp = fopen("/proc/net/route","r");
|
||||||
if (fp == NULL)
|
if (fp == NULL)
|
||||||
return;
|
return;
|
||||||
fgets(zeile,sizeof(zeile),fp);
|
fgets(zeile,sizeof(zeile),fp); /* skip header */
|
||||||
while(fgets(zeile,sizeof(zeile),fp))
|
while(fgets(zeile,sizeof(zeile),fp))
|
||||||
{
|
{
|
||||||
sscanf(zeile,"%8s %x %x",interface,(unsigned *) destination,(unsigned *) gateway);
|
destination = 1; /* in case sscanf fails */
|
||||||
if (*(unsigned *)destination == 0)
|
sscanf(zeile,"%8s %x %x", interface, &destination, &gw);
|
||||||
{
|
if (destination)
|
||||||
sprintf(ip,"%d.%d.%d.%d",gateway[0],gateway[1],gateway[2],gateway[3]);
|
continue;
|
||||||
|
/* big/little endian kernels have reversed entries, so this is correct */
|
||||||
|
memcpy(gateway, &gw, 4);
|
||||||
|
sprintf(ip, "%d.%d.%d.%d", gateway[0], gateway[1], gateway[2], gateway[3]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user