getip() returen 0.0.0.0
Posted: Tue May 06, 2014 9:25 pm
Estimados
La funcion GetIp() return 0.0.0.0 cuando la direccion es estatica, hay alguna manera de repararlo
adjunto la funcion
La funcion GetIp() return 0.0.0.0 cuando la direccion es estatica, hay alguna manera de repararlo
adjunto la funcion
- Code: Select all Expand view
- HB_FUNC( GETIP ) // nSocket
{
SOCKADDR_IN sa;
int iLen = sizeof( sa );
BYTE addr[ 20 ];
#ifdef UNICODE
LPWSTR pW1, pW2;
#endif
memset( ( char * ) &sa, 0, sizeof( sa ) );
getsockname( hb_parni( 1 ), ( SOCKADDR * ) &sa, &iLen );
strcpy( ( char * ) addr, "error" );
#ifndef UNICODE
wsprintf( ( char * ) addr, "%i.%i.%i.%i",
( BYTE ) sa.sin_addr.s_net, ( BYTE ) sa.sin_addr.s_host,
( BYTE ) sa.sin_addr.s_lh, ( BYTE ) sa.sin_addr.s_impno );
#else
pW1 = AnsiToWide( ( char * ) addr );
pW2 = AnsiToWide( "%i.%i.%i.%i" );
wsprintf( pW1, pW2,
( BYTE ) sa.sin_addr.s_net, ( BYTE ) sa.sin_addr.s_host,
( BYTE ) sa.sin_addr.s_lh, ( BYTE ) sa.sin_addr.s_impno );
hb_xfree( pW1 );
hb_xfree( pW2 );
#endif
hb_retc( ( char * ) addr );
}