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