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