1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 //------------------------------------------------------------------------ 28 //------------------------------------------------------------------------ 29 30 #ifndef _SOCKETHELPER_HXX_ 31 #define _SOCKETHELPER_HXX_ 32 33 //------------------------------------------------------------------------ 34 //------------------------------------------------------------------------ 35 #include <sal/types.h> 36 #include <rtl/textenc.h> 37 #include <rtl/ustring.hxx> 38 #include <rtl/ustring.h> 39 40 #ifndef _OSL_SOCLET_HXX_ 41 #include <osl/socket.hxx> 42 #endif 43 #include <osl/socket.h> 44 45 #ifndef _OSL_THREAD_HXX 46 #include <osl/thread.hxx> 47 #endif 48 49 #ifndef _OSL_FILE_HXX 50 #include <osl/file.hxx> 51 #endif 52 53 #ifndef _OSL_MUTEX_HXX 54 #include <osl/mutex.hxx> 55 #endif 56 #include <osl/time.h> 57 58 #ifdef __cplusplus 59 extern "C" 60 { 61 #endif 62 63 //------------------------------------------------------------------------ 64 // OS dependent declaration and includes 65 //------------------------------------------------------------------------ 66 #if ( defined UNX ) || ( defined OS2 ) //Unix 67 68 #include <unistd.h> 69 #include <limits.h> 70 #include <string.h> 71 #include <math.h> 72 #include <errno.h> 73 #include <fcntl.h> 74 #include <sys/stat.h> 75 #include <sys/statfs.h> 76 #include <sys/statvfs.h> 77 #include <sys/types.h> 78 #include <sys/socket.h> 79 #include <netdb.h> 80 #include <netinet/in.h> 81 #include <arpa/inet.h> 82 #include <sys/wait.h> 83 #endif 84 85 #ifndef _OSL_SOCKET_CONST_H_ 86 87 #if ( defined WNT ) // Windows 88 #include <tools/prewin.h> 89 // #include <windows.h> 90 #include <winsock.h> 91 #include <string.h> 92 #include <tools/postwin.h> 93 #endif 94 95 #endif 96 97 //------------------------------------------------------------------------ 98 //------------------------------------------------------------------------ 99 100 #ifdef __cplusplus 101 } 102 #endif 103 104 /** compare two OUString. 105 */ 106 sal_Bool compareUString( const ::rtl::OUString & ustr1, const ::rtl::OUString & ustr2 ); 107 /** compare a OUString and an ASCII string. 108 */ 109 sal_Bool compareUString( const ::rtl::OUString & ustr, const sal_Char *astr ); 110 /** compare two socket address. 111 */ 112 sal_Bool compareSocketAddr( const ::osl::SocketAddr & addr1 , const ::osl::SocketAddr & addr2 ); 113 //char * oustring2char( const ::rtl::OUString & str ); 114 /** print a UNI_CODE String. And also print some comments of the string. 115 */ 116 void printUString( const ::rtl::OUString & str, const char * msg = "" ); 117 /** get the local host name. 118 mindy: gethostbyname( "localhost" ), on Linux, it returns the hostname in /etc/hosts + domain name, 119 if no entry in /etc/hosts, it returns "localhost" + domain name 120 */ 121 ::rtl::OUString getHost( void ); 122 /** get the full host name of the current processor, such as "aegean.prc.sun.com" --mindyliu 123 */ 124 ::rtl::OUString getThisHostname( void ); 125 /** get IP by name, search /etc/hosts first, then search from dns, fail return OUString("") 126 */ 127 ::rtl::OUString getIPbyName( rtl::OString const& str_name ); 128 /** get local ethernet IP 129 */ 130 ::rtl::OUString getLocalIP( ); 131 /** construct error message 132 */ 133 ::rtl::OUString outputError( const ::rtl::OUString & returnVal, const ::rtl::OUString & rightVal, const sal_Char * msg = ""); 134 void thread_sleep( sal_Int32 _nSec ); 135 /** print Boolean value. 136 */ 137 void printBool( sal_Bool bOk ); 138 /** print content of a ByteSequence. 139 */ 140 void printByteSequence_IP( const ::rtl::ByteSequence & bsByteSeq, sal_Int32 nLen ); 141 /** convert an IP which is stored as a UString format to a ByteSequence array for later use. 142 */ 143 ::rtl::ByteSequence UStringIPToByteSequence( ::rtl::OUString aUStr ); 144 /** print a socket result name. 145 */ 146 void printSocketResult( oslSocketResult eResult ); 147 /** if 4 parts of an IP addr are equal to specified values 148 */ 149 sal_Bool ifIpv4is( const ::rtl::ByteSequence Ipaddr, sal_Int8 seq1, sal_Int8 seq2, sal_Int8 seq3, sal_Int8 seq4 ); 150 /** if the IP or hostname is availble( alive ) 151 */ 152 //sal_Bool ifAvailable( const char * stringAddrOrHostName ); 153 sal_Bool ifAvailable( rtl::OUString const& strAddrOrHostName ); 154 /* 155 class ClientSocketThread : public Thread 156 class ServerSocketThread : public Thread 157 class ValueCheckProvider 158 class ClientReadSocketThread : public Thread 159 class ServerWriteSocketThread : public Thread 160 class AcceptorThread : public Thread 161 class CloseSocketThread : public Thread 162 163 */ 164 165 #endif 166