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 30*cdf0e10cSrcweir #ifndef _SOCKETHELPER_HXX_ 31*cdf0e10cSrcweir #define _SOCKETHELPER_HXX_ 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir //------------------------------------------------------------------------ 34*cdf0e10cSrcweir //------------------------------------------------------------------------ 35*cdf0e10cSrcweir #include <sal/types.h> 36*cdf0e10cSrcweir #include <rtl/textenc.h> 37*cdf0e10cSrcweir #include <rtl/ustring.hxx> 38*cdf0e10cSrcweir #include <rtl/ustring.h> 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir #ifndef _OSL_SOCLET_HXX_ 41*cdf0e10cSrcweir #include <osl/socket.hxx> 42*cdf0e10cSrcweir #endif 43*cdf0e10cSrcweir #include <osl/socket.h> 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir #ifndef _OSL_THREAD_HXX 46*cdf0e10cSrcweir #include <osl/thread.hxx> 47*cdf0e10cSrcweir #endif 48*cdf0e10cSrcweir 49*cdf0e10cSrcweir #ifndef _OSL_FILE_HXX 50*cdf0e10cSrcweir #include <osl/file.hxx> 51*cdf0e10cSrcweir #endif 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir #ifndef _OSL_MUTEX_HXX 54*cdf0e10cSrcweir #include <osl/mutex.hxx> 55*cdf0e10cSrcweir #endif 56*cdf0e10cSrcweir #include <osl/time.h> 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir #ifdef __cplusplus 59*cdf0e10cSrcweir extern "C" 60*cdf0e10cSrcweir { 61*cdf0e10cSrcweir #endif 62*cdf0e10cSrcweir 63*cdf0e10cSrcweir //------------------------------------------------------------------------ 64*cdf0e10cSrcweir // OS dependent declaration and includes 65*cdf0e10cSrcweir //------------------------------------------------------------------------ 66*cdf0e10cSrcweir #if ( defined UNX ) || ( defined OS2 ) //Unix 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir #include <unistd.h> 69*cdf0e10cSrcweir #include <limits.h> 70*cdf0e10cSrcweir #include <string.h> 71*cdf0e10cSrcweir #include <math.h> 72*cdf0e10cSrcweir #include <errno.h> 73*cdf0e10cSrcweir #include <fcntl.h> 74*cdf0e10cSrcweir #include <sys/stat.h> 75*cdf0e10cSrcweir #include <sys/statfs.h> 76*cdf0e10cSrcweir #include <sys/statvfs.h> 77*cdf0e10cSrcweir #include <sys/types.h> 78*cdf0e10cSrcweir #include <sys/socket.h> 79*cdf0e10cSrcweir #include <netdb.h> 80*cdf0e10cSrcweir #include <netinet/in.h> 81*cdf0e10cSrcweir #include <arpa/inet.h> 82*cdf0e10cSrcweir #include <sys/wait.h> 83*cdf0e10cSrcweir #endif 84*cdf0e10cSrcweir 85*cdf0e10cSrcweir #ifndef _OSL_SOCKET_CONST_H_ 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir #if ( defined WNT ) // Windows 88*cdf0e10cSrcweir #include <tools/prewin.h> 89*cdf0e10cSrcweir // #include <windows.h> 90*cdf0e10cSrcweir #include <winsock.h> 91*cdf0e10cSrcweir #include <string.h> 92*cdf0e10cSrcweir #include <tools/postwin.h> 93*cdf0e10cSrcweir #endif 94*cdf0e10cSrcweir 95*cdf0e10cSrcweir #endif 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir //------------------------------------------------------------------------ 98*cdf0e10cSrcweir //------------------------------------------------------------------------ 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir #ifdef __cplusplus 101*cdf0e10cSrcweir } 102*cdf0e10cSrcweir #endif 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir /** compare two OUString. 105*cdf0e10cSrcweir */ 106*cdf0e10cSrcweir sal_Bool compareUString( const ::rtl::OUString & ustr1, const ::rtl::OUString & ustr2 ); 107*cdf0e10cSrcweir /** compare a OUString and an ASCII string. 108*cdf0e10cSrcweir */ 109*cdf0e10cSrcweir sal_Bool compareUString( const ::rtl::OUString & ustr, const sal_Char *astr ); 110*cdf0e10cSrcweir /** compare two socket address. 111*cdf0e10cSrcweir */ 112*cdf0e10cSrcweir sal_Bool compareSocketAddr( const ::osl::SocketAddr & addr1 , const ::osl::SocketAddr & addr2 ); 113*cdf0e10cSrcweir //char * oustring2char( const ::rtl::OUString & str ); 114*cdf0e10cSrcweir /** print a UNI_CODE String. And also print some comments of the string. 115*cdf0e10cSrcweir */ 116*cdf0e10cSrcweir void printUString( const ::rtl::OUString & str, const char * msg = "" ); 117*cdf0e10cSrcweir /** get the local host name. 118*cdf0e10cSrcweir mindy: gethostbyname( "localhost" ), on Linux, it returns the hostname in /etc/hosts + domain name, 119*cdf0e10cSrcweir if no entry in /etc/hosts, it returns "localhost" + domain name 120*cdf0e10cSrcweir */ 121*cdf0e10cSrcweir ::rtl::OUString getHost( void ); 122*cdf0e10cSrcweir /** get the full host name of the current processor, such as "aegean.prc.sun.com" --mindyliu 123*cdf0e10cSrcweir */ 124*cdf0e10cSrcweir ::rtl::OUString getThisHostname( void ); 125*cdf0e10cSrcweir /** get IP by name, search /etc/hosts first, then search from dns, fail return OUString("") 126*cdf0e10cSrcweir */ 127*cdf0e10cSrcweir ::rtl::OUString getIPbyName( rtl::OString const& str_name ); 128*cdf0e10cSrcweir /** get local ethernet IP 129*cdf0e10cSrcweir */ 130*cdf0e10cSrcweir ::rtl::OUString getLocalIP( ); 131*cdf0e10cSrcweir /** construct error message 132*cdf0e10cSrcweir */ 133*cdf0e10cSrcweir ::rtl::OUString outputError( const ::rtl::OUString & returnVal, const ::rtl::OUString & rightVal, const sal_Char * msg = ""); 134*cdf0e10cSrcweir void thread_sleep( sal_Int32 _nSec ); 135*cdf0e10cSrcweir /** print Boolean value. 136*cdf0e10cSrcweir */ 137*cdf0e10cSrcweir void printBool( sal_Bool bOk ); 138*cdf0e10cSrcweir /** print content of a ByteSequence. 139*cdf0e10cSrcweir */ 140*cdf0e10cSrcweir void printByteSequence_IP( const ::rtl::ByteSequence & bsByteSeq, sal_Int32 nLen ); 141*cdf0e10cSrcweir /** convert an IP which is stored as a UString format to a ByteSequence array for later use. 142*cdf0e10cSrcweir */ 143*cdf0e10cSrcweir ::rtl::ByteSequence UStringIPToByteSequence( ::rtl::OUString aUStr ); 144*cdf0e10cSrcweir /** print a socket result name. 145*cdf0e10cSrcweir */ 146*cdf0e10cSrcweir void printSocketResult( oslSocketResult eResult ); 147*cdf0e10cSrcweir /** if 4 parts of an IP addr are equal to specified values 148*cdf0e10cSrcweir */ 149*cdf0e10cSrcweir sal_Bool ifIpv4is( const ::rtl::ByteSequence Ipaddr, sal_Int8 seq1, sal_Int8 seq2, sal_Int8 seq3, sal_Int8 seq4 ); 150*cdf0e10cSrcweir /** if the IP or hostname is availble( alive ) 151*cdf0e10cSrcweir */ 152*cdf0e10cSrcweir //sal_Bool ifAvailable( const char * stringAddrOrHostName ); 153*cdf0e10cSrcweir sal_Bool ifAvailable( rtl::OUString const& strAddrOrHostName ); 154*cdf0e10cSrcweir /* 155*cdf0e10cSrcweir class ClientSocketThread : public Thread 156*cdf0e10cSrcweir class ServerSocketThread : public Thread 157*cdf0e10cSrcweir class ValueCheckProvider 158*cdf0e10cSrcweir class ClientReadSocketThread : public Thread 159*cdf0e10cSrcweir class ServerWriteSocketThread : public Thread 160*cdf0e10cSrcweir class AcceptorThread : public Thread 161*cdf0e10cSrcweir class CloseSocketThread : public Thread 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir */ 164*cdf0e10cSrcweir 165*cdf0e10cSrcweir #endif 166