xref: /aoo4110/main/sal/qa/osl/socket/sockethelper.hxx (revision b1cdbd2c)
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 #include <sys/statfs.h>
72 #include <sys/statvfs.h>
73 #include <sys/types.h>
74 #include <sys/socket.h>
75 #include <netdb.h>
76 #include <netinet/in.h>
77 #include <arpa/inet.h>
78 #include <sys/wait.h>
79 #endif
80 
81 #ifndef _OSL_SOCKET_CONST_H_
82 
83 #if ( defined WNT )                     // Windows
84 #include <tools/prewin.h>
85 // #include <windows.h>
86 #include <winsock.h>
87 #include <string.h>
88 #include <tools/postwin.h>
89 #endif
90 
91 #endif
92 
93 //------------------------------------------------------------------------
94 //------------------------------------------------------------------------
95 
96 #ifdef __cplusplus
97 }
98 #endif
99 
100 /** compare two OUString.
101 */
102 sal_Bool compareUString( const ::rtl::OUString & ustr1, const ::rtl::OUString & ustr2 );
103 /** compare a OUString and an ASCII string.
104 */
105 sal_Bool compareUString( const ::rtl::OUString & ustr, const sal_Char *astr );
106 /** compare two socket address.
107 */
108 sal_Bool compareSocketAddr( const ::osl::SocketAddr & addr1 , const ::osl::SocketAddr & addr2  );
109 //char * oustring2char( const ::rtl::OUString & str );
110 /** print a UNI_CODE String. And also print some comments of the string.
111 */
112 void printUString( const ::rtl::OUString & str, const char * msg = "" );
113 /** get the local host name.
114     mindy: gethostbyname( "localhost" ), on Linux, it returns the hostname in /etc/hosts + domain name,
115     if no entry in /etc/hosts, it returns "localhost" + domain name
116 */
117 ::rtl::OUString getHost( void );
118 /** get the full host name of the current processor, such as "aegean.prc.sun.com" --mindyliu
119 */
120 ::rtl::OUString getThisHostname( void );
121 /** get IP by name, search /etc/hosts first, then search from dns, fail return OUString("")
122 */
123 ::rtl::OUString getIPbyName( rtl::OString const& str_name );
124 /** get local ethernet IP
125 */
126 ::rtl::OUString getLocalIP( );
127 /** construct error message
128 */
129 ::rtl::OUString outputError( const ::rtl::OUString & returnVal, const ::rtl::OUString & rightVal, const sal_Char * msg = "");
130 void thread_sleep( sal_Int32 _nSec );
131 /** print Boolean value.
132 */
133 void printBool( sal_Bool bOk );
134 /** print content of a ByteSequence.
135 */
136 void printByteSequence_IP( const ::rtl::ByteSequence & bsByteSeq, sal_Int32 nLen );
137 /** convert an IP which is stored as a UString format to a ByteSequence array for later use.
138 */
139 ::rtl::ByteSequence UStringIPToByteSequence( ::rtl::OUString aUStr );
140 /** print a socket result name.
141 */
142 void printSocketResult( oslSocketResult eResult );
143 /** if 4 parts of an IP addr are equal to specified values
144 */
145 sal_Bool ifIpv4is( const ::rtl::ByteSequence Ipaddr, sal_Int8 seq1, sal_Int8 seq2, sal_Int8 seq3, sal_Int8 seq4 );
146 /** if the IP or hostname is  availble( alive )
147 */
148 //sal_Bool ifAvailable( const char *  stringAddrOrHostName );
149 sal_Bool ifAvailable( rtl::OUString const&  strAddrOrHostName );
150 /*
151 class ClientSocketThread : public Thread
152 class ServerSocketThread : public Thread
153 class ValueCheckProvider
154 class ClientReadSocketThread : public Thread
155 class ServerWriteSocketThread : public Thread
156 class AcceptorThread : public Thread
157 class CloseSocketThread : public Thread
158 
159 */
160 
161 #endif
162