2010-02-20 18:05 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl)

* harbour/src/vm/task.c
    ! fixed casting for C++ builds

  * harbour/src/lang/msges.c
    ! added hack for Solaris builds where ES is macro
      TODDO: sync names of lang and corresponding code modules.

  * harbour/src/vm/dynlibhb.c
    * pacified warning

  * harbour/contrib/xpp/xppextrn.ch
  * harbour/contrib/xpp/dbcmdx.c
  * harbour/include/hbextern.ch
  * harbour/src/rdd/dbcmd53.c
    ! moved ordWildSeek() from XPP to HBRDD library.
      I have no idea if XPP has such function or if it's or not
      compatible with ORDWILDSEEK() functions I created for [x]Harbour
    * disable ordCount() and ordWildSeek() functions when HB_CLP_STRICT
      macro is set

  * harbour/include/hbsocket.ch
    + added macro values interface info flags: HB_SOCKET_IFF_*
    + added macro values for interface info array indexes: HB_SOCKET_IFINFO_*

  * harbour/include/hbsocket.h
  * harbour/src/rtl/hbsocket.c
    + added new C function:
         PHB_ITEM hb_socketGetIFaces( int af, HB_BOOL fNoAliases );
      it returns array with existing interfaces description.
      This code was added for non MS-Windows based platforms only.
      Support for MS-Windows has to be added yet.
      Some platforms may not fill all fields in the returned array.
      When some fields are not supported by platform or interface then
      they can contain NIL value.
      On some platforms this code can effectively work only with IP4
      interfaces and IP6 ones will need different implementation.
      TODO: add support for alternative long interface introduced in some
            new systems using 'struct lifreq' with SIOCGLIF* ioctls instead
            of 'struct ifreq' and SIOCGIF*
      TODO: add support for extracting hardware addreses (i.e. ethernet
            macaddresses) for systems which do not support SIOCGIFHWADDR.

      Please test this code with OS2 using OpenWatcom and GCC (old and
      new socket API). I enabled HB_HAS_SOCKADDR_SA_LEN in OS2 builds.
      OpenWatocm OS2 header files have such fields but I do know if it's
      also present in GCC socket API.

  * harbour/include/hbextern.ch
  * harbour/src/rtl/hbinet.c
    + added new PRG function:
         hb_inetIfInfo( [<lNoAliases>] [, <nAddrFamily>] ) -> <aInfo>
      <lNoAliases> is .F. by default so aliases are included
      <nAddrFamily> is HB_SOCKET_AF_INET by default
      <aInfo> is an array in which each entry is also array with the
      following fields:
         HB_SOCKET_IFINFO_FAMILY    1     // adress family
         HB_SOCKET_IFINFO_NAME      2     // interface name
         HB_SOCKET_IFINFO_FLAGS     3     // flags HB_SOCKET_IFF_*
         HB_SOCKET_IFINFO_ADDR      4     // interface address
         HB_SOCKET_IFINFO_NETMASK   5     // subnetmask
         HB_SOCKET_IFINFO_BROADCAST 6     // broadcast address
         HB_SOCKET_IFINFO_P2PADDR   7     // point-to-point address
         HB_SOCKET_IFINFO_HWADDR    8     // hardware address

      Please use this code on different non MS-Windows platforms:

            proc main( noAlias )
               local iface
               ? os(), version()
               ? "interfaces:"
               for each iface in hb_inetIfInfo( !empty( noAlias ), 0 )
                  ? hb_valToExp( iface )
               next
               ?
            return

      and check if it returns correct information about available
      interfaces.
This commit is contained in:
Przemyslaw Czerpak
2010-02-20 17:07:00 +00:00
parent 6d9e5bbb8c
commit 87cff88914
12 changed files with 436 additions and 61 deletions

View File

@@ -17,6 +17,86 @@
past entries belonging to author(s): Viktor Szakats.
*/
2010-02-20 18:05 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl)
* harbour/src/vm/task.c
! fixed casting for C++ builds
* harbour/src/lang/msges.c
! added hack for Solaris builds where ES is macro
TODDO: sync names of lang and corresponding code modules.
* harbour/src/vm/dynlibhb.c
* pacified warning
* harbour/contrib/xpp/xppextrn.ch
* harbour/contrib/xpp/dbcmdx.c
* harbour/include/hbextern.ch
* harbour/src/rdd/dbcmd53.c
! moved ordWildSeek() from XPP to HBRDD library.
I have no idea if XPP has such function or if it's or not
compatible with ORDWILDSEEK() functions I created for [x]Harbour
* disable ordCount() and ordWildSeek() functions when HB_CLP_STRICT
macro is set
* harbour/include/hbsocket.ch
+ added macro values interface info flags: HB_SOCKET_IFF_*
+ added macro values for interface info array indexes: HB_SOCKET_IFINFO_*
* harbour/include/hbsocket.h
* harbour/src/rtl/hbsocket.c
+ added new C function:
PHB_ITEM hb_socketGetIFaces( int af, HB_BOOL fNoAliases );
it returns array with existing interfaces description.
This code was added for non MS-Windows based platforms only.
Support for MS-Windows has to be added yet.
Some platforms may not fill all fields in the returned array.
When some fields are not supported by platform or interface then
they can contain NIL value.
On some platforms this code can effectively work only with IP4
interfaces and IP6 ones will need different implementation.
TODO: add support for alternative long interface introduced in some
new systems using 'struct lifreq' with SIOCGLIF* ioctls instead
of 'struct ifreq' and SIOCGIF*
TODO: add support for extracting hardware addreses (i.e. ethernet
macaddresses) for systems which do not support SIOCGIFHWADDR.
Please test this code with OS2 using OpenWatcom and GCC (old and
new socket API). I enabled HB_HAS_SOCKADDR_SA_LEN in OS2 builds.
OpenWatocm OS2 header files have such fields but I do know if it's
also present in GCC socket API.
* harbour/include/hbextern.ch
* harbour/src/rtl/hbinet.c
+ added new PRG function:
hb_inetIfInfo( [<lNoAliases>] [, <nAddrFamily>] ) -> <aInfo>
<lNoAliases> is .F. by default so aliases are included
<nAddrFamily> is HB_SOCKET_AF_INET by default
<aInfo> is an array in which each entry is also array with the
following fields:
HB_SOCKET_IFINFO_FAMILY 1 // adress family
HB_SOCKET_IFINFO_NAME 2 // interface name
HB_SOCKET_IFINFO_FLAGS 3 // flags HB_SOCKET_IFF_*
HB_SOCKET_IFINFO_ADDR 4 // interface address
HB_SOCKET_IFINFO_NETMASK 5 // subnetmask
HB_SOCKET_IFINFO_BROADCAST 6 // broadcast address
HB_SOCKET_IFINFO_P2PADDR 7 // point-to-point address
HB_SOCKET_IFINFO_HWADDR 8 // hardware address
Please use this code on different non MS-Windows platforms:
proc main( noAlias )
local iface
? os(), version()
? "interfaces:"
for each iface in hb_inetIfInfo( !empty( noAlias ), 0 )
? hb_valToExp( iface )
next
?
return
and check if it returns correct information about available
interfaces.
2010-02-20 16:39 UTC+0100 Viktor Szakats (harbour.01 syenar.hu)
* src/vm/memvars.c
* src/common/hbverdsp.c

View File

@@ -76,56 +76,3 @@ HB_FUNC( DBSKIPPER )
{
HB_FUNC_EXEC( __DBSKIPPER );
}
HB_FUNC( ORDWILDSEEK )
{
AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer();
if( pArea )
{
const char * szPattern = hb_parc( 1 );
if( szPattern )
{
HB_BOOL fCont = hb_parl( 2 ), fBack = hb_parl( 3 ), fFound = HB_FALSE;
DBORDERINFO OrderInfo;
HB_ERRCODE errCode = HB_SUCCESS;
memset( &OrderInfo, 0, sizeof( DBORDERINFO ) );
OrderInfo.itmResult = hb_itemNew( NULL );
if( !fCont )
{
const char * szKey;
if( fBack )
errCode = SELF_GOBOTTOM( pArea );
else
errCode = SELF_GOTOP( pArea );
if( errCode == HB_SUCCESS )
{
errCode = SELF_ORDINFO( pArea, DBOI_KEYVAL, &OrderInfo );
if( errCode == HB_SUCCESS )
{
szKey = hb_itemGetCPtr( OrderInfo.itmResult );
fFound = hb_strMatchWild( szKey, szPattern );
}
}
}
if( !fFound && errCode == HB_SUCCESS )
{
OrderInfo.itmNewVal = hb_param( 1, HB_IT_STRING );
if( SELF_ORDINFO( pArea, fBack ? DBOI_SKIPWILDBACK : DBOI_SKIPWILD,
&OrderInfo ) == HB_SUCCESS )
fFound = hb_itemGetL( OrderInfo.itmResult );
}
hb_itemRelease( OrderInfo.itmResult );
hb_retl( fFound );
}
else
hb_errRT_DBCMD( EG_ARG, EDBCMD_DBFILEPUTBADPARAMETER, NULL, HB_ERR_FUNCNAME );
}
else
hb_errRT_DBCMD( EG_NOTABLE, EDBCMD_NOTABLE, NULL, HB_ERR_FUNCNAME );
}

View File

@@ -77,7 +77,6 @@ EXTERNAL NUMBUTTONS
EXTERNAL SETMOUSE
EXTERNAL U2BIN
EXTERNAL W2BIN
EXTERNAL ORDWILDSEEK
EXTERNAL _DBEXPORT
EXTERNAL _TYPEFILE
EXTERNAL THREADID

View File

@@ -342,6 +342,8 @@ EXTERNAL DBRENAME
EXTERNAL FIELDLEN
EXTERNAL FIELDDEC
EXTERNAL FIELDTYPE
EXTERNAL ORDCOUNT
EXTERNAL ORDWILDSEEK
EXTERNAL MMIDDLEDOWN
EXTERNAL STOD
#endif
@@ -724,7 +726,6 @@ EXTERNAL ORDKEYVAL
EXTERNAL ORDSETRELATION
EXTERNAL ORDSKIPUNIQUE
EXTERNAL ORDSKIPRAW
EXTERNAL ORDCOUNT
EXTERNAL ORDCUSTOM
EXTERNAL ORDFINDREC
EXTERNAL ORDKEYRELPOS
@@ -1179,6 +1180,7 @@ EXTERNAL HB_INETSEND
EXTERNAL HB_INETSENDALL
EXTERNAL HB_INETGETHOSTS
EXTERNAL HB_INETGETALIAS
EXTERNAL HB_INETIFINFO
EXTERNAL HB_INETSERVER
EXTERNAL HB_INETACCEPT
EXTERNAL HB_INETCONNECT

View File

@@ -186,4 +186,22 @@
#define HB_SOCKET_SHUT_WR 1
#define HB_SOCKET_SHUT_RDWR 2
/* interface information flags */
#define HB_SOCKET_IFF_UP 0x0001 /* Interface is up */
#define HB_SOCKET_IFF_BROADCAST 0x0002 /* Broadcast address valid */
#define HB_SOCKET_IFF_LOOPBACK 0x0004 /* Is a loopback net */
#define HB_SOCKET_IFF_POINTOPOINT 0x0008 /* Interface is point-to-point link */
#define HB_SOCKET_IFF_MULTICAST 0x0010 /* Supports multicast */
/* Harbour interface information indexes */
#define HB_SOCKET_IFINFO_FAMILY 1 /* adress family */
#define HB_SOCKET_IFINFO_NAME 2 /* interface name */
#define HB_SOCKET_IFINFO_FLAGS 3 /* flags HB_SOCKET_IFF_* */
#define HB_SOCKET_IFINFO_ADDR 4 /* interface address */
#define HB_SOCKET_IFINFO_NETMASK 5 /* subnetmask */
#define HB_SOCKET_IFINFO_BROADCAST 6 /* broadcast address */
#define HB_SOCKET_IFINFO_P2PADDR 7 /* point-to-point address */
#define HB_SOCKET_IFINFO_HWADDR 8 /* hardware address */
#define HB_SOCKET_IFINFO_LEN 8
#endif /* HB_SOCKET_CH_ */

View File

@@ -82,6 +82,7 @@ HB_EXPORT extern HB_BOOL hb_socketResolveInetAddr( void ** pSockAddr, unsig
HB_EXPORT extern char * hb_socketResolveAddr( const char * szAddr, int af );
HB_EXPORT extern PHB_ITEM hb_socketGetHosts( const char * szAddr, int af );
HB_EXPORT extern PHB_ITEM hb_socketGetAliases( const char * szAddr, int af );
HB_EXPORT extern PHB_ITEM hb_socketGetIFaces( int af, HB_BOOL fNoAliases );
HB_EXPORT extern int hb_socketAddrGetPort( const void * pSockAddr, unsigned len );
HB_EXPORT extern HB_BOOL hb_socketAddrFromItem( void ** pSockAddr, unsigned * puiLen, PHB_ITEM pAddrItm );
HB_EXPORT extern PHB_ITEM hb_socketAddrToItem( const void * pSockAddr, unsigned len );

View File

@@ -200,5 +200,6 @@ static HB_LANG s_lang =
}
};
#undef ES /* Hack for Solaris builds where ES is macro */
#define HB_LANG_ID ES
#include "hbmsgreg.h"

View File

@@ -320,6 +320,7 @@ HB_FUNC( ORDCUSTOM )
hb_errRT_DBCMD( EG_NOTABLE, EDBCMD_NOTABLE, NULL, HB_ERR_FUNCNAME );
}
#ifndef HB_CLP_STRICT
HB_FUNC( ORDCOUNT )
{
AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer();
@@ -337,6 +338,60 @@ HB_FUNC( ORDCOUNT )
hb_errRT_DBCMD( EG_NOTABLE, EDBCMD_NOTABLE, NULL, HB_ERR_FUNCNAME );
}
HB_FUNC( ORDWILDSEEK )
{
AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer();
if( pArea )
{
const char * szPattern = hb_parc( 1 );
if( szPattern )
{
HB_BOOL fCont = hb_parl( 2 ), fBack = hb_parl( 3 ), fFound = HB_FALSE;
DBORDERINFO OrderInfo;
HB_ERRCODE errCode = HB_SUCCESS;
memset( &OrderInfo, 0, sizeof( DBORDERINFO ) );
OrderInfo.itmResult = hb_itemNew( NULL );
if( !fCont )
{
const char * szKey;
if( fBack )
errCode = SELF_GOBOTTOM( pArea );
else
errCode = SELF_GOTOP( pArea );
if( errCode == HB_SUCCESS )
{
errCode = SELF_ORDINFO( pArea, DBOI_KEYVAL, &OrderInfo );
if( errCode == HB_SUCCESS )
{
szKey = hb_itemGetCPtr( OrderInfo.itmResult );
fFound = hb_strMatchWild( szKey, szPattern );
}
}
}
if( !fFound && errCode == HB_SUCCESS )
{
OrderInfo.itmNewVal = hb_param( 1, HB_IT_STRING );
if( SELF_ORDINFO( pArea, fBack ? DBOI_SKIPWILDBACK : DBOI_SKIPWILD,
&OrderInfo ) == HB_SUCCESS )
fFound = hb_itemGetL( OrderInfo.itmResult );
}
hb_itemRelease( OrderInfo.itmResult );
hb_retl( fFound );
}
else
hb_errRT_DBCMD( EG_ARG, EDBCMD_DBFILEPUTBADPARAMETER, NULL, HB_ERR_FUNCNAME );
}
else
hb_errRT_DBCMD( EG_NOTABLE, EDBCMD_NOTABLE, NULL, HB_ERR_FUNCNAME );
}
#endif
HB_FUNC( DBINFO )
{
AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer();

View File

@@ -1083,6 +1083,19 @@ HB_FUNC( HB_INETGETALIAS )
}
/**********************************************
* Interface information function
****/
HB_FUNC( HB_INETIFINFO )
{
PHB_ITEM pInfo = hb_socketGetIFaces( hb_parnidef( 2, HB_SOCKET_PF_INET ),
hb_parl( 1 ) );
if( pInfo )
hb_itemReturnRelease( pInfo );
else
hb_reta( 0 );
}
/**********************************************
* Server Specific functions
****/

View File

@@ -80,6 +80,9 @@
platform supports getaddrinfo()/freeaddrinfo() functions:
#define HB_HAS_ADDRINFO
platform uses sockaddr structure which contains sa_len member:
#define HB_HAS_SOCKADDR_SA_LEN
platform supports constant inet6 addresses in6addr_any and in6addr_loopback:
#define HB_HAS_INET6_ADDR_CONST
@@ -127,10 +130,18 @@
# if defined( HB_OS_BEOS )
# define HB_SOCKET_TRANSLATE_DOMAIN
# define HB_SOCKET_TRANSLATE_TYPE
# define HB_HAS_SOCKADDR_SA_LEN
# endif
# if defined( HB_OS_LINUX )
# define HB_HAS_SELECT_TIMER
# endif
# if defined( HB_OS_SUNOS ) && !defined( BSD_COMP )
# define BSD_COMP
# endif
# if defined( HB_OS_BSD )
# define HB_SOCKET_TRANSLATE_DOMAIN
# define HB_HAS_SOCKADDR_SA_LEN
# endif
#elif defined( HB_OS_WIN )
# if defined( __WATCOMC__ )
# if ( NTDDI_VERSION >= 0x06000000 )
@@ -146,6 +157,7 @@
# endif
# define HB_IS_INET_NTOA_MT_SAFE
#elif defined( HB_OS_OS2 )
# define HB_HAS_SOCKADDR_SA_LEN
# if defined( __WATCOMC__ )
# define HB_HAS_INET_PTON
# define HB_HAS_INET_NTOP
@@ -185,7 +197,6 @@
# endif
# include <sys/socket.h>
# include <sys/select.h>
# include <sys/ioctl.h>
# include <arpa/inet.h>
# endif
# if !( defined( HB_OS_DOS ) && defined( __WATCOMC__ ) )
@@ -193,6 +204,10 @@
# endif
# include <sys/types.h>
# include <sys/socket.h>
# include <sys/ioctl.h>
# if defined( HB_OS_BEOS )
# include <sys/sockio.h>
# endif
# include <netdb.h>
# include <netinet/in.h>
# include <arpa/inet.h>
@@ -200,10 +215,10 @@
# include <sys/un.h>
# endif
# include <netinet/tcp.h>
# include <net/if.h>
# include <unistd.h>
# include <fcntl.h>
# if defined( HB_OS_DOS )
# include <sys/ioctl.h>
# define select select_s
# endif
#endif
@@ -707,6 +722,14 @@ PHB_ITEM hb_socketGetAliases( const char * szAddr, int af )
return NULL;
}
PHB_ITEM hb_socketGetIFaces( int af, HB_BOOL fNoAliases )
{
HB_SYMBOL_UNUSED( af );
HB_SYMBOL_UNUSED( fNoAliases );
hb_socketSetRawError( HB_SOCKET_ERR_AFNOSUPPORT );
return NULL;
}
#else
#define HB_SOCKADDR_MAX_LEN 256
@@ -1702,7 +1725,7 @@ char * hb_socketAddrGetName( const void * pSockAddr, unsigned len )
const char * szAddr;
# if defined( HB_HAS_INET_NTOP )
char buf[ INET6_ADDRSTRLEN ];
szAddr = inet_ntop( AF_INET, &sa->sin6_addr, buf, sizeof( buf ) );
szAddr = inet_ntop( AF_INET6, &sa->sin6_addr, buf, sizeof( buf ) );
# else
{
int iTODO;
@@ -1856,7 +1879,7 @@ PHB_ITEM hb_socketAddrToItem( const void * pSockAddr, unsigned len )
const char * szAddr;
# if defined( HB_HAS_INET_NTOP )
char buf[ INET6_ADDRSTRLEN ];
szAddr = inet_ntop( AF_INET, &sa->sin6_addr, buf, sizeof( buf ) );
szAddr = inet_ntop( AF_INET6, &sa->sin6_addr, buf, sizeof( buf ) );
# else
{
int iTODO;
@@ -2690,7 +2713,7 @@ HB_BOOL hb_socketResolveInetAddr( void ** pSockAddr, unsigned * puiLen, const ch
hints.ai_family = AF_INET;
if( getaddrinfo( szAddr, NULL, &hints, &res ) == 0 )
{
if( res->ai_addrlen >= sizeof( struct sockaddr_in ) &&
if( ( int ) res->ai_addrlen >= ( int ) sizeof( struct sockaddr_in ) &&
hb_socketGetAddrFamilly( res->ai_addr, res->ai_addrlen ) == AF_INET )
{
sa.sin_addr.s_addr = ( ( struct sockaddr_in * ) res->ai_addr )->sin_addr.s_addr;
@@ -2944,4 +2967,238 @@ PHB_ITEM hb_socketGetAliases( const char * szAddr, int af )
return NULL;
}
#if defined( SIOCGIFCONF )
static void hb_socketArraySetInetAddr( PHB_ITEM pItem, HB_SIZE nPos,
const void * pSockAddr, unsigned len )
{
char * szAddr = hb_socketAddrGetName( pSockAddr, len );
if( szAddr )
{
if( ! hb_arraySetCLPtr( pItem, nPos, szAddr, strlen( szAddr ) ) )
hb_xfree( szAddr );
}
}
#endif
PHB_ITEM hb_socketGetIFaces( int af, HB_BOOL fNoAliases )
{
PHB_ITEM pArray = NULL;
/*
* TODO: add suppot for alternative long interface intorduced in some
* new systems using 'struct lifreq' with SIOCGLIF* ioctls instead
* of 'struct ifreq' and SIOCGIF*
*/
#if defined( SIOCGIFCONF )
PHB_ITEM pItem = NULL;
struct ifconf ifc;
struct ifreq * pifr;
char * buf, * ptr;
const char * pLastName = NULL;
int len = 0, size, iLastName = 0, iLastFamily = 0, flags, family;
HB_SOCKET sd;
sd = hb_socketOpen( af ? af : HB_SOCKET_AF_INET, HB_SOCKET_PT_DGRAM, 0 );
if( sd != HB_NO_SOCKET )
{
# if defined( HB_SOCKET_TRANSLATE_DOMAIN )
af = hb_socketTransDomain( af, NULL );
# endif
# ifdef SIOCGIFNUM
if( ioctl( sd, SIOCGIFNUM, &len ) == -1 )
len = 0;
# endif
if( len <= 0 )
len = 0x8000;
len *= sizeof( struct ifreq );
buf = ( char * ) hb_xgrab( len );
ifc.ifc_len = len;
ifc.ifc_buf = buf;
/* Warning: On some platforms this code can effectively work only with
* IP4 interfaces and IP6 will need different implementation.
*/
if( ioctl( sd, SIOCGIFCONF, &ifc ) != -1 )
{
for( ptr = ifc.ifc_buf, size = ifc.ifc_len; size > 0; )
{
pifr = ( struct ifreq * ) ptr;
family = pifr->ifr_addr.sa_family;
# if defined( HB_HAS_SOCKADDR_SA_LEN )
len = pifr->ifr_addr.sa_len;
if( len < ( int ) sizeof( struct sockaddr ) )
len = sizeof( struct sockaddr );
# else
switch( family )
{
# if defined( HB_HAS_INET6 )
case AF_INET6:
len = sizeof( struct sockaddr_in6 );
break;
# endif
# if defined( AF_INET )
case AF_INET:
# endif
default:
len = sizeof( struct sockaddr );
break;
}
# endif
len += sizeof( pifr->ifr_name );
# if !defined( HB_OS_BEOS )
if( len < ( int ) sizeof( struct ifreq ) )
len = ( int ) sizeof( struct ifreq );
# endif
ptr += len;
size -= len;
if( af && family != af )
continue;
/* skip alias devices */
if( fNoAliases )
{
const char * cptr = strchr( pifr->ifr_name, ':' );
len = cptr ? ( int ) ( pifr->ifr_name - cptr ) :
( int ) strlen( pifr->ifr_name );
if( pLastName && len == iLastName && family == iLastFamily &&
memcmp( pLastName, pifr->ifr_name, len ) == 0 )
continue;
pLastName = pifr->ifr_name;
iLastName = len;
iLastFamily = family;
}
{
struct ifreq ifr = *pifr;
if( ioctl( sd, SIOCGIFFLAGS, &ifr ) == -1 )
continue;
flags = ifr.ifr_flags;
}
if( ( flags & IFF_UP ) == 0 )
continue;
if( pItem == NULL )
pItem = hb_itemNew( NULL );
hb_arrayNew( pItem, HB_SOCKET_IFINFO_LEN );
pifr->ifr_name[ sizeof( pifr->ifr_name ) - 1 ] = '\0';
hb_arraySetC( pItem, HB_SOCKET_IFINFO_NAME, pifr->ifr_name );
switch( family )
{
# if defined( HB_HAS_INET6 )
case AF_INET6:
len = sizeof( struct sockaddr_in6 );
family = HB_SOCKET_AF_INET6;
break;
# endif
# if defined( AF_INET )
case AF_INET:
len = sizeof( struct sockaddr_in );
family = HB_SOCKET_AF_INET;
break;
# endif
default:
len = 0;
break;
}
hb_arraySetNI( pItem, HB_SOCKET_IFINFO_FAMILY, family );
if( len )
{
hb_socketArraySetInetAddr( pItem, HB_SOCKET_IFINFO_ADDR,
&pifr->ifr_addr, len );
# if defined( SIOCGIFNETMASK )
# ifndef ifr_netmask
# define ifr_netmask ifr_addr
# endif
if( ioctl( sd, SIOCGIFNETMASK, pifr ) != -1 )
hb_socketArraySetInetAddr( pItem, HB_SOCKET_IFINFO_NETMASK,
&pifr->ifr_netmask, len );
# endif
# if defined( SIOCGIFBRDADDR )
if( flags & IFF_BROADCAST )
{
if( ioctl( sd, SIOCGIFBRDADDR, pifr ) != -1 )
hb_socketArraySetInetAddr( pItem, HB_SOCKET_IFINFO_BROADCAST,
&pifr->ifr_broadaddr, len );
}
# endif
# if defined( SIOCGIFDSTADDR )
if( flags & IFF_POINTOPOINT )
{
if( ioctl( sd, SIOCGIFDSTADDR, pifr ) != -1 )
hb_socketArraySetInetAddr( pItem, HB_SOCKET_IFINFO_P2PADDR,
&pifr->ifr_dstaddr, len );
}
# endif
# if defined( SIOCGIFHWADDR )
# ifndef ifr_hwaddr
# define ifr_hwaddr ifr_addr
# endif
if( ioctl( sd, SIOCGIFHWADDR, pifr ) != -1 )
{
char hwaddr[ 24 ];
unsigned char * data;
data = ( unsigned char * ) &pifr->ifr_hwaddr.sa_data[0];
hb_snprintf( hwaddr, sizeof( hwaddr ),
"%02X:%02X:%02X:%02X:%02X:%02X",
data[ 0 ], data[ 1 ], data[ 2 ],
data[ 3 ], data[ 4 ], data[ 5 ] );
hb_arraySetC( pItem, HB_SOCKET_IFINFO_HWADDR, hwaddr );
}
# elif defined( SIOCGENADDR )
if( ioctl( sd, SIOCGENADDR, pifr ) != -1 )
{
char hwaddr[ 24 ];
unsigned char * data;
data = ( unsigned char * ) &pifr->ifr_enaddr[0];
hb_snprintf( hwaddr, sizeof( hwaddr ),
"%02X:%02X:%02X:%02X:%02X:%02X",
data[ 0 ], data[ 1 ], data[ 2 ],
data[ 3 ], data[ 4 ], data[ 5 ] );
hb_arraySetC( pItem, HB_SOCKET_IFINFO_HWADDR, hwaddr );
}
# endif
}
flags = ( ( flags & IFF_UP ) ?
HB_SOCKET_IFF_UP : 0 ) |
( ( flags & IFF_BROADCAST ) ?
HB_SOCKET_IFF_BROADCAST : 0 ) |
( ( flags & IFF_LOOPBACK ) ?
HB_SOCKET_IFF_LOOPBACK : 0 ) |
( ( flags & IFF_POINTOPOINT ) ?
HB_SOCKET_IFF_POINTOPOINT : 0 ) |
( ( flags & IFF_MULTICAST ) ?
HB_SOCKET_IFF_MULTICAST : 0 );
hb_arraySetNI( pItem, HB_SOCKET_IFINFO_FLAGS, flags );
if( pArray == NULL )
pArray = hb_itemArrayNew( 0 );
hb_arrayAddForward( pArray, pItem );
}
}
hb_xfree( buf );
hb_socketClose( sd );
}
if( pItem )
hb_itemRelease( pItem );
#else
int iTODO;
HB_SYMBOL_UNUSED( af );
HB_SYMBOL_UNUSED( fNoAliases );
#endif
return pArray;
}
#endif /* !HB_SOCKET_OFF */

View File

@@ -207,6 +207,8 @@ void * hb_libSymAddr( PHB_ITEM pDynLib, const char * pszSymbol )
return ( void * ) pProcAddr;
#elif defined( HB_HAS_DLFCN )
return dlsym( hDynLib, pszSymbol );
#else
HB_SYMBOL_UNUSED( pszSymbol );
#endif
}
return NULL;

View File

@@ -512,7 +512,7 @@ static PHB_TASKINFO hb_taskNew( long stack_size )
pTask = ( PHB_TASKINFO ) memset( hb_xgrab( sizeof( HB_TASKINFO ) ), 0,
sizeof( HB_TASKINFO ) );
pTask->stack = hb_xgrab( stack_size );
pTask->stack = ( char * ) hb_xgrab( stack_size );
stack_size += ( HB_PTRDIFF ) pTask->stack;
stack_size &= ~( HB_TASK_STACK_ALIGN - 1 );