libnet: avoid type-punning compiler warning

Origin commit data
------------------
Commit: a0c277eaac
Author: Stefan Seyfried <seife@tuxbox-git.slipkontur.de>
Date: 2013-03-24 (Sun, 24 Mar 2013)
This commit is contained in:
Stefan Seyfried
2013-03-24 17:02:44 +01:00
parent 72ba486773
commit d8e1cae899

View File

@@ -157,23 +157,26 @@ 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;
break; /* 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;
} }
fclose(fp); fclose(fp);
} }