From d8fabf2e52980d174c5cb87e24a18a16a54846dd Mon Sep 17 00:00:00 2001 From: Volker Fischer Date: Sat, 24 Feb 2007 09:49:52 +0000 Subject: [PATCH] implements possiblity to select host by name and not only by IP address (of course, selecting a host by IP address is still possible) --- src/client.cpp | 36 ++++++++++++++++++++++++++++-------- src/client.h | 2 ++ windows/llcon.dsp | 4 ++-- 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/src/client.cpp b/src/client.cpp index ffca08bf..efaaa913 100755 --- a/src/client.cpp +++ b/src/client.cpp @@ -88,17 +88,37 @@ bool CClient::SetServerAddr ( QString strNAddr ) { QHostAddress InetAddr; - if ( InetAddr.setAddress ( strNAddr ) ) + // first try if this is an IP number an can directly applied to QHostAddress + if ( !InetAddr.setAddress ( strNAddr ) ) { - // the server port is fixed and always the same - Channel.SetAddress ( CHostAddress ( InetAddr, LLCON_PORT_NUMBER ) ); - return true; - } - else - { - return false; // invalid address +// TODO implement the IP number query with QT objects (this is not possible with +// QT 2 so we have to implement a workaround solution here + + // it was no vaild IP address, try to get host by name, assuming + // that the string contains a valid host name string + const hostent* HostInf = gethostbyname ( strNAddr.latin1() ); + + if ( HostInf ) + { + uint32_t dwIPNumber; + + // copy IP address of first found host in host list + memcpy ( (char*) &dwIPNumber, HostInf->h_addr_list[0], sizeof ( dwIPNumber ) ); + + // apply IP address to QT object (change byte order, too) + InetAddr.setAddress ( htonl ( dwIPNumber ) ); + } + else + { + return false; // invalid address + } } + + // apply address (the server port is fixed and always the same) + Channel.SetAddress ( CHostAddress ( InetAddr, LLCON_PORT_NUMBER ) ); + + return true; } void CClient::OnProtocolStatus ( bool bOk ) diff --git a/src/client.h b/src/client.h index da5d512a..ce70f0e1 100755 --- a/src/client.h +++ b/src/client.h @@ -39,6 +39,8 @@ #else # include "../linux/sound.h" # include +# include +# include #endif diff --git a/windows/llcon.dsp b/windows/llcon.dsp index 4280f1e0..6490210f 100755 --- a/windows/llcon.dsp +++ b/windows/llcon.dsp @@ -54,7 +54,7 @@ BSC32=bscmake.exe # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386 -# ADD LINK32 winmm.lib $(QTDIR)\lib\qt-mt230nc.lib $(QTDIR)\lib\qtmain.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386 +# ADD LINK32 ws2_32.lib winmm.lib $(QTDIR)\lib\qt-mt230nc.lib $(QTDIR)\lib\qtmain.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386 !ELSEIF "$(CFG)" == "llcon - Win32 Debug" @@ -81,7 +81,7 @@ BSC32=bscmake.exe # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept -# ADD LINK32 winmm.lib $(QTDIR)\lib\qt-mt230nc.lib $(QTDIR)\lib\qtmain.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept +# ADD LINK32 ws2_32.lib winmm.lib $(QTDIR)\lib\qt-mt230nc.lib $(QTDIR)\lib\qtmain.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept !ENDIF