Here's how I time-out WSAAsyncGetHostByName().



Can you telnet to the server Mr Gates ?

If you like home-made “ cooking ”,
here's how I time-out WSAAsyncGetHostByName():

[ Note: code is from X.CPP, taken out of context.
X.CPP is in “ www.Cotse.NET/users/jeffrelf/Games.ZIP ” ]

#include <Winsock2.H>

#define Tics ( QueryPerformanceCounter( ( DubInt * ) & _Tics ), _Tics )
#define Secs ( _Secs = Tics / Secnd_Dub )

typedef wchar_t * LnP ;

__int64 _Tics, Secnd ; double _Secs, Secnd_Dub, Due, Started ;
.........
QueryPerformanceFrequency( ( DubInt * ) & Secnd );
Secnd_Dub = Secnd ;
.........
#define Patience( Seconds ) ( Due = Secs + Seconds, Started = _Secs )

int Getting( int TheGirl ) { blah blah blah ..... handle events.

enum { No_Protocol, Modem, SNTP, POP3, IMAP, SMTP_AUTH, NNTP };
LnP Protocol_Nam []
= { L"No_Protocol", L"Modem", L"SNTP", L"POP3"
, L"IMAP", L"SMTP_AUTH", L"NNTP " };
struct ServT { LnP Nick ; int Protocol ;
LnP Name, User, Pass ; int Port ; ulong IP ; };

typedef ServT * SrP ;

SrP Serv ; LnP SrvNam ;

struct sockaddr_in Host_IP ;

int Service () { int rv ;

if ( ! WinSock ) { WSADATA X;
WinSock = WSAStartup( 0x0202, & X ) >= 0 ;
if ( ! WinSock ) { Sh ( L"No Winsock 2.2" ); return 0 ; } };

Port = Serv->Port ; Protocol = Serv->Protocol ; SrvNam = Serv->Name ;
if ( ! Serv->IP ) { // if ( Protocol == IMAP )

char _SrvNam [ 200 ]; wcstombs( _SrvNam, SrvNam, 200 );
HANDLE DNS ; char Buff_DNS [ MAXGETHOSTSTRUCT ]; Patience( 10 );

DNS = WSAAsyncGetHostByName (
Win, WM_USER + 1, _SrvNam, Buff_DNS, sizeof Buff_DNS );

while ( Secs < Due && ! Getting ( WM_USER + 1 ) );
if ( WM != WM_USER + 1 || P_C2 [ 1 ] ) {

int rv = P_C2 [ 1 ] - WSABASEERR ;
Sh (
L"Didn't get an IP address for: “ %S ”. WsaBaseErr + %d"
, _SrvNam, rv );
return 0 ; }

Serv->IP = * ( ulong * )
* ( ( hostent * ) Buff_DNS ) -> h_addr_list ; }

Host_IP.sin_addr.S_un.S_addr = Serv->IP ;
Host_IP.sin_family = AF_INET ;
Host_IP.sin_port = htons( Port );

if ( Connected >= 0 ) closesocket( Connected );

Connected = socket(
AF_INET, Protocol == SNTP ? SOCK_DGRAM : SOCK_STREAM, 0 );

WSAAsyncSelect( Connected, Win, WM_USER + 2
, FD_CONNECT | FD_READ | FD_WRITE );

if ( Protocol == IMAP || Protocol == POP3
|| Protocol == SMTP_AUTH || Protocol == NNTP ) {

rv = connect (
Connected, ( struct sockaddr * ) & Host_IP
, sizeof Host_IP );

if ( rv && WSAGetLastError() != WSAEWOULDBLOCK )
closesocket( Connected ), Connected = -1 ;
else if ( Protocol != SNTP ) { Patience( 9 );

while (
Secs < Due
&& ! ( Getting ( WM_USER + 2 ) && * P_C2 == FD_CONNECT ) );

if ( WM != WM_USER + 2 || P_C2 [ 1 ] ) { rv = WSAGetLastError();
closesocket( Connected ), Connected = -1 ;

Sh ( L"FD_CONNECT to %s:%d, WinSock_Error_Code: %d."
, SrvNam, Port, rv ); return 0 ; } } }

if ( Connected < 0 ) { rv = WSAGetLastError();
Sh ( L"... No Socket, WinSock_Error_Code: %d.", rv ); return 0 ; }

if ( Protocol == SNTP ) return 1 ;
if ( Ask ( aLine, 0, 0 ) ) { Close; return 0 ; }
// if ( Protocol == IMAP ) *Ln.PP

if ( Protocol == POP3
&& ( Ask( aLine, 0, L"User %s", Serv->User )
|| Ask( aLine, 0, L"Pass %s", Serv->Pass ) ) ) {
Close; return 0 ; }

rv = Protocol == NNTP && Serv->Pass
&& ( Ask ( aLine, 0, L"AuthInfo User %s", Serv->User )
|| Ask ( aLine, 0, L"AuthInfo Pass %s", Serv->Pass ) );

return ! rv ; }

.



Relevant Pages

  • Writing a module, Segmentation fault
    ... For the access to IGT+, I am writing a Module in Perl. ... banking::igtplus - Perl extension for blah blah blah ... int igt_ack( ... dXSARGS; ...
    (comp.lang.perl.modules)
  • Diffing the strings: " FooBar " vs " BarFoo ".
    ... Reporting this Swapped_Text is complicated because: ... I'm insisting, over and over again, that she keep ice on it, ... inline int Apple_Apple_Eq( ... int Eq_Diff(LnP D, LnP L, LnP R) { ...
    (sci.physics)
  • Re: strange compiler message
    ... >> int main ... strcpy(blah, " blah blah "); ... When I use the wrong signature the compiler issues the following error: ... All of this because C++ introduces the concept of calling a constructor ...
    (comp.lang.cpp)
  • Re: [Full-disclosure] 0day LINUX 0day LATEST
    ... On 28 Jan 2008, at 10:55, Andrew Farmer wrote: ... <blah blah blah> ... int geteuid() ... University College London ...
    (Full-Disclosure)
  • 7 knots is 8 MPH... just add one seventh more.
    ... It takes a fool like me to write: ... a pair of matching strings merely have swapped positions. ... inline int Apple_Apple_Eq( ... int Eq_Diff(LnP D, LnP L, LnP R) { ...
    (sci.physics)