libnet: fix compil warning

This commit is contained in:
Jacek Jendrzej
2020-01-29 22:42:41 +01:00
parent 5c756e9dc5
commit 55ed87727b

View File

@@ -172,8 +172,8 @@ void netGetDefaultRoute( std::string &ip )
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); /* skip header */ char *fg = fgets(zeile,sizeof(zeile),fp); /* skip header */
while(fgets(zeile,sizeof(zeile),fp)) while(fg && (fg = fgets(zeile,sizeof(zeile),fp)))
{ {
destination = 1; /* in case sscanf fails */ destination = 1; /* in case sscanf fails */
sscanf(zeile,"%8s %x %x", interface, &destination, &gw); sscanf(zeile,"%8s %x %x", interface, &destination, &gw);
@@ -218,14 +218,19 @@ void netGetHostname( std::string &host )
void netSetHostname( std::string &host ) void netSetHostname( std::string &host )
{ {
FILE * fp; if (sethostname(host.c_str(), host.length()) < 0)
{
sethostname(host.c_str(), host.length()); fprintf(stderr, "error set %s\n", host.c_str());
fp = fopen("/etc/hostname", "w"); }
if(fp != NULL) { else
{
FILE * fp = fopen("/etc/hostname", "w");
if(fp != NULL)
{
fprintf(fp, "%s\n", host.c_str()); fprintf(fp, "%s\n", host.c_str());
fclose(fp); fclose(fp);
} }
}
} }
void netSetNameserver(std::string &ip) void netSetNameserver(std::string &ip)