1*565d668cSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*565d668cSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*565d668cSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*565d668cSAndrew Rist * distributed with this work for additional information 6*565d668cSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*565d668cSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*565d668cSAndrew Rist * "License"); you may not use this file except in compliance 9*565d668cSAndrew Rist * with the License. You may obtain a copy of the License at 10*565d668cSAndrew Rist * 11*565d668cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*565d668cSAndrew Rist * 13*565d668cSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*565d668cSAndrew Rist * software distributed under the License is distributed on an 15*565d668cSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*565d668cSAndrew Rist * KIND, either express or implied. See the License for the 17*565d668cSAndrew Rist * specific language governing permissions and limitations 18*565d668cSAndrew Rist * under the License. 19*565d668cSAndrew Rist * 20*565d668cSAndrew Rist *************************************************************/ 21*565d668cSAndrew Rist 22*565d668cSAndrew Rist 23cdf0e10cSrcweir //------------------------------------------------------------------------ 24cdf0e10cSrcweir //------------------------------------------------------------------------ 25cdf0e10cSrcweir 26cdf0e10cSrcweir #ifndef _SOCKETHELPER_HXX_ 27cdf0e10cSrcweir #define _SOCKETHELPER_HXX_ 28cdf0e10cSrcweir 29cdf0e10cSrcweir //------------------------------------------------------------------------ 30cdf0e10cSrcweir //------------------------------------------------------------------------ 31cdf0e10cSrcweir #include <sal/types.h> 32cdf0e10cSrcweir #include <rtl/textenc.h> 33cdf0e10cSrcweir #include <rtl/ustring.hxx> 34cdf0e10cSrcweir #include <rtl/ustring.h> 35cdf0e10cSrcweir 36cdf0e10cSrcweir #ifndef _OSL_SOCLET_HXX_ 37cdf0e10cSrcweir #include <osl/socket.hxx> 38cdf0e10cSrcweir #endif 39cdf0e10cSrcweir #include <osl/socket.h> 40cdf0e10cSrcweir 41cdf0e10cSrcweir #ifndef _OSL_THREAD_HXX 42cdf0e10cSrcweir #include <osl/thread.hxx> 43cdf0e10cSrcweir #endif 44cdf0e10cSrcweir 45cdf0e10cSrcweir #ifndef _OSL_FILE_HXX 46cdf0e10cSrcweir #include <osl/file.hxx> 47cdf0e10cSrcweir #endif 48cdf0e10cSrcweir 49cdf0e10cSrcweir #ifndef _OSL_MUTEX_HXX 50cdf0e10cSrcweir #include <osl/mutex.hxx> 51cdf0e10cSrcweir #endif 52cdf0e10cSrcweir #include <osl/time.h> 53cdf0e10cSrcweir 54cdf0e10cSrcweir #ifdef __cplusplus 55cdf0e10cSrcweir extern "C" 56cdf0e10cSrcweir { 57cdf0e10cSrcweir #endif 58cdf0e10cSrcweir 59cdf0e10cSrcweir //------------------------------------------------------------------------ 60cdf0e10cSrcweir // OS dependent declaration and includes 61cdf0e10cSrcweir //------------------------------------------------------------------------ 62cdf0e10cSrcweir #if ( defined UNX ) || ( defined OS2 ) //Unix 63cdf0e10cSrcweir 64cdf0e10cSrcweir #include <unistd.h> 65cdf0e10cSrcweir #include <limits.h> 66cdf0e10cSrcweir #include <string.h> 67cdf0e10cSrcweir #include <math.h> 68cdf0e10cSrcweir #include <errno.h> 69cdf0e10cSrcweir #include <fcntl.h> 70cdf0e10cSrcweir #include <sys/stat.h> 71cdf0e10cSrcweir #include <sys/statfs.h> 72cdf0e10cSrcweir #include <sys/statvfs.h> 73cdf0e10cSrcweir #include <sys/types.h> 74cdf0e10cSrcweir #include <sys/socket.h> 75cdf0e10cSrcweir #include <netdb.h> 76cdf0e10cSrcweir #include <netinet/in.h> 77cdf0e10cSrcweir #include <arpa/inet.h> 78cdf0e10cSrcweir #include <sys/wait.h> 79cdf0e10cSrcweir #endif 80cdf0e10cSrcweir 81cdf0e10cSrcweir #ifndef _OSL_SOCKET_CONST_H_ 82cdf0e10cSrcweir 83cdf0e10cSrcweir #if ( defined WNT ) // Windows 84cdf0e10cSrcweir #include <tools/prewin.h> 85cdf0e10cSrcweir // #include <windows.h> 86cdf0e10cSrcweir #include <winsock.h> 87cdf0e10cSrcweir #include <string.h> 88cdf0e10cSrcweir #include <tools/postwin.h> 89cdf0e10cSrcweir #endif 90cdf0e10cSrcweir 91cdf0e10cSrcweir #endif 92cdf0e10cSrcweir 93cdf0e10cSrcweir //------------------------------------------------------------------------ 94cdf0e10cSrcweir //------------------------------------------------------------------------ 95cdf0e10cSrcweir 96cdf0e10cSrcweir #ifdef __cplusplus 97cdf0e10cSrcweir } 98cdf0e10cSrcweir #endif 99cdf0e10cSrcweir 100cdf0e10cSrcweir /** compare two OUString. 101cdf0e10cSrcweir */ 102cdf0e10cSrcweir sal_Bool compareUString( const ::rtl::OUString & ustr1, const ::rtl::OUString & ustr2 ); 103cdf0e10cSrcweir /** compare a OUString and an ASCII string. 104cdf0e10cSrcweir */ 105cdf0e10cSrcweir sal_Bool compareUString( const ::rtl::OUString & ustr, const sal_Char *astr ); 106cdf0e10cSrcweir /** compare two socket address. 107cdf0e10cSrcweir */ 108cdf0e10cSrcweir sal_Bool compareSocketAddr( const ::osl::SocketAddr & addr1 , const ::osl::SocketAddr & addr2 ); 109cdf0e10cSrcweir //char * oustring2char( const ::rtl::OUString & str ); 110cdf0e10cSrcweir /** print a UNI_CODE String. And also print some comments of the string. 111cdf0e10cSrcweir */ 112cdf0e10cSrcweir void printUString( const ::rtl::OUString & str, const char * msg = "" ); 113cdf0e10cSrcweir /** get the local host name. 114cdf0e10cSrcweir mindy: gethostbyname( "localhost" ), on Linux, it returns the hostname in /etc/hosts + domain name, 115cdf0e10cSrcweir if no entry in /etc/hosts, it returns "localhost" + domain name 116cdf0e10cSrcweir */ 117cdf0e10cSrcweir ::rtl::OUString getHost( void ); 118cdf0e10cSrcweir /** get the full host name of the current processor, such as "aegean.prc.sun.com" --mindyliu 119cdf0e10cSrcweir */ 120cdf0e10cSrcweir ::rtl::OUString getThisHostname( void ); 121cdf0e10cSrcweir /** get IP by name, search /etc/hosts first, then search from dns, fail return OUString("") 122cdf0e10cSrcweir */ 123cdf0e10cSrcweir ::rtl::OUString getIPbyName( rtl::OString const& str_name ); 124cdf0e10cSrcweir /** get local ethernet IP 125cdf0e10cSrcweir */ 126cdf0e10cSrcweir ::rtl::OUString getLocalIP( ); 127cdf0e10cSrcweir /** construct error message 128cdf0e10cSrcweir */ 129cdf0e10cSrcweir ::rtl::OUString outputError( const ::rtl::OUString & returnVal, const ::rtl::OUString & rightVal, const sal_Char * msg = ""); 130cdf0e10cSrcweir void thread_sleep( sal_Int32 _nSec ); 131cdf0e10cSrcweir /** print Boolean value. 132cdf0e10cSrcweir */ 133cdf0e10cSrcweir void printBool( sal_Bool bOk ); 134cdf0e10cSrcweir /** print content of a ByteSequence. 135cdf0e10cSrcweir */ 136cdf0e10cSrcweir void printByteSequence_IP( const ::rtl::ByteSequence & bsByteSeq, sal_Int32 nLen ); 137cdf0e10cSrcweir /** convert an IP which is stored as a UString format to a ByteSequence array for later use. 138cdf0e10cSrcweir */ 139cdf0e10cSrcweir ::rtl::ByteSequence UStringIPToByteSequence( ::rtl::OUString aUStr ); 140cdf0e10cSrcweir /** print a socket result name. 141cdf0e10cSrcweir */ 142cdf0e10cSrcweir void printSocketResult( oslSocketResult eResult ); 143cdf0e10cSrcweir /** if 4 parts of an IP addr are equal to specified values 144cdf0e10cSrcweir */ 145cdf0e10cSrcweir sal_Bool ifIpv4is( const ::rtl::ByteSequence Ipaddr, sal_Int8 seq1, sal_Int8 seq2, sal_Int8 seq3, sal_Int8 seq4 ); 146cdf0e10cSrcweir /** if the IP or hostname is availble( alive ) 147cdf0e10cSrcweir */ 148cdf0e10cSrcweir //sal_Bool ifAvailable( const char * stringAddrOrHostName ); 149cdf0e10cSrcweir sal_Bool ifAvailable( rtl::OUString const& strAddrOrHostName ); 150cdf0e10cSrcweir /* 151cdf0e10cSrcweir class ClientSocketThread : public Thread 152cdf0e10cSrcweir class ServerSocketThread : public Thread 153cdf0e10cSrcweir class ValueCheckProvider 154cdf0e10cSrcweir class ClientReadSocketThread : public Thread 155cdf0e10cSrcweir class ServerWriteSocketThread : public Thread 156cdf0e10cSrcweir class AcceptorThread : public Thread 157cdf0e10cSrcweir class CloseSocketThread : public Thread 158cdf0e10cSrcweir 159cdf0e10cSrcweir */ 160cdf0e10cSrcweir 161cdf0e10cSrcweir #endif 162