xref: /aoo42x/main/sal/qa/osl/socket/sockethelper.hxx (revision e6348c9c)
1565d668cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3565d668cSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4565d668cSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5565d668cSAndrew Rist  * distributed with this work for additional information
6565d668cSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7565d668cSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8565d668cSAndrew Rist  * "License"); you may not use this file except in compliance
9565d668cSAndrew Rist  * with the License.  You may obtain a copy of the License at
10565d668cSAndrew Rist  *
11565d668cSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12565d668cSAndrew Rist  *
13565d668cSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14565d668cSAndrew Rist  * software distributed under the License is distributed on an
15565d668cSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16565d668cSAndrew Rist  * KIND, either express or implied.  See the License for the
17565d668cSAndrew Rist  * specific language governing permissions and limitations
18565d668cSAndrew Rist  * under the License.
19565d668cSAndrew Rist  *
20565d668cSAndrew Rist  *************************************************************/
21565d668cSAndrew Rist 
22565d668cSAndrew 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>
71*63d99982SDamjan Jovanovic #ifndef __FreeBSD__
72*63d99982SDamjan Jovanovic #   include <sys/statfs.h>
73*63d99982SDamjan Jovanovic #endif
74cdf0e10cSrcweir #include <sys/statvfs.h>
75cdf0e10cSrcweir #include <sys/types.h>
76cdf0e10cSrcweir #include <sys/socket.h>
77cdf0e10cSrcweir #include <netdb.h>
78cdf0e10cSrcweir #include <netinet/in.h>
79cdf0e10cSrcweir #include <arpa/inet.h>
80cdf0e10cSrcweir #include <sys/wait.h>
81cdf0e10cSrcweir #endif
82cdf0e10cSrcweir 
83cdf0e10cSrcweir #ifndef _OSL_SOCKET_CONST_H_
84cdf0e10cSrcweir 
85cdf0e10cSrcweir #if ( defined WNT )                     // Windows
86cdf0e10cSrcweir #include <winsock.h>
87cdf0e10cSrcweir #include <string.h>
88cdf0e10cSrcweir #endif
89cdf0e10cSrcweir 
90cdf0e10cSrcweir #endif
91cdf0e10cSrcweir 
92cdf0e10cSrcweir //------------------------------------------------------------------------
93cdf0e10cSrcweir //------------------------------------------------------------------------
94cdf0e10cSrcweir 
95cdf0e10cSrcweir #ifdef __cplusplus
96cdf0e10cSrcweir }
97cdf0e10cSrcweir #endif
98cdf0e10cSrcweir 
99cdf0e10cSrcweir /** compare two OUString.
100cdf0e10cSrcweir */
101cdf0e10cSrcweir sal_Bool compareUString( const ::rtl::OUString & ustr1, const ::rtl::OUString & ustr2 );
102cdf0e10cSrcweir /** compare a OUString and an ASCII string.
103cdf0e10cSrcweir */
104cdf0e10cSrcweir sal_Bool compareUString( const ::rtl::OUString & ustr, const sal_Char *astr );
105cdf0e10cSrcweir /** compare two socket address.
106cdf0e10cSrcweir */
107cdf0e10cSrcweir sal_Bool compareSocketAddr( const ::osl::SocketAddr & addr1 , const ::osl::SocketAddr & addr2  );
108cdf0e10cSrcweir //char * oustring2char( const ::rtl::OUString & str );
109cdf0e10cSrcweir /** print a UNI_CODE String. And also print some comments of the string.
110cdf0e10cSrcweir */
111cdf0e10cSrcweir void printUString( const ::rtl::OUString & str, const char * msg = "" );
112cdf0e10cSrcweir /** get the local host name.
113cdf0e10cSrcweir     mindy: gethostbyname( "localhost" ), on Linux, it returns the hostname in /etc/hosts + domain name,
114cdf0e10cSrcweir     if no entry in /etc/hosts, it returns "localhost" + domain name
115cdf0e10cSrcweir */
116cdf0e10cSrcweir ::rtl::OUString getHost( void );
117cdf0e10cSrcweir /** get the full host name of the current processor, such as "aegean.prc.sun.com" --mindyliu
118cdf0e10cSrcweir */
119cdf0e10cSrcweir ::rtl::OUString getThisHostname( void );
120cdf0e10cSrcweir /** get IP by name, search /etc/hosts first, then search from dns, fail return OUString("")
121cdf0e10cSrcweir */
122cdf0e10cSrcweir ::rtl::OUString getIPbyName( rtl::OString const& str_name );
123cdf0e10cSrcweir /** get local ethernet IP
124cdf0e10cSrcweir */
125cdf0e10cSrcweir ::rtl::OUString getLocalIP( );
126cdf0e10cSrcweir /** construct error message
127cdf0e10cSrcweir */
128cdf0e10cSrcweir ::rtl::OUString outputError( const ::rtl::OUString & returnVal, const ::rtl::OUString & rightVal, const sal_Char * msg = "");
129cdf0e10cSrcweir void thread_sleep( sal_Int32 _nSec );
130cdf0e10cSrcweir /** print Boolean value.
131cdf0e10cSrcweir */
132cdf0e10cSrcweir void printBool( sal_Bool bOk );
133cdf0e10cSrcweir /** print content of a ByteSequence.
134cdf0e10cSrcweir */
135cdf0e10cSrcweir void printByteSequence_IP( const ::rtl::ByteSequence & bsByteSeq, sal_Int32 nLen );
136cdf0e10cSrcweir /** convert an IP which is stored as a UString format to a ByteSequence array for later use.
137cdf0e10cSrcweir */
138cdf0e10cSrcweir ::rtl::ByteSequence UStringIPToByteSequence( ::rtl::OUString aUStr );
139cdf0e10cSrcweir /** print a socket result name.
140cdf0e10cSrcweir */
141cdf0e10cSrcweir void printSocketResult( oslSocketResult eResult );
142cdf0e10cSrcweir /** if 4 parts of an IP addr are equal to specified values
143cdf0e10cSrcweir */
144cdf0e10cSrcweir sal_Bool ifIpv4is( const ::rtl::ByteSequence Ipaddr, sal_Int8 seq1, sal_Int8 seq2, sal_Int8 seq3, sal_Int8 seq4 );
14586e1cf34SPedro Giffuni /** if the IP or hostname is  available( alive )
146cdf0e10cSrcweir */
147cdf0e10cSrcweir //sal_Bool ifAvailable( const char *  stringAddrOrHostName );
148cdf0e10cSrcweir sal_Bool ifAvailable( rtl::OUString const&  strAddrOrHostName );
149cdf0e10cSrcweir /*
150cdf0e10cSrcweir class ClientSocketThread : public Thread
151cdf0e10cSrcweir class ServerSocketThread : public Thread
152cdf0e10cSrcweir class ValueCheckProvider
153cdf0e10cSrcweir class ClientReadSocketThread : public Thread
154cdf0e10cSrcweir class ServerWriteSocketThread : public Thread
155cdf0e10cSrcweir class AcceptorThread : public Thread
156cdf0e10cSrcweir class CloseSocketThread : public Thread
157cdf0e10cSrcweir 
158cdf0e10cSrcweir */
159cdf0e10cSrcweir 
160cdf0e10cSrcweir #endif
161