1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir 29*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 30*cdf0e10cSrcweir #include "precompiled_sal.hxx" 31*cdf0e10cSrcweir #include "sockethelper.hxx" 32*cdf0e10cSrcweir #include <testshl/simpleheader.hxx> 33*cdf0e10cSrcweir 34*cdf0e10cSrcweir //------------------------------------------------------------------------ 35*cdf0e10cSrcweir // Ip version definition 36*cdf0e10cSrcweir //------------------------------------------------------------------------ 37*cdf0e10cSrcweir #define IP_VER 4 /// currently only IPv4 is considered. 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir //------------------------------------------------------------------------ 40*cdf0e10cSrcweir // helper functions 41*cdf0e10cSrcweir //------------------------------------------------------------------------ 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir /** compare two OUString. 44*cdf0e10cSrcweir */ 45*cdf0e10cSrcweir sal_Bool compareUString( const ::rtl::OUString & ustr1, const ::rtl::OUString & ustr2 ) 46*cdf0e10cSrcweir { 47*cdf0e10cSrcweir sal_Bool bOk = ustr1.equalsIgnoreAsciiCase( ustr2 ); 48*cdf0e10cSrcweir 49*cdf0e10cSrcweir return bOk; 50*cdf0e10cSrcweir } 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir /** compare a OUString and an ASCII string. 53*cdf0e10cSrcweir */ 54*cdf0e10cSrcweir sal_Bool compareUString( const ::rtl::OUString & ustr, const sal_Char *astr ) 55*cdf0e10cSrcweir { 56*cdf0e10cSrcweir ::rtl::OUString ustr2 = rtl::OUString::createFromAscii( astr ); 57*cdf0e10cSrcweir sal_Bool bOk = ustr.equalsIgnoreAsciiCase( ustr2 ); 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir return bOk; 60*cdf0e10cSrcweir } 61*cdf0e10cSrcweir 62*cdf0e10cSrcweir /** compare two socket address. 63*cdf0e10cSrcweir */ 64*cdf0e10cSrcweir sal_Bool compareSocketAddr( const ::osl::SocketAddr & addr1 , const ::osl::SocketAddr & addr2 ) 65*cdf0e10cSrcweir { 66*cdf0e10cSrcweir return ( ( sal_True == compareUString( addr1.getHostname( 0 ), addr2.getHostname( 0 ) ) ) && ( addr2.getPort( ) == addr2.getPort( ) ) ); 67*cdf0e10cSrcweir } 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir /*char * oustring2char( const ::rtl::OUString & str ) 70*cdf0e10cSrcweir { 71*cdf0e10cSrcweir rtl::OString aString; 72*cdf0e10cSrcweir aString = ::rtl::OUStringToOString( str, RTL_TEXTENCODING_ASCII_US ); 73*cdf0e10cSrcweir t_print("oustring2char %s\n", aString.getStr( ) ); 74*cdf0e10cSrcweir sal_Char * sStr = aString.getStr( ); 75*cdf0e10cSrcweir return (char *)sStr; 76*cdf0e10cSrcweir }*/ 77*cdf0e10cSrcweir 78*cdf0e10cSrcweir /** print a UNI_CODE String. And also print some comments of the string. 79*cdf0e10cSrcweir */ 80*cdf0e10cSrcweir void printUString( const ::rtl::OUString & str, const char* msg) 81*cdf0e10cSrcweir { 82*cdf0e10cSrcweir t_print("#%s #printUString_u# ", msg ); 83*cdf0e10cSrcweir rtl::OString aString; 84*cdf0e10cSrcweir aString = ::rtl::OUStringToOString( str, RTL_TEXTENCODING_ASCII_US ); 85*cdf0e10cSrcweir //char * sStr = aString.getStr( ); 86*cdf0e10cSrcweir t_print("%s\n", aString.getStr( ) ); 87*cdf0e10cSrcweir } 88*cdf0e10cSrcweir 89*cdf0e10cSrcweir /** get the local host name. 90*cdf0e10cSrcweir mindy: gethostbyname( "localhost" ), on Linux, it returns the hostname in /etc/hosts + domain name, 91*cdf0e10cSrcweir if no entry in /etc/hosts, it returns "localhost" + domain name 92*cdf0e10cSrcweir */ 93*cdf0e10cSrcweir ::rtl::OUString getHost( void ) 94*cdf0e10cSrcweir { 95*cdf0e10cSrcweir struct hostent *hptr; 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir hptr = gethostbyname( "localhost" ); 98*cdf0e10cSrcweir OSL_ENSURE( hptr != NULL, "#In getHostname function, error on gethostbyname()" ); 99*cdf0e10cSrcweir ::rtl::OUString aUString = ::rtl::OUString::createFromAscii( (const sal_Char *) hptr->h_name ); 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir return aUString; 102*cdf0e10cSrcweir } 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir /** get the full host name of the current processor, such as "aegean.prc.sun.com" --mindyliu 105*cdf0e10cSrcweir */ 106*cdf0e10cSrcweir ::rtl::OUString getThisHostname( void ) 107*cdf0e10cSrcweir { 108*cdf0e10cSrcweir ::rtl::OUString aUString; 109*cdf0e10cSrcweir #ifdef WNT 110*cdf0e10cSrcweir struct hostent *hptr; 111*cdf0e10cSrcweir hptr = gethostbyname( "localhost" ); 112*cdf0e10cSrcweir OSL_ENSURE( hptr != NULL, "#In getHostname function, error on gethostbyname()" ); 113*cdf0e10cSrcweir rtl::OString sHostname(hptr->h_name); 114*cdf0e10cSrcweir aUString = ::rtl::OStringToOUString(sHostname, RTL_TEXTENCODING_ASCII_US); 115*cdf0e10cSrcweir #else 116*cdf0e10cSrcweir char hostname[255]; 117*cdf0e10cSrcweir if (gethostname(hostname, 255) != 0) { 118*cdf0e10cSrcweir OSL_ENSURE( false, "#Error: gethostname failed." ); 119*cdf0e10cSrcweir } 120*cdf0e10cSrcweir 121*cdf0e10cSrcweir struct hostent *hptr; 122*cdf0e10cSrcweir //first search /ets/hosts, then search from dns 123*cdf0e10cSrcweir hptr = gethostbyname( hostname); 124*cdf0e10cSrcweir if ( hptr != NULL ) 125*cdf0e10cSrcweir { 126*cdf0e10cSrcweir strcpy( hostname, hptr->h_name ); 127*cdf0e10cSrcweir } 128*cdf0e10cSrcweir 129*cdf0e10cSrcweir t_print("hostname is %s \n", hostname ); 130*cdf0e10cSrcweir rtl::OString sHostname( hostname ); 131*cdf0e10cSrcweir aUString = ::rtl::OStringToOUString( sHostname, RTL_TEXTENCODING_ASCII_US ); 132*cdf0e10cSrcweir aUString.getLength(); 133*cdf0e10cSrcweir #endif 134*cdf0e10cSrcweir return aUString; 135*cdf0e10cSrcweir } 136*cdf0e10cSrcweir 137*cdf0e10cSrcweir /** get IP by name, search /etc/hosts first, then search from dns, fail return OUString("") 138*cdf0e10cSrcweir */ 139*cdf0e10cSrcweir ::rtl::OUString getIPbyName( rtl::OString const& str_name ) 140*cdf0e10cSrcweir { 141*cdf0e10cSrcweir ::rtl::OUString aUString; 142*cdf0e10cSrcweir struct hostent *hptr; 143*cdf0e10cSrcweir //first search /ets/hosts, then search from dns 144*cdf0e10cSrcweir hptr = gethostbyname( str_name.getStr()); 145*cdf0e10cSrcweir if ( hptr != NULL ) 146*cdf0e10cSrcweir { 147*cdf0e10cSrcweir struct in_addr ** addrptr; 148*cdf0e10cSrcweir addrptr = (struct in_addr **) hptr->h_addr_list ; 149*cdf0e10cSrcweir //if there are more than one IPs on the same machine, we select one 150*cdf0e10cSrcweir for (; *addrptr; addrptr++) 151*cdf0e10cSrcweir { 152*cdf0e10cSrcweir t_print("#Local IP Address: %s\n", inet_ntoa(**addrptr)); 153*cdf0e10cSrcweir aUString = ::rtl::OUString::createFromAscii( (sal_Char *) (inet_ntoa(**addrptr)) ); 154*cdf0e10cSrcweir } 155*cdf0e10cSrcweir } 156*cdf0e10cSrcweir return aUString; 157*cdf0e10cSrcweir } 158*cdf0e10cSrcweir 159*cdf0e10cSrcweir /** get local ethernet IP 160*cdf0e10cSrcweir */ 161*cdf0e10cSrcweir ::rtl::OUString getLocalIP( ) 162*cdf0e10cSrcweir { 163*cdf0e10cSrcweir char hostname[255]; 164*cdf0e10cSrcweir gethostname(hostname, 255); 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir return getIPbyName( hostname ); 167*cdf0e10cSrcweir } 168*cdf0e10cSrcweir 169*cdf0e10cSrcweir /** construct error message 170*cdf0e10cSrcweir */ 171*cdf0e10cSrcweir ::rtl::OUString outputError( const ::rtl::OUString & returnVal, const ::rtl::OUString & rightVal, const sal_Char * msg ) 172*cdf0e10cSrcweir { 173*cdf0e10cSrcweir ::rtl::OUString aUString; 174*cdf0e10cSrcweir if ( returnVal.equals( rightVal ) ) 175*cdf0e10cSrcweir return aUString; 176*cdf0e10cSrcweir aUString += ::rtl::OUString::createFromAscii(msg); 177*cdf0e10cSrcweir aUString += ::rtl::OUString::createFromAscii(": the returned value is '"); 178*cdf0e10cSrcweir aUString += returnVal; 179*cdf0e10cSrcweir aUString += ::rtl::OUString::createFromAscii("', but the value should be '"); 180*cdf0e10cSrcweir aUString += rightVal; 181*cdf0e10cSrcweir aUString += ::rtl::OUString::createFromAscii("'."); 182*cdf0e10cSrcweir return aUString; 183*cdf0e10cSrcweir } 184*cdf0e10cSrcweir 185*cdf0e10cSrcweir /** wait _nSec seconds. 186*cdf0e10cSrcweir */ 187*cdf0e10cSrcweir void thread_sleep( sal_Int32 _nSec ) 188*cdf0e10cSrcweir { 189*cdf0e10cSrcweir /// print statement in thread process must use fflush() to force display. 190*cdf0e10cSrcweir // printf("wait %d seconds. ", _nSec ); 191*cdf0e10cSrcweir // fflush(stdout); 192*cdf0e10cSrcweir 193*cdf0e10cSrcweir #ifdef WNT //Windows 194*cdf0e10cSrcweir Sleep( _nSec * 100 ); 195*cdf0e10cSrcweir #endif 196*cdf0e10cSrcweir #if ( defined UNX ) || ( defined OS2 ) //Unix 197*cdf0e10cSrcweir usleep(_nSec * 100000); 198*cdf0e10cSrcweir #endif 199*cdf0e10cSrcweir // t_print("# done\n" ); 200*cdf0e10cSrcweir } 201*cdf0e10cSrcweir 202*cdf0e10cSrcweir /** print Boolean value. 203*cdf0e10cSrcweir */ 204*cdf0e10cSrcweir void printBool( sal_Bool bOk ) 205*cdf0e10cSrcweir { 206*cdf0e10cSrcweir t_print("printBool " ); 207*cdf0e10cSrcweir ( sal_True == bOk ) ? t_print("YES!" ): t_print("NO!"); 208*cdf0e10cSrcweir t_print("\n"); 209*cdf0e10cSrcweir } 210*cdf0e10cSrcweir 211*cdf0e10cSrcweir /** print content of a ByteSequence. 212*cdf0e10cSrcweir */ 213*cdf0e10cSrcweir void printByteSequence_IP( const ::rtl::ByteSequence & bsByteSeq, sal_Int32 nLen ) 214*cdf0e10cSrcweir { 215*cdf0e10cSrcweir t_print("ByteSequence is: " ); 216*cdf0e10cSrcweir for ( int i = 0; i < nLen; i++ ){ 217*cdf0e10cSrcweir if ( bsByteSeq[i] < 0 ) 218*cdf0e10cSrcweir t_print("%d ", 256 + bsByteSeq[i] ); 219*cdf0e10cSrcweir else 220*cdf0e10cSrcweir t_print("%d ", bsByteSeq[i] ); 221*cdf0e10cSrcweir } 222*cdf0e10cSrcweir t_print(" .\n" ); 223*cdf0e10cSrcweir } 224*cdf0e10cSrcweir 225*cdf0e10cSrcweir /** convert an IP which is stored as a UString format to a ByteSequence array for later use. 226*cdf0e10cSrcweir */ 227*cdf0e10cSrcweir ::rtl::ByteSequence UStringIPToByteSequence( ::rtl::OUString aUStr ) 228*cdf0e10cSrcweir { 229*cdf0e10cSrcweir 230*cdf0e10cSrcweir rtl::OString aString = ::rtl::OUStringToOString( aUStr, RTL_TEXTENCODING_ASCII_US ); 231*cdf0e10cSrcweir const sal_Char *pChar = aString.getStr( ) ; 232*cdf0e10cSrcweir sal_Char tmpBuffer[4]; 233*cdf0e10cSrcweir sal_Int32 nCharCounter = 0; 234*cdf0e10cSrcweir ::rtl::ByteSequence bsByteSequence( IP_VER ); 235*cdf0e10cSrcweir sal_Int32 nByteSeqCounter = 0; 236*cdf0e10cSrcweir 237*cdf0e10cSrcweir for ( int i = 0; i < aString.getLength( ) + 1 ; i++ ) 238*cdf0e10cSrcweir { 239*cdf0e10cSrcweir if ( ( *pChar != '.' ) && ( i !=aString.getLength( ) ) ) 240*cdf0e10cSrcweir tmpBuffer[nCharCounter++] = *pChar; 241*cdf0e10cSrcweir else 242*cdf0e10cSrcweir { 243*cdf0e10cSrcweir tmpBuffer[nCharCounter] = '\0'; 244*cdf0e10cSrcweir nCharCounter = 0; 245*cdf0e10cSrcweir bsByteSequence[nByteSeqCounter++] = static_cast<sal_Int8>(atoi( tmpBuffer )); 246*cdf0e10cSrcweir } 247*cdf0e10cSrcweir pChar++; 248*cdf0e10cSrcweir } 249*cdf0e10cSrcweir return bsByteSequence; 250*cdf0e10cSrcweir } 251*cdf0e10cSrcweir 252*cdf0e10cSrcweir /** print a socket result name. 253*cdf0e10cSrcweir */ 254*cdf0e10cSrcweir void printSocketResult( oslSocketResult eResult ) 255*cdf0e10cSrcweir { 256*cdf0e10cSrcweir t_print("printSocketResult: " ); 257*cdf0e10cSrcweir if (!eResult) 258*cdf0e10cSrcweir switch (eResult) 259*cdf0e10cSrcweir { 260*cdf0e10cSrcweir case osl_Socket_Ok: 261*cdf0e10cSrcweir t_print("client connected\n"); 262*cdf0e10cSrcweir break; 263*cdf0e10cSrcweir case osl_Socket_Error: 264*cdf0e10cSrcweir t_print("got an error ... exiting\r\n\r\n" ); 265*cdf0e10cSrcweir break; 266*cdf0e10cSrcweir case osl_Socket_TimedOut: 267*cdf0e10cSrcweir t_print("timeout\n"); 268*cdf0e10cSrcweir break; 269*cdf0e10cSrcweir case osl_Socket_Interrupted: 270*cdf0e10cSrcweir t_print("interrupted\n"); 271*cdf0e10cSrcweir break; 272*cdf0e10cSrcweir case osl_Socket_InProgress: 273*cdf0e10cSrcweir t_print("in progress\n"); 274*cdf0e10cSrcweir break; 275*cdf0e10cSrcweir default: 276*cdf0e10cSrcweir t_print("unknown result\n"); 277*cdf0e10cSrcweir break; 278*cdf0e10cSrcweir } 279*cdf0e10cSrcweir } 280*cdf0e10cSrcweir 281*cdf0e10cSrcweir /** if 4 parts of an IP addr are equal to specified values 282*cdf0e10cSrcweir */ 283*cdf0e10cSrcweir sal_Bool ifIpv4is( const ::rtl::ByteSequence Ipaddr, sal_Int8 seq1, sal_Int8 seq2, sal_Int8 seq3, sal_Int8 seq4 ) 284*cdf0e10cSrcweir { 285*cdf0e10cSrcweir if ( ( Ipaddr[0] == seq1 ) && ( Ipaddr[1] == seq2 ) && ( Ipaddr[2] == seq3 ) && ( Ipaddr[3] == seq4 ) ) 286*cdf0e10cSrcweir return sal_True; 287*cdf0e10cSrcweir return sal_False; 288*cdf0e10cSrcweir } 289*cdf0e10cSrcweir 290*cdf0e10cSrcweir /** if the IP or hostname is availble( alive ) 291*cdf0e10cSrcweir */ 292*cdf0e10cSrcweir /*sal_Bool ifAvailable( const char * stringAddrOrHostName ) 293*cdf0e10cSrcweir { 294*cdf0e10cSrcweir sal_Bool result; 295*cdf0e10cSrcweir int p[2]; 296*cdf0e10cSrcweir sal_Char buffer[2000]; 297*cdf0e10cSrcweir char stringhost[20]; 298*cdf0e10cSrcweir strcpy(stringhost, stringAddrOrHostName ); 299*cdf0e10cSrcweir 300*cdf0e10cSrcweir result = sal_False; 301*cdf0e10cSrcweir if (pipe (p) == 0) 302*cdf0e10cSrcweir { 303*cdf0e10cSrcweir pid_t pid; 304*cdf0e10cSrcweir int nStatus; 305*cdf0e10cSrcweir pid = fork(); 306*cdf0e10cSrcweir if (pid == 0) 307*cdf0e10cSrcweir { 308*cdf0e10cSrcweir #if ( defined LINUX ) 309*cdf0e10cSrcweir char *argv[] = 310*cdf0e10cSrcweir { 311*cdf0e10cSrcweir "/bin/ping", 312*cdf0e10cSrcweir "-c", "3", 313*cdf0e10cSrcweir "-W", "3", 314*cdf0e10cSrcweir stringhost, 315*cdf0e10cSrcweir NULL 316*cdf0e10cSrcweir }; 317*cdf0e10cSrcweir #endif 318*cdf0e10cSrcweir #if ( defined SOLARIS ) 319*cdf0e10cSrcweir char *argv[] = 320*cdf0e10cSrcweir { 321*cdf0e10cSrcweir "/usr/sbin/ping", 322*cdf0e10cSrcweir stringhost, 323*cdf0e10cSrcweir "3", 324*cdf0e10cSrcweir NULL 325*cdf0e10cSrcweir }; 326*cdf0e10cSrcweir #endif 327*cdf0e10cSrcweir close (p[0]); 328*cdf0e10cSrcweir dup2 (p[1], 1); 329*cdf0e10cSrcweir close (p[1]); 330*cdf0e10cSrcweir #if ( defined LINUX ) 331*cdf0e10cSrcweir execv ("/bin/ping", argv); 332*cdf0e10cSrcweir #endif 333*cdf0e10cSrcweir #if ( defined SOLARIS ) 334*cdf0e10cSrcweir execv ("/usr/sbin/ping", argv); 335*cdf0e10cSrcweir #endif 336*cdf0e10cSrcweir // arriving here means exec failed 337*cdf0e10cSrcweir _exit(-1); 338*cdf0e10cSrcweir } 339*cdf0e10cSrcweir else if (pid > 0) 340*cdf0e10cSrcweir { 341*cdf0e10cSrcweir sal_Int32 k = 0, n = 2000; 342*cdf0e10cSrcweir close (p[1]); 343*cdf0e10cSrcweir if ((k = read (p[0], buffer, n - 1)) > 0) 344*cdf0e10cSrcweir { 345*cdf0e10cSrcweir buffer[k] = 0; 346*cdf0e10cSrcweir if (buffer[k - 1] == '\n') 347*cdf0e10cSrcweir buffer[k - 1] = 0; 348*cdf0e10cSrcweir #if ( defined LINUX ) 349*cdf0e10cSrcweir char strOK[] = "bytes from"; 350*cdf0e10cSrcweir #endif 351*cdf0e10cSrcweir #if ( defined SOLARIS ) 352*cdf0e10cSrcweir char strOK[] = "is alive"; 353*cdf0e10cSrcweir #endif 354*cdf0e10cSrcweir if (strstr( buffer, strOK ) != NULL ) 355*cdf0e10cSrcweir result = sal_True; 356*cdf0e10cSrcweir t_print("buffer is %s\n", buffer ); 357*cdf0e10cSrcweir } 358*cdf0e10cSrcweir close (p[0]); 359*cdf0e10cSrcweir waitpid (pid, &nStatus, 0); 360*cdf0e10cSrcweir } 361*cdf0e10cSrcweir else 362*cdf0e10cSrcweir { 363*cdf0e10cSrcweir close (p[0]); 364*cdf0e10cSrcweir close (p[1]); 365*cdf0e10cSrcweir } 366*cdf0e10cSrcweir 367*cdf0e10cSrcweir } 368*cdf0e10cSrcweir return result; 369*cdf0e10cSrcweir }*/ 370*cdf0e10cSrcweir 371*cdf0e10cSrcweir sal_Bool ifAvailable( rtl::OUString const& strAddrOrHostName ) 372*cdf0e10cSrcweir { 373*cdf0e10cSrcweir ::osl::ConnectorSocket aSocket( osl_Socket_FamilyInet, osl_Socket_ProtocolIp, osl_Socket_TypeStream ); 374*cdf0e10cSrcweir ::osl::SocketAddr aSocketAddr( strAddrOrHostName, 7 ); 375*cdf0e10cSrcweir 376*cdf0e10cSrcweir if (! aSocketAddr.is()) 377*cdf0e10cSrcweir { 378*cdf0e10cSrcweir aSocket.close(); 379*cdf0e10cSrcweir return sal_False; 380*cdf0e10cSrcweir } 381*cdf0e10cSrcweir 382*cdf0e10cSrcweir aSocket.setOption( osl_Socket_OptionReuseAddr, 1 ); //sal_True; 383*cdf0e10cSrcweir 384*cdf0e10cSrcweir TimeValue *pTimeout; 385*cdf0e10cSrcweir pTimeout = ( TimeValue* )malloc( sizeof( TimeValue ) ); 386*cdf0e10cSrcweir pTimeout->Seconds = 3; 387*cdf0e10cSrcweir pTimeout->Nanosec = 0; 388*cdf0e10cSrcweir 389*cdf0e10cSrcweir oslSocketResult aResult = aSocket.connect( aSocketAddr, pTimeout ); 390*cdf0e10cSrcweir free( pTimeout ); 391*cdf0e10cSrcweir aSocket.close(); 392*cdf0e10cSrcweir if ( aResult != osl_Socket_Ok ) 393*cdf0e10cSrcweir { 394*cdf0e10cSrcweir t_print("Error: "); 395*cdf0e10cSrcweir printSocketResult(aResult); 396*cdf0e10cSrcweir t_print("\n"); 397*cdf0e10cSrcweir 398*cdf0e10cSrcweir return sal_False; 399*cdf0e10cSrcweir } 400*cdf0e10cSrcweir return sal_True; 401*cdf0e10cSrcweir } 402