sockethelper.cxx (86e1cf34) sockethelper.cxx (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

--- 11 unchanged lines hidden (view full) ---

20 *************************************************************/
21
22
23
24
25// MARKER(update_precomp.py): autogen include statement, do not remove
26#include "precompiled_sal.hxx"
27#include "sockethelper.hxx"
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

--- 11 unchanged lines hidden (view full) ---

20 *************************************************************/
21
22
23
24
25// MARKER(update_precomp.py): autogen include statement, do not remove
26#include "precompiled_sal.hxx"
27#include "sockethelper.hxx"
28#include <testshl/simpleheader.hxx>
29
30//------------------------------------------------------------------------
31// Ip version definition
32//------------------------------------------------------------------------
33#define IP_VER 4 /// currently only IPv4 is considered.
34
35//------------------------------------------------------------------------
36// helper functions

--- 24 unchanged lines hidden (view full) ---

61{
62 return ( ( sal_True == compareUString( addr1.getHostname( 0 ), addr2.getHostname( 0 ) ) ) && ( addr2.getPort( ) == addr2.getPort( ) ) );
63}
64
65/*char * oustring2char( const ::rtl::OUString & str )
66{
67 rtl::OString aString;
68 aString = ::rtl::OUStringToOString( str, RTL_TEXTENCODING_ASCII_US );
28
29//------------------------------------------------------------------------
30// Ip version definition
31//------------------------------------------------------------------------
32#define IP_VER 4 /// currently only IPv4 is considered.
33
34//------------------------------------------------------------------------
35// helper functions

--- 24 unchanged lines hidden (view full) ---

60{
61 return ( ( sal_True == compareUString( addr1.getHostname( 0 ), addr2.getHostname( 0 ) ) ) && ( addr2.getPort( ) == addr2.getPort( ) ) );
62}
63
64/*char * oustring2char( const ::rtl::OUString & str )
65{
66 rtl::OString aString;
67 aString = ::rtl::OUStringToOString( str, RTL_TEXTENCODING_ASCII_US );
69 t_print("oustring2char %s\n", aString.getStr( ) );
68 printf("oustring2char %s\n", aString.getStr( ) );
70 sal_Char * sStr = aString.getStr( );
71 return (char *)sStr;
72}*/
73
74/** print a UNI_CODE String. And also print some comments of the string.
75*/
76void printUString( const ::rtl::OUString & str, const char* msg)
77{
69 sal_Char * sStr = aString.getStr( );
70 return (char *)sStr;
71}*/
72
73/** print a UNI_CODE String. And also print some comments of the string.
74*/
75void printUString( const ::rtl::OUString & str, const char* msg)
76{
78 t_print("#%s #printUString_u# ", msg );
77 printf("#%s #printUString_u# ", msg );
79 rtl::OString aString;
80 aString = ::rtl::OUStringToOString( str, RTL_TEXTENCODING_ASCII_US );
81 //char * sStr = aString.getStr( );
78 rtl::OString aString;
79 aString = ::rtl::OUStringToOString( str, RTL_TEXTENCODING_ASCII_US );
80 //char * sStr = aString.getStr( );
82 t_print("%s\n", aString.getStr( ) );
81 printf("%s\n", aString.getStr( ) );
83}
84
85/** get the local host name.
86 mindy: gethostbyname( "localhost" ), on Linux, it returns the hostname in /etc/hosts + domain name,
87 if no entry in /etc/hosts, it returns "localhost" + domain name
88*/
89::rtl::OUString getHost( void )
90{

--- 26 unchanged lines hidden (view full) ---

117 struct hostent *hptr;
118 //first search /ets/hosts, then search from dns
119 hptr = gethostbyname( hostname);
120 if ( hptr != NULL )
121 {
122 strcpy( hostname, hptr->h_name );
123 }
124
82}
83
84/** get the local host name.
85 mindy: gethostbyname( "localhost" ), on Linux, it returns the hostname in /etc/hosts + domain name,
86 if no entry in /etc/hosts, it returns "localhost" + domain name
87*/
88::rtl::OUString getHost( void )
89{

--- 26 unchanged lines hidden (view full) ---

116 struct hostent *hptr;
117 //first search /ets/hosts, then search from dns
118 hptr = gethostbyname( hostname);
119 if ( hptr != NULL )
120 {
121 strcpy( hostname, hptr->h_name );
122 }
123
125 t_print("hostname is %s \n", hostname );
124 printf("hostname is %s \n", hostname );
126 rtl::OString sHostname( hostname );
127 aUString = ::rtl::OStringToOUString( sHostname, RTL_TEXTENCODING_ASCII_US );
128 aUString.getLength();
129#endif
130 return aUString;
131}
132
133/** get IP by name, search /etc/hosts first, then search from dns, fail return OUString("")

--- 6 unchanged lines hidden (view full) ---

140 hptr = gethostbyname( str_name.getStr());
141 if ( hptr != NULL )
142 {
143 struct in_addr ** addrptr;
144 addrptr = (struct in_addr **) hptr->h_addr_list ;
145 //if there are more than one IPs on the same machine, we select one
146 for (; *addrptr; addrptr++)
147 {
125 rtl::OString sHostname( hostname );
126 aUString = ::rtl::OStringToOUString( sHostname, RTL_TEXTENCODING_ASCII_US );
127 aUString.getLength();
128#endif
129 return aUString;
130}
131
132/** get IP by name, search /etc/hosts first, then search from dns, fail return OUString("")

--- 6 unchanged lines hidden (view full) ---

139 hptr = gethostbyname( str_name.getStr());
140 if ( hptr != NULL )
141 {
142 struct in_addr ** addrptr;
143 addrptr = (struct in_addr **) hptr->h_addr_list ;
144 //if there are more than one IPs on the same machine, we select one
145 for (; *addrptr; addrptr++)
146 {
148 t_print("#Local IP Address: %s\n", inet_ntoa(**addrptr));
147 printf("#Local IP Address: %s\n", inet_ntoa(**addrptr));
149 aUString = ::rtl::OUString::createFromAscii( (sal_Char *) (inet_ntoa(**addrptr)) );
150 }
151 }
152 return aUString;
153}
154
155/** get local ethernet IP
156*/

--- 30 unchanged lines hidden (view full) ---

187 // fflush(stdout);
188
189#ifdef WNT //Windows
190 Sleep( _nSec * 100 );
191#endif
192#if ( defined UNX ) || ( defined OS2 ) //Unix
193 usleep(_nSec * 100000);
194#endif
148 aUString = ::rtl::OUString::createFromAscii( (sal_Char *) (inet_ntoa(**addrptr)) );
149 }
150 }
151 return aUString;
152}
153
154/** get local ethernet IP
155*/

--- 30 unchanged lines hidden (view full) ---

186 // fflush(stdout);
187
188#ifdef WNT //Windows
189 Sleep( _nSec * 100 );
190#endif
191#if ( defined UNX ) || ( defined OS2 ) //Unix
192 usleep(_nSec * 100000);
193#endif
195 // t_print("# done\n" );
194 // printf("# done\n" );
196}
197
198/** print Boolean value.
199*/
200void printBool( sal_Bool bOk )
201{
195}
196
197/** print Boolean value.
198*/
199void printBool( sal_Bool bOk )
200{
202 t_print("printBool " );
203 ( sal_True == bOk ) ? t_print("YES!" ): t_print("NO!");
204 t_print("\n");
201 printf("printBool " );
202 ( sal_True == bOk ) ? printf("YES!" ): printf("NO!");
203 printf("\n");
205}
206
207/** print content of a ByteSequence.
208*/
209void printByteSequence_IP( const ::rtl::ByteSequence & bsByteSeq, sal_Int32 nLen )
210{
204}
205
206/** print content of a ByteSequence.
207*/
208void printByteSequence_IP( const ::rtl::ByteSequence & bsByteSeq, sal_Int32 nLen )
209{
211 t_print("ByteSequence is: " );
210 printf("ByteSequence is: " );
212 for ( int i = 0; i < nLen; i++ ){
213 if ( bsByteSeq[i] < 0 )
211 for ( int i = 0; i < nLen; i++ ){
212 if ( bsByteSeq[i] < 0 )
214 t_print("%d ", 256 + bsByteSeq[i] );
213 printf("%d ", 256 + bsByteSeq[i] );
215 else
214 else
216 t_print("%d ", bsByteSeq[i] );
215 printf("%d ", bsByteSeq[i] );
217 }
216 }
218 t_print(" .\n" );
217 printf(" .\n" );
219}
220
221/** convert an IP which is stored as a UString format to a ByteSequence array for later use.
222*/
223::rtl::ByteSequence UStringIPToByteSequence( ::rtl::OUString aUStr )
224{
225
226 rtl::OString aString = ::rtl::OUStringToOString( aUStr, RTL_TEXTENCODING_ASCII_US );

--- 17 unchanged lines hidden (view full) ---

244 }
245 return bsByteSequence;
246}
247
248/** print a socket result name.
249*/
250void printSocketResult( oslSocketResult eResult )
251{
218}
219
220/** convert an IP which is stored as a UString format to a ByteSequence array for later use.
221*/
222::rtl::ByteSequence UStringIPToByteSequence( ::rtl::OUString aUStr )
223{
224
225 rtl::OString aString = ::rtl::OUStringToOString( aUStr, RTL_TEXTENCODING_ASCII_US );

--- 17 unchanged lines hidden (view full) ---

243 }
244 return bsByteSequence;
245}
246
247/** print a socket result name.
248*/
249void printSocketResult( oslSocketResult eResult )
250{
252 t_print("printSocketResult: " );
251 printf("printSocketResult: " );
253 if (!eResult)
254 switch (eResult)
255 {
256 case osl_Socket_Ok:
252 if (!eResult)
253 switch (eResult)
254 {
255 case osl_Socket_Ok:
257 t_print("client connected\n");
256 printf("client connected\n");
258 break;
259 case osl_Socket_Error:
257 break;
258 case osl_Socket_Error:
260 t_print("got an error ... exiting\r\n\r\n" );
259 printf("got an error ... exiting\r\n\r\n" );
261 break;
262 case osl_Socket_TimedOut:
260 break;
261 case osl_Socket_TimedOut:
263 t_print("timeout\n");
262 printf("timeout\n");
264 break;
265 case osl_Socket_Interrupted:
263 break;
264 case osl_Socket_Interrupted:
266 t_print("interrupted\n");
265 printf("interrupted\n");
267 break;
268 case osl_Socket_InProgress:
266 break;
267 case osl_Socket_InProgress:
269 t_print("in progress\n");
268 printf("in progress\n");
270 break;
271 default:
269 break;
270 default:
272 t_print("unknown result\n");
271 printf("unknown result\n");
273 break;
274 }
275}
276
277/** if 4 parts of an IP addr are equal to specified values
278*/
279sal_Bool ifIpv4is( const ::rtl::ByteSequence Ipaddr, sal_Int8 seq1, sal_Int8 seq2, sal_Int8 seq3, sal_Int8 seq4 )
280{

--- 63 unchanged lines hidden (view full) ---

344#if ( defined LINUX )
345 char strOK[] = "bytes from";
346#endif
347#if ( defined SOLARIS )
348 char strOK[] = "is alive";
349#endif
350 if (strstr( buffer, strOK ) != NULL )
351 result = sal_True;
272 break;
273 }
274}
275
276/** if 4 parts of an IP addr are equal to specified values
277*/
278sal_Bool ifIpv4is( const ::rtl::ByteSequence Ipaddr, sal_Int8 seq1, sal_Int8 seq2, sal_Int8 seq3, sal_Int8 seq4 )
279{

--- 63 unchanged lines hidden (view full) ---

343#if ( defined LINUX )
344 char strOK[] = "bytes from";
345#endif
346#if ( defined SOLARIS )
347 char strOK[] = "is alive";
348#endif
349 if (strstr( buffer, strOK ) != NULL )
350 result = sal_True;
352 t_print("buffer is %s\n", buffer );
351 printf("buffer is %s\n", buffer );
353 }
354 close (p[0]);
355 waitpid (pid, &nStatus, 0);
356 }
357 else
358 {
359 close (p[0]);
360 close (p[1]);

--- 21 unchanged lines hidden (view full) ---

382 pTimeout->Seconds = 3;
383 pTimeout->Nanosec = 0;
384
385 oslSocketResult aResult = aSocket.connect( aSocketAddr, pTimeout );
386 free( pTimeout );
387 aSocket.close();
388 if ( aResult != osl_Socket_Ok )
389 {
352 }
353 close (p[0]);
354 waitpid (pid, &nStatus, 0);
355 }
356 else
357 {
358 close (p[0]);
359 close (p[1]);

--- 21 unchanged lines hidden (view full) ---

381 pTimeout->Seconds = 3;
382 pTimeout->Nanosec = 0;
383
384 oslSocketResult aResult = aSocket.connect( aSocketAddr, pTimeout );
385 free( pTimeout );
386 aSocket.close();
387 if ( aResult != osl_Socket_Ok )
388 {
390 t_print("Error: ");
389 printf("Error: ");
391 printSocketResult(aResult);
390 printSocketResult(aResult);
392 t_print("\n");
391 printf("\n");
393
394 return sal_False;
395 }
396 return sal_True;
397}
392
393 return sal_False;
394 }
395 return sal_True;
396}