From 0d8ed0a52313b378bbe98e71ae7a10f9d1f44b0f Mon Sep 17 00:00:00 2001 From: TTimo Date: Mon, 14 Apr 2008 20:15:34 +0000 Subject: [PATCH] error handling in watchbsp (contributed by ilm) git-svn-id: svn://svn.icculus.org/gtkradiant/GtkRadiant/branches/ZeroRadiant@250 8a3a26a2-13c4-0310-b231-cf6edde360e5 --- libs/l_net/l_net.c | 4 +++- libs/l_net/l_net_berkeley.c | 8 ++++++++ radiant/watchbsp.cpp | 7 +++++-- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/libs/l_net/l_net.c b/libs/l_net/l_net.c index 9ead665..a8a5957 100644 --- a/libs/l_net/l_net.c +++ b/libs/l_net/l_net.c @@ -346,7 +346,9 @@ void Net_MyAddress(address_t *address) //=========================================================================== int Net_Setup(void) { - WINS_Init(); + if( !WINS_Init() ) + return qfalse; + // WinPrint("my address is %s\n", WINS_MyAddress()); // diff --git a/libs/l_net/l_net_berkeley.c b/libs/l_net/l_net_berkeley.c index 2d4d33b..e7d0b96 100644 --- a/libs/l_net/l_net_berkeley.c +++ b/libs/l_net/l_net_berkeley.c @@ -175,6 +175,14 @@ int WINS_Init(void) // determine my name & address gethostname(buff, MAXHOSTNAMELEN); local = gethostbyname(buff); + + // When hostname can not be resolved, return gracefully + if( local == 0 ) + { + WinError("WINS_Init: Unable to resolve hostname\n"); + return 0; + } + myAddr = *(int *)local->h_addr_list[0]; // if the quake hostname isn't set, set it to the machine name diff --git a/radiant/watchbsp.cpp b/radiant/watchbsp.cpp index 314921a..2c85e57 100644 --- a/radiant/watchbsp.cpp +++ b/radiant/watchbsp.cpp @@ -305,10 +305,13 @@ bool CWatchBSP::SetupListening() } #endif Sys_Printf("Setting up\n"); - Net_Setup(); - m_pListenSocket = Net_ListenSocket(39000); + if( !Net_Setup() ) + return false; + + m_pListenSocket = Net_ListenSocket(39000); if (m_pListenSocket == NULL) return false; + Sys_Printf("Listening...\n"); return true; }