diff --git a/harbour/ChangeLog b/harbour/ChangeLog index ac2755a72b..f11133f78d 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -16,6 +16,19 @@ The license applies to all entries newer than 2009-04-28. */ +2011-02-07 14:43 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) + * harbour/src/rtl/gttrm/gttrm.c + ! fixed typo in key escape sequence + + * harbour/include/hbsocket.h + * harbour/src/rtl/hbsocket.c + + added new C function: + char * hb_socketGetHostName( const void * pSockAddr, unsigned len ); + + * harbour/src/rtl/hbsockhb.c + + added new PRG function: + HB_SOCKETGETHOSTNAME( ) --> + 2011-02-07 10:54 UTC+0100 Viktor Szakats (harbour.01 syenar.hu) * utils/hbmk2/hbmk2.prg ! Do not add .hbx file to input file list if the file doesn't diff --git a/harbour/include/hbsocket.h b/harbour/include/hbsocket.h index 4cc78edf92..2411443f71 100644 --- a/harbour/include/hbsocket.h +++ b/harbour/include/hbsocket.h @@ -82,6 +82,7 @@ extern HB_EXPORT HB_BOOL hb_socketResolveInetAddr( void ** pSockAddr, unsig extern HB_EXPORT char * hb_socketResolveAddr( const char * szAddr, int af ); extern HB_EXPORT PHB_ITEM hb_socketGetHosts( const char * szAddr, int af ); extern HB_EXPORT PHB_ITEM hb_socketGetAliases( const char * szAddr, int af ); +extern HB_EXPORT char * hb_socketGetHostName( const void * pSockAddr, unsigned len ); extern HB_EXPORT PHB_ITEM hb_socketGetIFaces( int af, HB_BOOL fNoAliases ); extern HB_EXPORT int hb_socketAddrGetPort( const void * pSockAddr, unsigned len ); extern HB_EXPORT HB_BOOL hb_socketAddrFromItem( void ** pSockAddr, unsigned * puiLen, PHB_ITEM pAddrItm ); diff --git a/harbour/src/rtl/gttrm/gttrm.c b/harbour/src/rtl/gttrm/gttrm.c index 1e66a62de6..c6de9a0efb 100644 --- a/harbour/src/rtl/gttrm/gttrm.c +++ b/harbour/src/rtl/gttrm/gttrm.c @@ -2776,7 +2776,7 @@ static void init_keys( PHB_GTTRM pTerm ) { EXKEY_F8 |KEY_CTRLMASK|KEY_ALTMASK, "\033[f" }, /* kf20 */ { EXKEY_F9 |KEY_CTRLMASK|KEY_ALTMASK, "\033[g" }, /* kf21 */ { EXKEY_F10|KEY_CTRLMASK|KEY_ALTMASK, "\033[h" }, /* kf22 */ - { EXKEY_F11|KEY_CTRLMASK|KEY_ALTMASK, "\033[j" }, /* kf23 */ + { EXKEY_F11|KEY_CTRLMASK|KEY_ALTMASK, "\033[i" }, /* kf23 */ { EXKEY_F12|KEY_CTRLMASK|KEY_ALTMASK, "\033[j" }, /* kf24 */ { EXKEY_F1 |KEY_CTRLMASK, "\033[k" }, /* kf25 */ diff --git a/harbour/src/rtl/hbsocket.c b/harbour/src/rtl/hbsocket.c index 5d6037c757..dde9e4025a 100644 --- a/harbour/src/rtl/hbsocket.c +++ b/harbour/src/rtl/hbsocket.c @@ -80,6 +80,9 @@ platform supports getaddrinfo()/freeaddrinfo() functions: #define HB_HAS_ADDRINFO + platform supports getnameinfo() function: + #define HB_HAS_NAMEINFO + platform uses sockaddr structure which contains sa_len member: #define HB_HAS_SOCKADDR_SA_LEN @@ -122,6 +125,7 @@ # define HB_HAS_INET_NTOP # define HB_HAS_SOCKADDR_STORAGE # define HB_HAS_ADDRINFO +# define HB_HAS_NAMEINFO # endif # if !defined( __WATCOMC__ ) && !defined( HB_OS_BEOS ) && !defined( HB_OS_MINIX ) # define HB_HAS_INET6 @@ -181,6 +185,7 @@ # define HB_HAS_INET_NTOP # define HB_HAS_SOCKADDR_STORAGE # define HB_HAS_ADDRINFO +# define HB_HAS_NAMEINFO # define HB_HAS_INET6_ADDR_CONST /* # define HB_HAS_INET6 */ #endif @@ -2743,7 +2748,10 @@ int hb_socketSelect( PHB_ITEM pArrayRD, HB_BOOL fSetRD, return ret; } -/* DNS functions */ + +/* + * DNS functions + */ HB_BOOL hb_socketResolveInetAddr( void ** pSockAddr, unsigned * puiLen, const char * szAddr, int iPort ) { #if defined( AF_INET ) @@ -3045,6 +3053,55 @@ PHB_ITEM hb_socketGetAliases( const char * szAddr, int af ) return NULL; } +char * hb_socketGetHostName( const void * pSockAddr, unsigned len ) +{ + char * szResult = NULL; + int af = hb_socketGetAddrFamily( pSockAddr, len ); + + if( af != -1 ) + { +#if defined( HB_HAS_NAMEINFO ) + #if !defined( NI_MAXHOST ) + #define NI_MAXHOST 1025 + #endif + char szHost[ NI_MAXHOST ]; + int iResult; + + hb_vmUnlock(); + iResult = getnameinfo( pSockAddr, len, szHost, NI_MAXHOST, NULL, 0, 0 ); + hb_vmLock(); + if( iResult == 0 ) + szResult = hb_strdup( szHost ); +#else + struct hostent * he = NULL; + + if( af == AF_INET ) + { + const struct sockaddr_in * sa = ( const struct sockaddr_in * ) pSockAddr; + hb_vmUnlock(); + he = gethostbyaddr( ( const char * ) &sa->sin_addr, sizeof( sa->sin_addr ), af ); + hb_vmLock(); + } +#if defined( HB_HAS_INET6 ) + else if( af == AF_INET6 ) + { + const struct sockaddr_in6 * sa = ( const struct sockaddr_in6 * ) pSockAddr; + hb_vmUnlock(); + he = gethostbyaddr( ( const char * ) &sa->sin6_addr, sizeof( sa->sin6_addr ), af ); + hb_vmLock(); + } +#endif + if( he && he->h_name ) + szResult = hb_strdup( he->h_name ); +#endif + } + return szResult; +} + + +/* + * IFACEs + */ #if defined( HB_OS_WIN ) || ( defined( SIOCGIFCONF ) && \ !( defined( HB_OS_LINUX ) && defined( __WATCOMC__ ) ) ) static void hb_socketArraySetInetAddr( PHB_ITEM pItem, HB_SIZE nPos, diff --git a/harbour/src/rtl/hbsockhb.c b/harbour/src/rtl/hbsockhb.c index eac8862712..9e8d1a7a80 100644 --- a/harbour/src/rtl/hbsockhb.c +++ b/harbour/src/rtl/hbsockhb.c @@ -84,6 +84,7 @@ * HB_SOCKETSELECT( aRead, lSetRead, aWrite, lSetWrite, aExcep, lSetExcep, [ nTimeout = FOREVER ] ) --> nRet * HB_SOCKETRESOLVEINETADDR( cAddr, nPort ) --> aAddr | NIL * HB_SOCKETRESOLVEADDR( cAddr, [ nFamily = HB_SOCKET_AF_INET ] ) --> cResolved + * HB_SOCKETGETHOSTNAME( aAddr ) --> cHostName * HB_SOCKETGETHOSTS( cAddr, [ nFamily = HB_SOCKET_AF_INET ] ) --> aHosts * HB_SOCKETGETIFACES( [ nFamily ], [ lNoAliases ] ) --> aIfaces */ @@ -646,6 +647,24 @@ HB_FUNC( HB_SOCKETRESOLVEADDR ) hb_retc( "" ); } +HB_FUNC( HB_SOCKETGETHOSTNAME ) +{ + void * addr; + unsigned int len; + + if( socketaddrParam( 1, &addr, &len ) ) + { + char * szHostName = hb_socketGetHostName( addr, len ); + + if( addr ) + hb_xfree( addr ); + if( szHostName ) + hb_retc_buffer( szHostName ); + else + hb_retc_null(); + } +} + HB_FUNC( HB_SOCKETGETHOSTS ) { PHB_ITEM pItem;