l_net: don't segfault of gethostbyname(gethostname()) fails

Can happen on Linux with misconfigured /etc/hosts.
This commit is contained in:
Rudolf Polzer 2012-10-24 15:55:42 +02:00
parent a28eb11302
commit cb907744d6
2 changed files with 8 additions and 2 deletions

View File

@ -173,7 +173,10 @@ int WINS_Init( void ){
// determine my name & address // determine my name & address
gethostname( buff, MAXHOSTNAMELEN ); gethostname( buff, MAXHOSTNAMELEN );
local = gethostbyname( buff ); local = gethostbyname( buff );
if(local && local->h_addr_list && local->h_addr_list[0])
myAddr = *(int *)local->h_addr_list[0]; myAddr = *(int *)local->h_addr_list[0];
else
myAddr = inet_ntoa("127.0.0.1");
// if the quake hostname isn't set, set it to the machine name // if the quake hostname isn't set, set it to the machine name
// if (Q_strcmp(hostname.string, "UNNAMED") == 0) // if (Q_strcmp(hostname.string, "UNNAMED") == 0)

View File

@ -196,7 +196,10 @@ int WINS_Init( void ){
// determine my name & address // determine my name & address
gethostname( buff, MAXHOSTNAMELEN ); gethostname( buff, MAXHOSTNAMELEN );
local = gethostbyname( buff ); local = gethostbyname( buff );
if(local && local->h_addr_list && local->h_addr_list[0])
myAddr = *(int *)local->h_addr_list[0]; myAddr = *(int *)local->h_addr_list[0];
else
myAddr = inet_ntoa("127.0.0.1");
// if the quake hostname isn't set, set it to the machine name // if the quake hostname isn't set, set it to the machine name
// if (Q_strcmp(hostname.string, "UNNAMED") == 0) // if (Q_strcmp(hostname.string, "UNNAMED") == 0)