libnet: fix compil warning

Origin commit data
------------------
Branch: ni/coolstream
Commit: 0a14475cfc
Author: Jacek Jendrzej <overx300@gmail.com>
Date: 2020-01-29 (Wed, 29 Jan 2020)


------------------
No further description and justification available within origin commit message!

------------------
This commit was generated by Migit
This commit is contained in:
Jacek Jendrzej
2020-01-29 23:35:31 +01:00
committed by vanhofen
parent 48aa8967ba
commit 9f0ad28628

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,13 +218,18 @@ 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
fprintf(fp, "%s\n", host.c_str()); {
fclose(fp); FILE * fp = fopen("/etc/hostname", "w");
if(fp != NULL)
{
fprintf(fp, "%s\n", host.c_str());
fclose(fp);
}
} }
} }