Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //=== platform specific
- #include <common/pgas_platform.h>
- #if defined ( _PLATFORM_LINUX_)
- #include <netinet/ether.h>
- //#include <sys/ioctl.h>
- #include <net/if.h>
- #elif defined ( _PLATFORM_WINDOWS_)
- //#include <winsock2.h>
- #include <iphlpapi.h>
- #elif defined ( _PLATFORM_IOS_)
- //#include <sys/types.h>
- //#include <sys/socket.h>
- #include <ifaddrs.h>
- //#include <sys/ioctl.h>
- #include <net/if.h>
- #endif
- //=== libpgas
- #include "protocol_base.h"
- //=== libprotocol
- #include "sys/SYS_network_utils.h"
- //=============================================================================
- // local trace defines
- //=============================================================================
- #undef _FORCE_TRACE_DEBUG_
- #undef _ENABLE_TRACE_DEBUG_
- #undef _DISABLE_TRACE_WARNINGS_
- #undef _BREAK_ON_ERROR_
- #undef _BACKTRACE_ON_ERROR_
- //=
- //#define _FORCE_TRACE_DEBUG_
- #define _ENABLE_TRACE_DEBUG_
- //#define _DISABLE_TRACE_WARNINGS_
- //#define _BREAK_ON_ERROR_
- //#define _BACKTRACE_ON_ERROR_
- #include <tools/pgas_trace.h>
- //=
- #undef TLS_LOG_MYMODULE
- #define TLS_LOG_MYMODULE TLS_LOG_MODULE_PROTOCOL
- //=============================================================================
- namespace pga
- {
- namespace protocol
- {
- INT32 GetNbNetworkInterface( )
- {
- INT32 ret = PRT_FAILED;
- #if defined (_PLATFORM_LINUX_)
- struct ifconf ifc;
- struct ifreq ifr[ 32 ];
- int sock = socket(AF_INET, SOCK_DGRAM, 0);
- if (sock >= 0)
- {
- // demande des interfaces disponibles
- ifc.ifc_buf = (char *)ifr;
- ifc.ifc_len = sizeof(ifr);
- if (ioctl(sock, SIOCGIFCONF, &ifc) >= 0)
- {
- ret = ifc.ifc_len / sizeof(struct ifreq);
- }
- else
- {
- PGAS_ERROR(("<GetNbNetworkInterface> ioctl(SIOCGIFCONF)" ));
- }
- close(sock);
- }
- else
- {
- PGAS_ERROR(("<GetNbNetworkInterface> socket() " ));
- }
- #elif defined (_PLATFORM_WINDOWS_)
- //ECP 1ere version, mais risque car GetNumberOfInterfaces ne compte pas le loopback
- //DWORD dwNombre;
- //if (GetNumberOfInterfaces(&dwNombre) != NO_ERROR)
- // ret = dwNombre;
- //ECP 2eme version, sans risque car elle utilise la meme API que GetConfigurationInterface()
- PIP_ADAPTER_INFO adapter_info_p , adapter_p = NULL;
- adapter_info_p = (IP_ADAPTER_INFO *)malloc(sizeof(IP_ADAPTER_INFO));
- if ( adapter_info_p != NULL)
- {
- ULONG outbuf_len = sizeof(IP_ADAPTER_INFO);
- if ( GetAdaptersInfo( adapter_info_p , &outbuf_len ) == ERROR_BUFFER_OVERFLOW ) // buffer trop petit
- {
- free( adapter_info_p );
- adapter_info_p = (IP_ADAPTER_INFO *)malloc( outbuf_len );
- if ( adapter_info_p == NULL )
- {
- PGAS_ERROR(("< GetNbNetworkInterface > : memory allocation failed !"));
- goto fin;
- }
- }
- DWORD retval = 0;
- if ( ( retval = GetAdaptersInfo( adapter_info_p , &outbuf_len ) ) == NO_ERROR )
- {
- adapter_p = adapter_info_p;
- ret = 0;
- do {ret++;}
- while (( adapter_p = adapter_p->Next));
- }
- else
- {
- PGAS_ERROR(( "< GetNbNetworkInterface > : GetAdaptersInfo() returned error %d !" , retval ));
- }
- }
- else
- {
- PGAS_ERROR(( "< GetNbNetworkInterface > : memory allocation failed !" ));
- }
- fin:
- free( adapter_info_p );
- #elif defined ( _PLATFORM_IOS_ )
- struct ifaddrs * ifap , * myifap = NULL;
- int value = getifaddrs( &ifap);
- if ( value == 0 )
- {
- myifap = ifap;
- ret = 0;
- while ( myifap )
- {
- if ( myifap->ifa_addr->sa_family == AF_INET ) ret++;
- myifap = myifap->ifa_next;
- }
- freeifaddrs( ifap );
- }
- else
- {
- PGAS_ERROR(("Erreur getifaddrs %d" , errno));
- }
- #endif // defined (_PLATFORM_LINUX_) / defined (_PLATFORM_WINDOWS_)
- return ret;
- }
- //=================================================================================
- //=================================================================================
- //=================================================================================
- // GetConfigurationInterface
- // permet de recuperer les parametres d'une interface donnee
- PRT_RESULT
- //GetConfigurationNetworkInterface( int _interface_index , char * _name_sz , char * _ip_sz , char * _mask_sz , char * _broadcast_sz , char * _mac_sz , size_t _size_l )
- GetConfigurationNetworkInterface( INT32 _interface_index, CString& _out_name_str, CString& _out_ip_str, CString& _out_mask_str, CString& _out_broadcast_str, CString& _out_mac_str )
- {
- PRT_RESULT ret = PRT_FAILED;
- _out_name_str.Empty();
- _out_ip_str.Empty();
- _out_mask_str.Empty();
- _out_broadcast_str.Empty();
- #if defined (_PLATFORM_LINUX_) //|| defined(_PLATFORM_IOS_)
- struct ifconf ifc;
- struct ifreq ifr[ 32 ];
- int sock = socket(AF_INET, SOCK_DGRAM, 0);
- if (sock >= 0)
- {
- // demande des interfaces disponibles
- ifc.ifc_buf = (char *)ifr;
- ifc.ifc_len = sizeof(ifr);
- if (ioctl(sock, SIOCGIFCONF, &ifc) >= 0)
- {
- /*
- if ( _name_sz )
- {
- pgas_strncpy( _name_sz , ifr[ _interface_index ].ifr_name, _size_l );
- }
- */
- _out_name_str = ifr[ _interface_index ].ifr_name;
- /*
- if ( _ip_sz )
- {
- pgas_strncpy( _ip_sz , inet_ntoa(((struct sockaddr_in *)&ifr[ _interface_index ].ifr_addr)->sin_addr),_size_l );
- }
- */
- _out_ip_str = inet_ntoa(((struct sockaddr_in *)&ifr[ _interface_index ].ifr_addr)->sin_addr);
- /*
- if ( _mask_sz )
- {
- if ( ioctl( sock , SIOCGIFNETMASK , &ifr[ _interface_index ] ) >= 0 )
- {
- pgas_strncpy( _mask_sz , inet_ntoa(((struct sockaddr_in *)&ifr[ _interface_index ].ifr_addr)->sin_addr),_size_l );
- }
- else
- {
- PGAS_WARNING(("<GetConfigurationNetworkInterface> ioctl(SIOCGIFNETMASK): "));
- }
- }
- */
- if ( ioctl( sock , SIOCGIFNETMASK , &ifr[ _interface_index ] ) >= 0 )
- {
- _out_mask_str = inet_ntoa(((struct sockaddr_in *)&ifr[ _interface_index ].ifr_addr)->sin_addr);
- }
- else
- {
- PGAS_WARNING(("< GetConfigurationNetworkInterface > ioctl(SIOCGIFNETMASK) failed !"));
- }
- /*
- if ( _broadcast_sz )
- {
- if ( ioctl( sock , SIOCGIFBRDADDR , &ifr[ _interface_index ] ) >= 0 )
- {
- pgas_strncpy( _broadcast_sz , inet_ntoa(((struct sockaddr_in *)&ifr[ _interface_index ].ifr_broadaddr)->sin_addr), _size_l );
- }
- else
- {
- PGAS_WARNING(("<GetConfigurationNetworkInterface> ioctl(SIOCGIFBRDADDR): "));
- }
- }
- */
- if ( ioctl( sock , SIOCGIFBRDADDR , &ifr[ _interface_index ] ) >= 0 )
- {
- _out_broadcast_str = inet_ntoa(((struct sockaddr_in *)&ifr[ _interface_index ].ifr_broadaddr)->sin_addr);
- }
- else
- {
- PGAS_WARNING(("< GetConfigurationNetworkInterface > ioctl(SIOCGIFBRDADDR) failed !"));
- }
- #if 0
- if ( _mac_sz )
- {
- #if !defined (_PLATFORM_FREEBSD_) && !defined (_PLATFORM_ANDROID_)
- /*
- if ( ioctl( sock , SIOCGIFHWADDR , &ifr[ _interface_index ] ) >= 0 )
- {
- //pgas_strncpy( _mac_sz , ether_ntoa((struct ether_addr *)&ifr[ _interface_index ].ifr_hwaddr.sa_data ) , _size_l );
- _out_mac_str
- }
- else
- {
- PGAS_WARNING(("<GetConfigurationNetworkInterface> ioctl(SIOCGIFHWADDR): "));
- }
- */
- #else
- pgas_snprintf( _mac_sz , sizeof( _mac_sz ) , "" );
- #endif
- }
- #endif
- #if !defined (_PLATFORM_FREEBSD_) && !defined (_PLATFORM_ANDROID_)
- /*
- if ( ioctl( sock , SIOCGIFHWADDR , &ifr[ _interface_index ] ) >= 0 )
- {
- _out_mac_str = ether_ntoa((struct ether_addr *)&ifr[ _interface_index ].ifr_hwaddr.sa_data );
- }
- else
- {
- PGAS_WARNING(("< GetConfigurationNetworkInterface > ioctl(SIOCGIFHWADDR) failed !"));
- }
- */
- #endif
- ret = PRT_SUCCESS;
- }
- else
- {
- PGAS_ERROR(("<GetConfigurationNetworkInterface> ioctl(SIOCGIFCONF)" ));
- }
- close(sock);
- }
- else
- {
- PGAS_ERROR(("<GetConfigurationNetworkInterface> socket()" ));
- }
- #elif defined (_PLATFORM_WINDOWS_)
- PIP_ADAPTER_INFO adapter_info_p , adapter_p = NULL;
- adapter_info_p = (IP_ADAPTER_INFO *)malloc( sizeof(IP_ADAPTER_INFO) );
- if ( adapter_info_p != NULL )
- {
- ULONG outbuf_len = sizeof(IP_ADAPTER_INFO);
- if ( GetAdaptersInfo( adapter_info_p , &outbuf_len ) == ERROR_BUFFER_OVERFLOW ) // buffer trop petit
- {
- free( adapter_info_p );
- adapter_info_p = (IP_ADAPTER_INFO *)malloc( outbuf_len+1 );
- if (adapter_info_p == NULL)
- {
- PGAS_ERROR(("< CPRTPapClient::GetConfigurationInterface() > : memory allocation failed !"));
- goto FINALIZE;
- }
- }
- DWORD retval = 0;
- if ( ( retval = GetAdaptersInfo(adapter_info_p, &outbuf_len ) ) == NO_ERROR)
- {
- adapter_p = adapter_info_p;
- INT32 courant_l = 0;
- /*
- while ( courant_l != _interface_index ) // on n'est pas sur l'interface demandee
- if (( adapter_p = adapter_p->Next)) // la fin de liste chainee n'est pas encore atteinte
- courant_l++; // interface suivante
- else break; // la liste chainee est finie
- */
- while ( (courant_l != _interface_index) && ((adapter_p = adapter_p->Next) != NULL) ) ++courant_l; // interface suivante
- if ( courant_l == _interface_index ) // on a trouve l'interface
- {
- /*
- if ( _name_sz )
- {
- pgas_strncpy( _name_sz , adapter_p->Description, _size_l );
- }
- */
- _out_name_str = adapter_p->Description;
- /*
- if ( _ip_sz )
- {
- pgas_strncpy( _ip_sz , adapter_p->IpAddressList.IpAddress.String, _size_l );
- }
- */
- _out_ip_str = adapter_p->IpAddressList.IpAddress.String;
- /*
- if ( _mask_sz )
- {
- pgas_strncpy( _mask_sz , adapter_p->IpAddressList.IpMask.String, _size_l );
- }
- */
- _out_mask_str = adapter_p->IpAddressList.IpMask.String;
- /*
- if ( _broadcast_sz )
- { // GetAdaptersInfo() ne permet pas d'avoir l'adresse de broadcast, alors on la calcule
- UINT32 ulMasque = inet_addr( _mask_sz ),
- ulReseau = inet_addr( _ip_sz),
- ulBroadcast = ulReseau | (~ulMasque);
- in_addr iaBroadcast;
- iaBroadcast.s_addr = ulBroadcast;
- pgas_strncpy( _broadcast_sz , inet_ntoa(iaBroadcast) , _size_l );
- }
- */
- UINT32 ulMasque = inet_addr( _out_mask_str.GetChars() );
- UINT32 ulReseau = inet_addr( _out_ip_str.GetChars() );
- UINT32 ulBroadcast = ulReseau | (~ulMasque);
- in_addr iaBroadcast;
- iaBroadcast.s_addr = ulBroadcast;
- _out_broadcast_str = inet_ntoa( iaBroadcast );
- /*
- if ( _mac_sz )
- {
- CHAR* mymac_sz = _mac_sz;
- for ( UINT i = 0; ( i < adapter_p->AddressLength) && ( mymac_sz < &_mac_sz[ _size_l ] ) ; i++ )
- {
- if (i == ( adapter_p->AddressLength - 1))
- {
- mymac_sz += pgas_snprintf(mymac_sz , _size_l - ( mymac_sz - _mac_sz ) , "%02X", (int)adapter_p->Address[i]);
- }
- else
- {
- mymac_sz += pgas_snprintf(mymac_sz , _size_l - ( mymac_sz - _mac_sz ) , "%02X:", (int)adapter_p->Address[i]);
- }
- }
- PGAS_DEBUG( ("< GetConfigurationNetworkInterface > [ %d ] => MAC = '%s'", _interface_index, _mac_sz) );
- }
- */
- CString nibble;
- for ( UINT i = 0; i < adapter_p->AddressLength ; i++ )
- {
- nibble.Format( "%02X", adapter_p->Address[i] );
- _out_mac_str += nibble;
- if ( i < ( adapter_p->AddressLength-1) )
- {
- _out_mac_str += ':';
- }
- }
- ret = PRT_SUCCESS;
- }
- else
- {
- PGAS_WARNING(( "<GetConfigurationNetworkInterface> : couldn't find configuration for interface index %d", _interface_index ));
- }
- }
- else
- {
- PGAS_ERROR(( "<GetConfigurationNetworkInterface> GetAdaptersInfo() returned error %d !" , retval ));
- }
- }
- else
- {
- PGAS_ERROR(( "< GetConfigurationNetworkInterface > : memory allocation failed !" ));
- }
- FINALIZE:
- free( adapter_info_p );
- #elif defined (_PLATFORM_IOS_)
- struct ifaddrs * ifap , * myifap = NULL;
- int value = getifaddrs( &ifap);
- if ( value == 0 )
- {
- myifap = ifap;
- int cpt = 0;
- int ok = false;
- while ( myifap )
- {
- if ( myifap->ifa_addr->sa_family == AF_INET )
- {
- if ( cpt == _interface_index)
- {
- ok = true;
- break;
- }
- else
- {
- cpt++;
- }
- }
- myifap = myifap->ifa_next;
- }
- if ( ok )
- {
- /*
- if ( _name_sz )
- {
- pgas_strncpy( _name_sz , myifap->ifa_name, _size_l );
- }
- */
- _out_name_str = myifap->ifa_name;
- /*
- if ( _ip_sz )
- {
- pgas_strncpy( _ip_sz , inet_ntoa(((struct sockaddr_in *)myifap->ifa_addr)->sin_addr),_size_l );
- }
- */
- _out_ip_str = inet_ntoa(((struct sockaddr_in *)myifap->ifa_addr)->sin_addr);
- /*
- if ( _mask_sz )
- {
- pgas_strncpy( _mask_sz , inet_ntoa(((struct sockaddr_in *)myifap->ifa_netmask)->sin_addr),_size_l );
- }
- */
- _out_mask_str = inet_ntoa(((struct sockaddr_in *)myifap->ifa_netmask)->sin_addr);
- /*
- if ( _broadcast_sz )
- { // GetAdaptersInfo() ne permet pas d'avoir l'adresse de broadcast, alors on la calcule
- ULONG ulMasque = inet_addr( _mask_sz ),
- ulReseau = inet_addr( _ip_sz),
- ulBroadcast = ulReseau | (~ulMasque);
- in_addr iaBroadcast;
- iaBroadcast.s_addr = ulBroadcast;
- pgas_strncpy( _broadcast_sz , inet_ntoa(iaBroadcast) , _size_l );
- }
- */
- UINT32 ulMasque = inet_addr( _out_mask_str.GetChars() );
- UINT32 ulReseau = inet_addr( _out_ip_str.GetChars() );
- UINT32 ulBroadcast = ulReseau | (~ulMasque);
- in_addr iaBroadcast;
- iaBroadcast.s_addr = ulBroadcast;
- _out_broadcast_str = inet_ntoa( iaBroadcast );
- ret = PRT_SUCCESS;
- }
- freeifaddrs( ifap );
- }
- else
- {
- PGAS_ERROR(("< GetConfigurationNetworkInterface > : getifaddrs returned error %d !", errno));
- }
- #endif
- return ret;
- }
- /*
- * Returns address of interface matching with dest IP addr
- *
- * For example, I want to dialog with 172.17.4.5
- *
- * There is 2 interfaces :
- * - 10.4.30.1 / 255.0.0.0
- * - 172.17.0.141 / 255.255.0.0
- *
- * This function will choose the second interface because dest and itf are on the same sub-network.
- *
- *
- * Doesn't work if there is gateway on 10.4.30.1 and if we want to use 10.4.30.1
- *
- *
- */
- PRT_RESULT GetMatchingInterface( const CHAR* _dest_ip_sz, CString &_out_itf_ip_str )
- {
- PRT_RESULT ret = PRT_FAILED;
- _out_itf_ip_str.Empty();
- //if ( _dest == NULL || _itf == NULL ) return PRT_FAILED;
- if ( _dest_ip_sz == NULL ) return PRT_FAILED; // DRS : replace by "255.255.255.255" ???
- INT32 nb = GetNbNetworkInterface();
- if ( nb != PRT_FAILED )
- {
- for ( INT32 i = 0 ; i < nb ; i++ )
- {
- /*
- CHAR name_sz[128]; name_sz[0] = '\0';
- CHAR ip_sz[128]; ip_sz[0] = '\0';
- CHAR mask_sz[128]; mask_sz[0] = '\0';
- CHAR broadcast_sz[128]; broadcast_sz[0] = '\0';
- CHAR mac_sz[128]; mac_sz[0] = '\0';
- */
- CString name_str;
- CString ip_str;
- CString mask_str;
- CString broadcast_str;
- CString mac_str;
- //if ( PRT_SUCCESS == GetConfigurationNetworkInterface( i , name_sz , ip_sz , mask_sz , broadcast_sz , mac_sz , 128 ) )
- if ( PRT_SUCCESS == GetConfigurationNetworkInterface( i, name_str, ip_str, mask_str, broadcast_str, mac_str ) )
- {
- // recuperer mask
- /*
- UINT32 mask = inet_addr( mask_sz );
- UINT32 dest = inet_addr( _dest );
- UINT32 ip = inet_addr( ip_sz );
- */
- UINT32 dest = inet_addr( _dest_ip_sz );
- UINT32 ip = inet_addr( ip_str.GetChars() );
- UINT32 mask = inet_addr( mask_str.GetChars() );
- if ( ((dest & mask) == (ip & mask)) && ((ip != 0) || (mask != 0)) )
- {
- //pgas_sprintf( _itf , ip_sz );
- _out_itf_ip_str = ip_str;
- return PRT_SUCCESS;
- }
- }
- }
- }
- return ret;
- }
- #if defined ( _PLATFORM_WINDOWS_ )
- void PrintBufEntry ( WSAPROTOCOL_INFO *pProtocolBuf )
- {
- int j;
- #if defined ( _PLATFORM_WINDESKTOP_ )
- PGAS_TRACE((">> Protocol <%s>", pProtocolBuf->szProtocol));
- #elif defined ( _PLATFORM_WINCE_ )
- char message_sz[1024];
- int cw=lstrlenW( pProtocolBuf->szProtocol );
- WideCharToMultiByte(CP_ACP,0,pProtocolBuf->szProtocol ,cw,message_sz,1024,NULL,NULL);
- PGAS_TRACE(("Protocol <%s>", message_sz));
- #endif
- /* // A guid is the same as a uuid.
- unsigned char *pszUuid;
- UuidToString(&pProtocolBuf->ProviderId, &pszUuid);
- PGAS_TRACE((" ProviderId {%s}", pszUuid));
- RpcStringFree(&pszUuid);
- */
- if (!pProtocolBuf->dwServiceFlags1)
- PGAS_TRACE((" dwServiceFlags1: 0"));
- else
- PGAS_TRACE((" dwServiceFlags1: 0x%08X",
- pProtocolBuf->dwServiceFlags1));
- // Check which bit flags are set.
- if (pProtocolBuf->dwServiceFlags1 & XP1_CONNECTIONLESS)
- PGAS_TRACE((" XP1_CONNECTIONLESS"));
- if (pProtocolBuf->dwServiceFlags1 & XP1_GUARANTEED_DELIVERY)
- PGAS_TRACE((" XP1_GUARANTEED_DELIVERY"));
- if (pProtocolBuf->dwServiceFlags1 & XP1_GUARANTEED_ORDER)
- PGAS_TRACE((" XP1_GUARANTEED_ORDER"));
- if (pProtocolBuf->dwServiceFlags1 & XP1_MESSAGE_ORIENTED)
- PGAS_TRACE((" XP1_MESSAGE_ORIENTED"));
- if (pProtocolBuf->dwServiceFlags1 & XP1_PSEUDO_STREAM)
- PGAS_TRACE((" XP1_PSEUDO_STREAM"));
- if (pProtocolBuf->dwServiceFlags1 & XP1_GRACEFUL_CLOSE)
- PGAS_TRACE((" XP1_GRACEFUL_CLOSE"));
- if (pProtocolBuf->dwServiceFlags1 & XP1_EXPEDITED_DATA)
- PGAS_TRACE((" XP1_EXPEDITED_DATA"));
- if (pProtocolBuf->dwServiceFlags1 & XP1_CONNECT_DATA)
- PGAS_TRACE((" XP1_CONNECT_DATA"));
- if (pProtocolBuf->dwServiceFlags1 & XP1_DISCONNECT_DATA)
- PGAS_TRACE((" XP1_DISCONNECT_DATA"));
- if (pProtocolBuf->dwServiceFlags1 & XP1_SUPPORT_BROADCAST)
- PGAS_TRACE((" XP1_SUPPORT_BROADCAST"));
- if (pProtocolBuf->dwServiceFlags1 & XP1_SUPPORT_MULTIPOINT)
- PGAS_TRACE((" XP1_SUPPORT_MULTIPOINT"));
- if (pProtocolBuf->dwServiceFlags1 & XP1_MULTIPOINT_CONTROL_PLANE)
- PGAS_TRACE((" XP1_MULTIPOINT_CONTROL_PLANE"));
- if (pProtocolBuf->dwServiceFlags1 & XP1_MULTIPOINT_DATA_PLANE)
- PGAS_TRACE((" XP1_MULTIPOINT_DATA_PLANE"));
- if (pProtocolBuf->dwServiceFlags1 & XP1_QOS_SUPPORTED)
- PGAS_TRACE((" XP1_QOS_SUPPORTED"));
- if (pProtocolBuf->dwServiceFlags1 & XP1_INTERRUPT)
- PGAS_TRACE((" XP1_INTERRUPT"));
- if (pProtocolBuf->dwServiceFlags1 & XP1_UNI_SEND)
- PGAS_TRACE((" XP1_UNI_SEND"));
- if (pProtocolBuf->dwServiceFlags1 & XP1_UNI_RECV)
- PGAS_TRACE((" XP1_UNI_RECV"));
- if (pProtocolBuf->dwServiceFlags1 & XP1_IFS_HANDLES)
- PGAS_TRACE((" XP1_IFS_HANDLES"));
- if (pProtocolBuf->dwServiceFlags1 & XP1_PARTIAL_MESSAGE)
- PGAS_TRACE((" XP1_PARTIAL_MESSAGE"));
- PGAS_TRACE((" dwServiceFlags2: reserved"));
- PGAS_TRACE((" dwServiceFlags3: reserved"));
- PGAS_TRACE((" dwServiceFlags4: reserved"));
- PGAS_TRACE((" dwProviderFlags:"));
- if (pProtocolBuf->dwProviderFlags & PFL_MULTIPLE_PROTO_ENTRIES)
- PGAS_TRACE((" PFL_MULTIPLE_PROTO_ENTRIES"));
- if (pProtocolBuf->dwProviderFlags & PFL_RECOMMENDED_PROTO_ENTRY)
- PGAS_TRACE((" PFL_RECOMMENDED_PROTO_ENTRY"));
- if (pProtocolBuf->dwProviderFlags & PFL_HIDDEN)
- PGAS_TRACE((" PFL_HIDDEN"));
- if (pProtocolBuf->dwProviderFlags & PFL_MATCHES_PROTOCOL_ZERO)
- PGAS_TRACE((" PFL_MATCHES_PROTOCOL_ZERO"));
- PGAS_TRACE((" dwCatalogEntryId = %u", pProtocolBuf->dwCatalogEntryId));
- PGAS_TRACE((" ProtocolChain.ChainLen = %d ",
- pProtocolBuf->ProtocolChain.ChainLen));
- if (1 == pProtocolBuf->ProtocolChain.ChainLen)
- PGAS_TRACE((" ==> this is a base service provider"));
- else if (pProtocolBuf->ProtocolChain.ChainLen > 1)
- {
- PGAS_TRACE((" ==> ProtocolChain layered to base protocol"));
- for (j=0; j<pProtocolBuf->ProtocolChain.ChainLen; j++)
- PGAS_TRACE((" Chain Catalog Entry Id = %u",
- pProtocolBuf->ProtocolChain.ChainEntries[j]));
- }
- else if (0 == pProtocolBuf->ProtocolChain.ChainLen)
- PGAS_TRACE((" ==> this is a layered service provider"));
- else
- PGAS_TRACE((" Invalid"));
- PGAS_TRACE((" iVersion = %d", pProtocolBuf->iVersion));
- PGAS_TRACE((" iAddressFamily = %d", pProtocolBuf->iAddressFamily));
- PGAS_TRACE((" iMaxSockAddr = %d", pProtocolBuf->iMaxSockAddr));
- PGAS_TRACE((" iMinSockAddr = %d", pProtocolBuf->iMinSockAddr));
- // iProtocols returns a negative number for Microsoft NetBIOS
- // service providers corresponding to the lana number * -1 (for
- // example, -2 implies lana 2), except for lana 0 which is equal to
- // 0x80000000 because protocol 0 is reserved for special use.
- PGAS_TRACE((" iProtocol = %d", pProtocolBuf->iProtocol));
- PGAS_TRACE((" iProtocolMaxOffset = %d",
- pProtocolBuf->iProtocolMaxOffset));
- PGAS_TRACE((" iNetworkByteOrder = %s",
- ((pProtocolBuf->iNetworkByteOrder == LITTLEENDIAN) ?
- "LITTLEENDIAN" : "BIGENDIAN")));
- PGAS_TRACE((" iSecurityScheme = %d", pProtocolBuf->iSecurityScheme));
- PGAS_TRACE((" dwMessageSize = %u", pProtocolBuf->dwMessageSize));
- PGAS_TRACE((" dwProviderReserved = reserved"));
- }
- #endif
- int GetCapabilities( )
- {
- int ret = PRT_FAILED;
- #if defined ( _PLATFORM_WINDOWS_ )
- int i, nRet;
- DWORD dwErr;
- WSAPROTOCOL_INFO *lpProtocolBuf = NULL;
- DWORD dwBufLen = 0;
- // First, have WSAEnumProtocols tell you how big a buffer you
- // need.
- nRet = WSAEnumProtocols(NULL, lpProtocolBuf, &dwBufLen);
- if (SOCKET_ERROR != nRet)
- printf("WSAEnumProtocols: should not have succeeded\n");
- else if (WSAENOBUFS != (dwErr = WSAGetLastError()))
- // WSAEnumProtocols failed for some reason not relating
- // to buffer size - also odd.
- printf("WSAEnumProtocols(1): %d\n", WSAGetLastError());
- else
- {
- // WSAEnumProtocols failed for the "expected" reason.
- // Now you need to allocate a buffer that is the right size.
- lpProtocolBuf = (WSAPROTOCOL_INFO *)malloc(dwBufLen);
- if (lpProtocolBuf)
- {
- // Now you can call WSAEnumProtocols again with the
- // expectation that it will succeed
- // because you have allocated a big enough buffer.
- nRet = WSAEnumProtocols(NULL, lpProtocolBuf, &dwBufLen);
- if (SOCKET_ERROR == nRet)
- printf("WSAEnumProtocols(3): %d\n",
- WSAGetLastError());
- else
- {
- // Enumerate the protocols.
- for (i=0; i<nRet; i++)
- PrintBufEntry(&lpProtocolBuf[i]);
- }
- free(lpProtocolBuf);
- }
- }
- #endif
- return ret;
- }
- } // namespace protocol
- } // namespace pga
Add Comment
Please, Sign In to add comment