More than u ever wanted to know - Interfaces and Adapters

Share your advanced PureBasic knowledge/code with the community.
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

More than u ever wanted to know - Interfaces and Adapters

Post by SFSxOI »

Been a while since I posted, been really busy and traveling a lot. Anyway, was working on a project for work and finally finished it. While working on the project I put together a sort of 'test bed' for checking out various things to do with adpaters and interfaces for inclusion in the final project. Although I can't share the final project code because its now property of my employer and is now proprietary, and normally I can't share anything to do with developing a proprietary project, I did get permission to share the "rough" basic adapter and interface 'test bed' code, so here it is. There may still be a few bugs in it that I did not clean up in the 'test bed' code presented that were corrected for the final project code, but the following works and I hope it helps someone. Oh yeah, it was made with Windows 7 x86 in mind so some of it may not work on other versions. A few things in the include file are from forum code I collected over time, I don't remember who exactly they were from so credit for those things goes to the original posters, these items were only used in the 'test bed' code and did not appear in the final project code as they were later replaced with other things but I included them here because people would have the best chance of duplicating them for their own purposes, or maybe already have them, if they wanted to do so.

If a few things seem "disconnected" or "missing", or some of the comments seem odd or incomplete, its because I had to remove or change them for the posted code due to the proprietary requirements to be allowed to post the 'test bed' code and had to make it as 'generic' as possible before posting. This means that all the GUI stuff and the lists, along with some other things, were also removed but I put in a ton of debugs so you get the same information, so you can change it to suit your needs.

"interfaceinfo_enums_and_types.pbi"

Code: Select all

; this is XIncludeFile "interfaceinfo_enums_and_types.pbi"



; prototypes and init

Prototype PGetAdaptersAddresses(Family, Flags, Null, pAddresses, outBufLen)
Prototype PWSAAddressToString(lpsaAddress,dwAddressLength,lpProtocolInfo,lpszAddressString,lpdwAddressStringLength)
Prototype PConvertInterfaceLuidToIndex(pLUID, out_index)
Prototype PConvertInterfaceLuidToGuid(pLUID, out_guid)
Prototype PConvertConvertInterfaceGuidToLuid(pIn_GUID, pOut_LUID)
Prototype PGetIfEntry2(pIfRow)
Prototype PFreeMibTable(pIfRow)
Prototype PGetIpNetTable(pIpNetTable,pdwSize,bOrder)
Prototype PGetIpNetTable2(family, ptable)
Prototype PGetTeredoPort(torport)
Prototype PGetIpInterfaceTable(Family, Table)
Prototype PGetIpInterfaceEntry(in_out_pRow)
Prototype PInitializeIpInterfaceEntry(pRow)
Prototype Pif_indextoname(InterfaceIndex, InterfaceName)
Prototype PGetAdapterIndex(AdapterName, If_Index) ; AdapterName is LPWSTR A pointer to a Unicode string that specifies the name of the adapter
Prototype PGetIfTable2(pRow)
Prototype PRtlIpv6AddressToString(Addr, LPTSTR_S)
Prototype PRtlIpv4AddressToString(Addr, LPTSTR_S)
Prototype PInetNtop(Family, pAddr, pStringBuf, StringBufSize)
Prototype PGetIfStackTable(Tablex)
Prototype PGetIpNetEntry2(Row)
;Prototype PGetIpStatistics(pStats)
; 
;Prototype PZeroMemory(pIf_Row, size)
; 
Global GetIfEntry2.PGetIfEntry2
Global GetAdaptersAddresses.PGetAdaptersAddresses
Global ConvertInterfaceLuidToIndex.PConvertInterfaceLuidToIndex
Global ConvertInterfaceLuidToGuid.PConvertInterfaceLuidToGuid
Global ConvertInterfaceGuidToLuid.PConvertConvertInterfaceGuidToLuid
Global FreeMibTable.PFreeMibTable
Global WSAAddressToString.PWSAAddressToString
Global GetIpNetTable.PGetIpNetTable
Global GetIpNetTable2.PGetIpNetTable2
Global GetTeredoPort.PGetTeredoPort
Global GetIpInterfaceTable.PGetIpInterfaceTable
Global GetIpInterfaceEntry.PGetIpInterfaceEntry
Global InitializeIpInterfaceEntry.PInitializeIpInterfaceEntry
Global if_indextoname.Pif_indextoname
Global GetAdapterIndex.PGetAdapterIndex
Global GetIfTable2.PGetIfTable2
Global RtlIpv6AddressToString.PRtlIpv6AddressToString
Global RtlIpv4AddressToString.PRtlIpv4AddressToString
Global InetNtop.PInetNtop
Global GetIfStackTable.PGetIfStackTable
Global GetIpNetEntry2.PGetIpNetEntry2
;Global GetIpStatistics.PGetIpStatistics
;Global ZeroMemory.PZeroMemory

Procedure LoadLibraries()
Global Lib_iphlpapi.i, Lib_Winsock.i, Lib_Ntdll.i;, Lib_Kernel.i

Lib_iphlpapi = OpenLibrary(#PB_Any,"iphlpapi.dll")
If Lib_iphlpapi<> 0
  GetAdaptersAddresses.PGetAdaptersAddresses=GetFunction(Lib_iphlpapi,"GetAdaptersAddresses")
  ConvertInterfaceLuidToIndex.PConvertInterfaceLuidToIndex=GetFunction(Lib_iphlpapi,"ConvertInterfaceLuidToIndex")
  ConvertInterfaceLuidToGuid.PConvertInterfaceLuidToGuid=GetFunction(Lib_iphlpapi,"ConvertInterfaceLuidToGuid")
  ConvertInterfaceGuidToLuid.PConvertConvertInterfaceGuidToLuid=GetFunction(Lib_iphlpapi,"ConvertInterfaceGuidToLuid")
  GetIfEntry2.PGetIfEntry2=GetFunction(Lib_iphlpapi,"GetIfEntry2")
  FreeMibTable.PFreeMibTable=GetFunction(Lib_iphlpapi,"FreeMibTable")
  GetIpNetTable.PGetIpNetTable=GetFunction(Lib_iphlpapi,"GetIpNetTable")
  GetIpNetTable2.PGetIpNetTable2= GetFunction(Lib_iphlpapi,"GetIpNetTable2")
  GetTeredoPort.PGetTeredoPort=GetFunction(Lib_iphlpapi,"GetTeredoPort")
  GetIpInterfaceTable.PGetIpInterfaceTable=GetFunction(Lib_iphlpapi,"GetIpInterfaceTable")
  GetIpInterfaceEntry.PGetIpInterfaceEntry=GetFunction(Lib_iphlpapi,"GetIpInterfaceEntry")
  InitializeIpInterfaceEntry.PInitializeIpInterfaceEntry=GetFunction(Lib_iphlpapi,"InitializeIpInterfaceEntry")
  if_indextoname.Pif_indextoname=GetFunction(Lib_iphlpapi,"if_indextoname")
  GetAdapterIndex.PGetAdapterIndex=GetFunction(Lib_iphlpapi,"GetAdapterIndex")
  GetIfTable2.PGetIfTable2=GetFunction(Lib_iphlpapi,"GetIfTable2")
  GetIfStackTable.PGetIfStackTable=GetFunction(Lib_iphlpapi,"GetIfStackTable")
  GetIpNetEntry2.PGetIpNetEntry2=GetFunction(Lib_iphlpapi,"GetIpNetEntry2")
  ;GetIpStatistics.PGetIpStatistics=GetFunction(Lib_iphlpapi,"GetIpStatistics")
EndIf

Lib_Winsock = OpenLibrary(#PB_Any,"ws2_32.dll")
If Lib_Winsock
  CompilerIf #PB_Compiler_Unicode ; if compiled in unicode use this
    WSAAddressToString.PWSAAddressToString=GetFunction(Lib_Winsock,"WSAAddressToStringW")
    InetNtop.PInetNtop=GetFunction(Lib_Winsock,"InetNtopW")
  CompilerElse ; if not compiled in unicode use this
    WSAAddressToString.PWSAAddressToString=GetFunction(Lib_Winsock,"WSAAddressToStringA")
    InetNtop.PInetNtop=GetFunction(Lib_Winsock,"inet_ntop")
  CompilerEndIf
EndIf

Lib_Ntdll = OpenLibrary(#PB_Any,"Ntdll.dll")
If Lib_Ntdll
  CompilerIf #PB_Compiler_Unicode ; if compiled in unicode use this
    RtlIpv6AddressToString.PRtlIpv6AddressToString=GetFunction(Lib_Ntdll,"RtlIpv6AddressToStringW")
    RtlIpv4AddressToString.PRtlIpv4AddressToString=GetFunction(Lib_Ntdll,"RtlIpv4AddressToStringW")
  CompilerElse ; if not compiled in unicode use this
    RtlIpv6AddressToString.PRtlIpv6AddressToString=GetFunction(Lib_Ntdll,"RtlIpv6AddressToStringA")
    RtlIpv4AddressToString.PRtlIpv4AddressToString=GetFunction(Lib_Ntdll,"RtlIpv4AddressToStringA")
  CompilerEndIf
EndIf




; Lib_Kernel = OpenLibrary(#PB_Any,"kernel32.dll")
; If Lib_Kernel
;   ZeroMemory.PZeroMemory=GetFunction(Lib_Kernel,"RtlSecureZeroMemory")
; EndIf


If Lib_iphlpapi <> 0 And Lib_Winsock <> 0 And Lib_Ntdll <> 0 ;And Lib_Kernel <> 0
  ProcedureReturn #True
Else
  ProcedureReturn #False
EndIf

EndProcedure
;*****************************************************************************************

#ANY_SIZE = 1

;the family type values

#AF_UNSPEC = 0 ; unspecified
#AF_UNIX =   1 ; local To host (pipes, portals)
#AF_INET =   2 ; internetwork: UDP, TCP, etc. - IPv4
#AF_IMPLINK = 3 ; arpanet imp addresses
#AF_PUP =    4 ; pup protocols: e.g. BSP
#AF_CHAOS =  5 ; mit CHAOS protocols
#AF_NS =     6 ; XEROX NS protocols
#AF_IPX =    #AF_NS ; IPX protocols: IPX, SPX, etc.
#AF_ISO =    7 ; ISO protocols
#AF_OSI =    #AF_ISO ; OSI is ISO
#AF_ECMA =   8 ; european computer manufacturers
#AF_DATAKIT = 9 ; datakit protocols
#AF_CCITT =  10 ; CCITT protocols, X.25 etc
#AF_SNA =    11 ; IBM SNA
#AF_DECnet = 12 ; DECnet
#AF_DLI =    13 ; Direct Data link Interface
#AF_LAT =    14 ; LAT
#AF_HYLINK = 15 ; NSC Hyperchannel
#AF_APPLETALK = 16 ; AppleTalk
#AF_NETBIOS = 17 ; NetBios-style addresses
#AF_VOICEVIEW = 18 ; VoiceView
#AF_FIREFOX = 19 ; Protocols from Firefox
#AF_UNKNOWN1 = 20 ; Somebody is using this!
#AF_BAN =    21 ; Banyan
#AF_ATM =    22 ; Native ATM Services
#AF_INET6 =  23 ; Internetwork Version 6 - IPv6
#AF_CLUSTER = 24 ; Microsoft Wolfpack
#AF_12844 =  25 ; IEEE 1284.4 WG AF
#AF_IRDA =   26 ; IrDA
#AF_NETDES = 28 ; Network Designers OSI & gateway
; #if(_WIN32_WINNT < 0x0501)
; #AF_MAX =    29
; #else //(_WIN32_WINNT < 0x0501)
#AF_TCNPROCESS = 29
#AF_TCNMESSAGE = 30
#AF_ICLFXBM = 31
; #if(_WIN32_WINNT < 0x0600)
; #AF_MAX =    32
; #else //(_WIN32_WINNT < 0x0600)
#AF_BTH =    32 ; Bluetooth RFCOMM/L2CAP protocols
; #if(_WIN32_WINNT < 0x0601)
; #AF_MAX =    33
; #else //(_WIN32_WINNT < 0x0601)
#AF_LINK =   33
#AF_MAXx =    34 ; - this value is changed for this use - Purebasic has the wrong value for #AF_MAX as 18 - win 7 SDK has it as 34, no wonder i was getting crashes with my code, making my own variation with correct value fixed it

; #AF_INET = 2 = ipv4
#MAX_ADAPTER_NAME=128
#MAX_ADAPTER_NAME_LENGTH=256 
#MAX_ADAPTER_DESCRIPTION_LENGTH=128
#MAX_ADAPTER_ADDRESS_LENGTH=8
#MAX_HOSTNAME_LEN = 128
#MAX_DOMAIN_NAME_LEN = 128
#MAX_SCOPE_ID_LEN = 256
#ERROR_UNKNOWN = 1776
#BROADCAST_NODETYPE = 1 ; A broadcast nodetype
#PEER_TO_PEER_NODETYPE = 2 ; A peer To peer nodetype
#MIXED_NODETYPE = 4 ; A mixed nodetype
#HYBRID_NODETYPE = 8 ; A hybrid nodetype
#MAX_DHCPV6_DUID_LENGTH = 130
#MAX_DNS_SUFFIX_STRING_LENGTH = 256
#DNS_MAX_NAME_BUFFER_LENGTH = 256

;"SKIP"  = do not include
;"INCLUDE" = include
#GAA_FLAG_SKIP_UNICAST = $1
#GAA_FLAG_SKIP_ANYCAST = $2
#GAA_FLAG_SKIP_MULTICAST = $4
#GAA_FLAG_SKIP_DNS_SERVER = $8
#GAA_FLAG_INCLUDE_PREFIX = $10
#GAA_FLAG_SKIP_FRIENDLY_NAME = $20
#GAA_FLAG_INCLUDE_WINS_INFO = $40
#GAA_FLAG_INCLUDE_GATEWAYS = $80
#GAA_FLAG_INCLUDE_ALL_INTERFACES = $100
#GAA_FLAG_INCLUDE_ALL_COMPARTMENTS = $200 ; to get only the hardware interfaces
#GAA_FLAG_INCLUDE_TUNNEL_BINDINGORDER = $400
;
#GAA_FLAG_OMIT = #GAA_FLAG_SKIP_UNICAST | #GAA_FLAG_SKIP_ANYCAST | #GAA_FLAG_SKIP_MULTICAST | #GAA_FLAG_SKIP_DNS_SERVER | #GAA_FLAG_INCLUDE_PREFIX | #GAA_FLAG_SKIP_FRIENDLY_NAME
#GAA_FLAG_GET = #GAA_FLAG_INCLUDE_WINS_INFO | #GAA_FLAG_INCLUDE_GATEWAYS | #GAA_FLAG_INCLUDE_ALL_INTERFACES | #GAA_FLAG_INCLUDE_ALL_COMPARTMENTS | #GAA_FLAG_INCLUDE_TUNNEL_BINDINGORDER
;If this parameter is zero, then unicast, anycast, and multicast IP addresses will be returned
#GAA_FLAG_UNI_MULT_ANY = 0
#GAA_FLAG_INCLUDE_IP_PREFIX_STUFF = #GAA_FLAG_UNI_MULT_ANY ;| #GAA_FLAG_GET ;| #GAA_FLAG_INCLUDE_PREFIX ;|#GAA_FLAG_INCLUDE_GATEWAYS ;|#GAA_FLAG_INCLUDE_WINS_INFO ;|#GAA_FLAG_INCLUDE_ALL_COMPARTMENTS


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; buffer minimum address string lenghts
#INET_ADDRSTRLEN = 22
#INET6_ADDRSTRLEN = 65

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

#IP_ADAPTER_DDNS_ENABLED               = $00000001
#IP_ADAPTER_REGISTER_ADAPTER_SUFFIX    = $00000002
#IP_ADAPTER_DHCP_ENABLED               = $00000004
#IP_ADAPTER_RECEIVE_ONLY               = $00000008
#IP_ADAPTER_NO_MULTICAST               = $00000010
#IP_ADAPTER_IPV6_OTHER_STATEFUL_CONFIG = $00000020
#IP_ADAPTER_NETBIOS_OVER_TCPIP_ENABLED = $00000040
#IP_ADAPTER_IPV4_ENABLED               = $00000080
#IP_ADAPTER_IPV6_ENABLED               = $00000100
#IP_ADAPTER_IPV6_MANAGE_ADDRESS_CONFIG = $00000200


#ERROR_ADDRESS_NOT_ASSOCIATED = 1228
#IF_TYPE_OTHER = 1 ; "Some other type of network interface"
#IF_TYPE_ETHERNET_CSMACD = 6 ; "An Ethernet network interface"
#IF_TYPE_ISO88025_TOKENRING = 9 ; "A token ring network interface"
#IF_TYPE_PPP = 23 ; "A PPP network interface"
#IF_TYPE_SOFTWARE_LOOPBACK = 24 ; "A software loopback network interface"
#IF_TYPE_ATM = 37 ; "An ATM network interface"
#IF_TYPE_IEEE80211 = 71 ; "An IEEE 802.11 wireless network interface. On Windows Vista and later, wireless network cards are reported as IF_TYPE_IEEE80211. On earlier versions of Windows, wireless network cards are reported as IF_TYPE_ETHERNET_CSMACD"
#IF_TYPE_TUNNEL = 131 ; "A tunnel type encapsulation network interface"
#IF_TYPE_IEEE1394 = 144 ; "An IEEE 1394 (Firewire) high performance serial bus network interface"

;Bit values of IP_ADAPTER_ADDRESSES Flags field.
#IP_ADAPTER_DDNS_ENABLED = $1
#IP_ADAPTER_REGISTER_ADAPTER_SUFFIX = $2
#IP_ADAPTER_DHCP_ENABLED = $4
#IP_ADAPTER_RECEIVE_ONLY = $8
#IP_ADAPTER_NO_MULTICAST = $10
#IP_ADAPTER_IPV6_OTHER_STATEFUL_CONFIG = $20
#IP_ADAPTER_NETBIOS_OVER_TCPIP_ENABLED = $40
#IP_ADAPTER_IPV4_ENABLED = $80
#IP_ADAPTER_IPV6_ENABLED = $100
#IP_ADAPTER_IPV6_MANAGE_ADDRESS_CONFIG = $200

#MAXLEN_PHYSADDR =  8
#IP_ADAPTER_ADDRESS_DNS_ELIGIBLE = 1
#IP_ADAPTER_ADDRESS_TRANSIENT    = 2
#FLAG_ICC_FORCE_CONNECTION = 1

#IF_MAX_STRING_SIZE = 256
#NDIS_IF_MAX_STRING_SIZE = #IF_MAX_STRING_SIZE
#IF_NAMESIZE = #IF_MAX_STRING_SIZE

;********************************************************************************
;compartment ID type
#IF_COMPARTMENT_ID_UNSPECIFIED = 0
#IF_COMPARTMENT_ID_PRIMARY     = 1
;#NET_IF_OID_IF_ALIAS = $1 ;identifies the ifAlias string For an Interface
;#NET_IF_OID_COMPARTMENT_ID = $2 ;identifies the compartment ID For an Interface.
;#NET_IF_OID_NETWORK_GUID = $3 ;identifies the NetworkGuid For an Interface.
;#NET_IF_OID_IF_ENTRY = $4 ;identifies statistics For an Interface
;********************************************************************************

#IF_MAX_STRING_SIZE = 256
#IF_MAX_PHYS_ADDRESS_LENGTH = 32

#MIB_IPADDR_PRIMARY = $0001
#MIB_IPADDR_DYNAMIC = $0004
#MIB_IPADDR_DISCONNECTED = $0008
#MIB_IPADDR_DELETED = $0040
#MIB_IPADDR_TRANSIENT = $0080
#MIB_IPADDR_DNS_ELIGIBLE = $0100 ; Address is published in DNS.

; IF_Type
#MIN_IF_TYPE =   1
#IF_TYPE_OTHER = 1   ; None of the below
#IF_TYPE_REGULAR_1822 = 2
#IF_TYPE_HDH_1822 =     3
#IF_TYPE_DDN_X25 =      4
#IF_TYPE_RFC877_X25 =   5
#IF_TYPE_ETHERNET_CSMACD = 6
#IF_TYPE_IS088023_CSMACD = 7
#IF_TYPE_ISO88024_TOKENBUS = 8
#IF_TYPE_ISO88025_TOKENRING = 9
#IF_TYPE_ISO88026_MAN = 10
#IF_TYPE_STARLAN =      11
#IF_TYPE_PROTEON_10MBIT =  12
#IF_TYPE_PROTEON_80MBIT =  13
#IF_TYPE_HYPERCHANNEL = 14
#IF_TYPE_FDDI =  15
#IF_TYPE_LAP_B = 16
#IF_TYPE_SDLC =  17
#IF_TYPE_DS1 =   18  ; DS1-MIB
#IF_TYPE_E1 =    19  ; Obsolete; see DS1-MIB
#IF_TYPE_BASIC_ISDN =   20
#IF_TYPE_PRIMARY_ISDN = 21
#IF_TYPE_PROP_POINT2POINT_SERIAL = 22  ; proprietary serial
#IF_TYPE_PPP =   23
#IF_TYPE_SOFTWARE_LOOPBACK = 24
#IF_TYPE_EON =   25  ; CLNP over IP
#IF_TYPE_ETHERNET_3MBIT =  26
#IF_TYPE_NSIP =  27  ; XNS over IP
#IF_TYPE_SLIP =  28  ; Generic Slip
#IF_TYPE_ULTRA = 29  ; ULTRA Technologies
#IF_TYPE_DS3 =   30  ; DS3-MIB
#IF_TYPE_SIP =   31  ; SMDS, coffee
#IF_TYPE_FRAMERELAY =   32  ; DTE only
#IF_TYPE_RS232 = 33
#IF_TYPE_PARA =  34  ; Parallel port
#IF_TYPE_ARCNET = 35
#IF_TYPE_ARCNET_PLUS =  36
#IF_TYPE_ATM =   37  ; ATM cells
#IF_TYPE_MIO_X25 =      38
#IF_TYPE_SONET = 39  ; SONET Or SDH
#IF_TYPE_X25_PLE =      40
#IF_TYPE_ISO88022_LLC = 41
#IF_TYPE_LOCALTALK =    42
#IF_TYPE_SMDS_DXI =     43
#IF_TYPE_FRAMERELAY_SERVICE = 44  ; FRNETSERV-MIB
#IF_TYPE_V35 =   45
#IF_TYPE_HSSI =  46
#IF_TYPE_HIPPI = 47
#IF_TYPE_MODEM = 48  ; Generic Modem
#IF_TYPE_AAL5 =  49  ; AAL5 over ATM
#IF_TYPE_SONET_PATH =   50
#IF_TYPE_SONET_VT =     51
#IF_TYPE_SMDS_ICIP =    52  ; SMDS InterCarrier Interface
#IF_TYPE_PROP_VIRTUAL = 53  ; Proprietary virtual/internal
#IF_TYPE_PROP_MULTIPLEXOR =  54  ; Proprietary multiplexing
#IF_TYPE_IEEE80212 =    55  ; 100BaseVG
#IF_TYPE_FIBRECHANNEL = 56
#IF_TYPE_HIPPIINTERFACE =  57
#IF_TYPE_FRAMERELAY_INTERCONNECT = 58  ; Obsolete, use 32 Or 44
#IF_TYPE_AFLANE_8023 =  59  ; ATM Emulated LAN For 802.3
#IF_TYPE_AFLANE_8025 =  60  ; ATM Emulated LAN For 802.5
#IF_TYPE_CCTEMUL =      61  ; ATM Emulated circuit
#IF_TYPE_FASTETHER =    62  ; Fast Ethernet (100BaseT)
#IF_TYPE_ISDN =  63  ; ISDN And X.25
#IF_TYPE_V11 =   64  ; CCITT V.11/X.21
#IF_TYPE_V36 =   65  ; CCITT V.36
#IF_TYPE_G703_64K =     66  ; CCITT G703 at 64Kbps
#IF_TYPE_G703_2MB =     67  ; Obsolete; see DS1-MIB
#IF_TYPE_QLLC =  68  ; SNA QLLC
#IF_TYPE_FASTETHER_FX = 69  ; Fast Ethernet (100BaseFX)
#IF_TYPE_CHANNEL =      70
#IF_TYPE_IEEE80211 =    71  ; Radio spread spectrum
#IF_TYPE_IBM370PARCHAN =   72  ; IBM System 360/370 OEMI Channel
#IF_TYPE_ESCON = 73  ; IBM Enterprise Systems Connection
#IF_TYPE_DLSW =  74  ; Data Link Switching
#IF_TYPE_ISDN_S = 75  ; ISDN S/T Interface
#IF_TYPE_ISDN_U = 76  ; ISDN U Interface
#IF_TYPE_LAP_D = 77  ; Link Access Protocol D
#IF_TYPE_IPSWITCH =     78  ; IP Switching Objects
#IF_TYPE_RSRB =  79  ; Remote Source Route Bridging
#IF_TYPE_ATM_LOGICAL =  80  ; ATM Logical Port
#IF_TYPE_DS0 =   81  ; Digital Signal Level 0
#IF_TYPE_DS0_BUNDLE =   82  ; Group of ds0s on the same ds1
#IF_TYPE_BSC =   83  ; Bisynchronous Protocol
#IF_TYPE_ASYNC = 84  ; Asynchronous Protocol
#IF_TYPE_CNR =   85  ; Combat Net Radio
#IF_TYPE_ISO88025R_DTR =   86  ; ISO 802.5r DTR
#IF_TYPE_EPLRS = 87  ; Ext Pos Loc Report Sys
#IF_TYPE_ARAP =  88  ; Appletalk Remote Access Protocol
#IF_TYPE_PROP_CNLS =    89  ; Proprietary Connectionless Proto
#IF_TYPE_HOSTPAD =      90  ; CCITT-ITU X.29 PAD Protocol
#IF_TYPE_TERMPAD =      91  ; CCITT-ITU X.3 PAD Facility
#IF_TYPE_FRAMERELAY_MPI =  92  ; Multiproto Interconnect over FR
#IF_TYPE_X213 =  93  ; CCITT-ITU X213
#IF_TYPE_ADSL =  94  ; Asymmetric Digital Subscrbr Loop
#IF_TYPE_RADSL = 95  ; Rate-Adapt Digital Subscrbr Loop
#IF_TYPE_SDSL =  96  ; Symmetric Digital Subscriber Loop
#IF_TYPE_VDSL =  97  ; Very H-Speed Digital Subscrb Loop
#IF_TYPE_ISO88025_CRFPRINT = 98  ; ISO 802.5 CRFP
#IF_TYPE_MYRINET =      99  ; Myricom Myrinet
#IF_TYPE_VOICE_EM =     100 ; Voice recEive And transMit
#IF_TYPE_VOICE_FXO =    101 ; Voice Foreign Exchange Office
#IF_TYPE_VOICE_FXS =    102 ; Voice Foreign Exchange Station
#IF_TYPE_VOICE_ENCAP =  103 ; Voice encapsulation
#IF_TYPE_VOICE_OVERIP = 104 ; Voice over IP encapsulation
#IF_TYPE_ATM_DXI =      105 ; ATM DXI
#IF_TYPE_ATM_FUNI =     106 ; ATM FUNI
#IF_TYPE_ATM_IMA =      107 ; ATM IMA
#IF_TYPE_PPPMULTILINKBUNDLE = 108 ; PPP Multilink Bundle
#IF_TYPE_IPOVER_CDLC =  109 ; IBM ipOverCdlc
#IF_TYPE_IPOVER_CLAW =  110 ; IBM Common Link Access To Workstn
#IF_TYPE_STACKTOSTACK = 111 ; IBM stackToStack
#IF_TYPE_VIRTUALIPADDRESS =  112 ; IBM VIPA
#IF_TYPE_MPC =   113 ; IBM multi-proto channel support
#IF_TYPE_IPOVER_ATM =   114 ; IBM ipOverAtm
#IF_TYPE_ISO88025_FIBER =  115 ; ISO 802.5j Fiber Token Ring
#IF_TYPE_TDLC =  116 ; IBM twinaxial Data link control
#IF_TYPE_GIGABITETHERNET = 117
#IF_TYPE_HDLC =  118
#IF_TYPE_LAP_F = 119
#IF_TYPE_V37 =   120
#IF_TYPE_X25_MLP =      121 ; Multi-Link Protocol
#IF_TYPE_X25_HUNTGROUP =   122 ; X.25 Hunt Group
#IF_TYPE_TRANSPHDLC =   123
#IF_TYPE_INTERLEAVE =   124 ; Interleave channel
#IF_TYPE_FAST =  125 ; Fast channel
#IF_TYPE_IP =    126 ; IP (For APPN HPR in IP networks)
#IF_TYPE_DOCSCABLE_MACLAYER = 127 ; CATV Mac Layer
#IF_TYPE_DOCSCABLE_DOWNSTREAM = 128 ; CATV Downstream Interface
#IF_TYPE_DOCSCABLE_UPSTREAM = 129 ; CATV Upstream Interface
#IF_TYPE_A12MPPSWITCH = 130 ; Avalon Parallel Processor
#IF_TYPE_TUNNEL = 131 ; Encapsulation Interface
#IF_TYPE_COFFEE = 132 ; Coffee pot
#IF_TYPE_CES =   133 ; Circuit Emulation Service
#IF_TYPE_ATM_SUBINTERFACE =  134 ; ATM Sub Interface
#IF_TYPE_L2_VLAN =      135 ; Layer 2 Virtual LAN using 802.1Q
#IF_TYPE_L3_IPVLAN =    136 ; Layer 3 Virtual LAN using IP
#IF_TYPE_L3_IPXVLAN =   137 ; Layer 3 Virtual LAN using IPX
#IF_TYPE_DIGITALPOWERLINE =  138 ; IP over Power Lines
#IF_TYPE_MEDIAMAILOVERIP = 139 ; Multimedia Mail over IP
#IF_TYPE_DTM =   140 ; Dynamic syncronous Transfer Mode
#IF_TYPE_DCN =   141 ; Data Communications Network
#IF_TYPE_IPFORWARD =    142 ; IP Forwarding Interface
#IF_TYPE_MSDSL = 143 ; Multi-rate Symmetric DSL
#IF_TYPE_IEEE1394 =     144 ; IEEE1394 High Perf Serial Bus
#IF_TYPE_IF_GSN = 145
#IF_TYPE_DVBRCC_MACLAYER = 146
#IF_TYPE_DVBRCC_DOWNSTREAM = 147
#IF_TYPE_DVBRCC_UPSTREAM = 148
#IF_TYPE_ATM_VIRTUAL =  149
#IF_TYPE_MPLS_TUNNEL =  150
#IF_TYPE_SRP =   151
#IF_TYPE_VOICEOVERATM = 152
#IF_TYPE_VOICEOVERFRAMERELAY = 153
#IF_TYPE_IDSL =  154
#IF_TYPE_COMPOSITELINK =   155
#IF_TYPE_SS7_SIGLINK =  156
#IF_TYPE_PROP_WIRELESS_P2P = 157
#IF_TYPE_FR_FORWARD =   158
#IF_TYPE_RFC1483 =      159
#IF_TYPE_USB =   160
#IF_TYPE_IEEE8023AD_LAG =  161
#IF_TYPE_BGP_POLICY_ACCOUNTING = 162
#IF_TYPE_FRF16_MFR_BUNDLE =  163
#IF_TYPE_H323_GATEKEEPER = 164
#IF_TYPE_H323_PROXY =   165
#IF_TYPE_MPLS =  166
#IF_TYPE_MF_SIGLINK =   167
#IF_TYPE_HDSL2 = 168
#IF_TYPE_SHDSL = 169
#IF_TYPE_DS1_FDL =      170
#IF_TYPE_POS =   171
#IF_TYPE_DVB_ASI_IN =   172
#IF_TYPE_DVB_ASI_OUT =  173
#IF_TYPE_PLC =   174
#IF_TYPE_NFAS =  175
#IF_TYPE_TR008 = 176
#IF_TYPE_GR303_RDT =    177
#IF_TYPE_GR303_IDT =    178
#IF_TYPE_ISUP =  179
#IF_TYPE_PROP_DOCS_WIRELESS_MACLAYER = 180
#IF_TYPE_PROP_DOCS_WIRELESS_DOWNSTREAM = 181
#IF_TYPE_PROP_DOCS_WIRELESS_UPSTREAM = 182
#IF_TYPE_HIPERLAN2 =      183
#IF_TYPE_PROP_BWA_P2MP =  184
#IF_TYPE_SONET_OVERHEAD_CHANNEL =   185
#IF_TYPE_DIGITAL_WRAPPER_OVERHEAD_CHANNEL = 186
#IF_TYPE_AAL2 =   187
#IF_TYPE_RADIO_MAC =      188
#IF_TYPE_ATM_RADIO =      189
#IF_TYPE_IMT = 190
#IF_TYPE_MVL = 191
#IF_TYPE_REACH_DSL =      192
#IF_TYPE_FR_DLCI_ENDPT =  193
#IF_TYPE_ATM_VCI_ENDPT =  194
#IF_TYPE_OPTICAL_CHANNEL = 195
#IF_TYPE_OPTICAL_TRANSPORT =     196
#IF_TYPE_IEEE80216_WMAN = 237
#IF_TYPE_WWANPP = 243 ; WWAN devices based on GSM technology
#IF_TYPE_WWANPP2 =      244 ; WWAN devices based on CDMA technology
#MAX_IF_TYPE = 244

;  Access types
;****************************************************************************

Enumeration ;_#IF_ACCESS_TYPE {
  #IF_ACCESS_LOOPBACK             = 1
  #IF_ACCESS_BROADCAST            = 2
  #IF_ACCESS_POINT_TO_POINT       = 3 ;  New definition.
  #IF_ACCESS_POINT_TO_MULTI_POINT = 4 ;  New definition.
  #NET_IF_ACCESS_MAXIMUM = 5 ; The maximum possible value for the NET_IF_ACCESS_TYPE enumeration type. This is not a legal value for AccessType member.
EndEnumeration


;****************************************************************************

;  Interface Capabilities (bit flags)
;****************************************************************************

#IF_CHECK_NONE = $0
#IF_CHECK_MCAST = $1
#IF_CHECK_SEND = $2

;****************************************************************************
; Flags To extend operational status - used for NDIS driver/IF status
;
#NET_IF_OPER_STATUS_DOWN_NOT_AUTHENTICATED = $1
#NET_IF_OPER_STATUS_DOWN_NOT_MEDIA_CONNECTED = $2
#NET_IF_OPER_STATUS_DORMANT_PAUSED = $4
#NET_IF_OPER_STATUS_DORMANT_LOW_POWER = $8

;****************************************************************************

;  Connection Types

;****************************************************************************

Enumeration ; NET_IF_CONNECTION_TYPE
  #NET_IF_CONNECTION_DEDICATED = 1
  #NET_IF_CONNECTION_PASSIVE = 2
  #NET_IF_CONNECTION_DEMAND = 3
  #NET_IF_CONNECTION_MAXIMUM = 4
EndEnumeration

#IF_CONNECTION_DEDICATED = 1
#IF_CONNECTION_PASSIVE = 2
#IF_CONNECTION_DEMAND = 3


#IF_ADMIN_STATUS_UP  = 1
#IF_ADMIN_STATUS_DOWN = 2
#IF_ADMIN_STATUS_TESTING = 3

;***************************************************************************
;                                                                          ;
; The following are the the operational states For WAN And LAN interfaces. ;
; The order of the states seems weird, but is done For a purpose. All      ;
; states >= CONNECTED can transmit Data right away. States >= DISCONNECTED ;
; can tx Data but some set up might be needed. States < DISCONNECTED can   ;
; Not transmit Data.                                                       ;
; A card is marked UNREACHABLE If Dim calls InterfaceUnreachable For       ;
; reasons other than failure To connect.                                   ;
;                                                                          ;
; NON_OPERATIONAL -- Valid For LAN Interfaces. Means the card is Not       ;
;                      working Or Not plugged in Or has no address.        ;
; UNREACHABLE     -- Valid For WAN Interfaces. Means the remote site is    ;
;                      Not reachable at this time.                         ;
; DISCONNECTED    -- Valid For WAN Interfaces. Means the remote site is    ;
;                      Not connected at this time.                         ;
; CONNECTING      -- Valid For WAN Interfaces. Means a connection attempt  ;
;                      has been initiated To the remote site.              ;
; CONNECTED       -- Valid For WAN Interfaces. Means the remote site is    ;
;                      connected.                                          ;
; OPERATIONAL     -- Valid For LAN Interfaces. Means the card is plugged   ;
;                      in And working.                                     ;
;                                                                          ;
; It is the users duty To convert these values To MIB-II values If they    ;
; are To be used by a subagent                                             ;
;                                                                          ;
;***************************************************************************

Enumeration ; _INTERNAL_IF_OPER_STATUS
  #IF_OPER_STATUS_NON_OPERATIONAL = 0
  #IF_OPER_STATUS_UNREACHABLE     = 1
  #IF_OPER_STATUS_DISCONNECTED    = 2
  #IF_OPER_STATUS_CONNECTING      = 3
  #IF_OPER_STATUS_CONNECTED       = 4
  #IF_OPER_STATUS_OPERATIONAL     = 5
EndEnumeration

#MIB_IF_TYPE_OTHER = 1
#MIB_IF_TYPE_ETHERNET = 6
#MIB_IF_TYPE_TOKENRING = 9
#MIB_IF_TYPE_FDDI = 15
#MIB_IF_TYPE_PPP = 23
#MIB_IF_TYPE_LOOPBACK = 24
#MIB_IF_TYPE_SLIP = 28

#MIB_IF_ADMIN_STATUS_UP = 1
#MIB_IF_ADMIN_STATUS_DOWN = 2
#MIB_IF_ADMIN_STATUS_TESTING = 3

;Medium the Ndis Driver is running on (OID_GEN_MEDIA_SUPPORTED/ OID_GEN_MEDIA_IN_USE).

Enumeration ; _#Ndis_MEDIUM
  #NdisMedium802_3
  #NdisMedium802_5
  #NdisMediumFddi
  #NdisMediumWan
  #NdisMediumLocalTalk
  #NdisMediumDix    ;defined For convenience, Not a real medium
  #NdisMediumArcnetRaw
  #NdisMediumArcnet878_2
  #NdisMediumAtm
  #NdisMediumWirelessWan
  #NdisMediumIrda
  #NdisMediumBpc
  #NdisMediumCoWan
  #NdisMedium1394
  #NdisMediumInfiniBand
  #NdisMediumTunnel
  #NdisMediumNative802_11
  #NdisMediumLoopback
  #NdisMediumWiMAX
  #NdisMediumIP
  #NdisMediumMax ; Not a real medium, defined As an upper-bound
EndEnumeration

;Physical Medium Type definitions.

Enumeration ; _NDIS_PHYSICAL_MEDIUM
  #NdisPhysicalMediumUnspecified
  #NdisPhysicalMediumWirelessLan
  #NdisPhysicalMediumCableModem
  #NdisPhysicalMediumPhoneLine
  #NdisPhysicalMediumPowerLine
  #NdisPhysicalMediumDSL      ; includes ADSL And UADSL (G.Lite)
  #NdisPhysicalMediumFibreChannel
  #NdisPhysicalMedium1394
  #NdisPhysicalMediumWirelessWan
  #NdisPhysicalMediumNative802_11
  #NdisPhysicalMediumBluetooth
  #NdisPhysicalMediumInfiniband
  #NdisPhysicalMediumWiMax
  #NdisPhysicalMediumUWB
  #NdisPhysicalMedium802_3
  #NdisPhysicalMedium802_5
  #NdisPhysicalMediumIrda
  #NdisPhysicalMediumWiredWAN
  #NdisPhysicalMediumWiredCoWan
  #NdisPhysicalMediumOther
  #NdisPhysicalMediumMax       ; Not a real physical type defined As an upper-bound
EndEnumeration

Enumeration ;#NET_IF_DIRECTION_TYPE
   #NET_IF_DIRECTION_SENDRECEIVE
   #NET_IF_DIRECTION_SENDONLY
   #NET_IF_DIRECTION_RECEIVEONLY
   #NET_IF_DIRECTION_MAXIMUM
 EndEnumeration
 
 Enumeration ; _#NET_IF_ADMIN_STATUS
   #NET_IF_ADMIN_STATUS_UP = 1
   #NET_IF_ADMIN_STATUS_DOWN = 2
   #NET_IF_ADMIN_STATUS_TESTING = 3
 EndEnumeration
 
 Enumeration ; NET_IF_MEDIA_CONNECT_STATE
  #MediaConnectStateUnknown
  #MediaConnectStateConnected
  #MediaConnectStateDisconnected
EndEnumeration

Enumeration ; NET_IF_MEDIA_DUPLEX_STATE
  #MediaDuplexStateUnknown
  #MediaDuplexStateHalf
  #MediaDuplexStateFull
EndEnumeration
 
Enumeration; _MIB_IF_TABLE_LEVEL
   #MibIfTableNormal
   #MibIfTableRaw
EndEnumeration

Enumeration; NET_IF_ACCESS_TYPE
  #NET_IF_ACCESS_LOOPBACK = 1
  #NET_IF_ACCESS_BROADCAST = 2
  #NET_IF_ACCESS_POINT_TO_POINT = 3
  #NET_IF_ACCESS_POINT_TO_MULTI_POINT = 4
  #NET_IF_ACCESS_MAXIMUM = 5
EndEnumeration

;#MibIfTableNormal ; Calling the GetIfTable2Ex function with the Level parameter set to MibIfTableNormal retrieves the same results as calling the GetIfTable2 function. 
;The values of statistics And state returned in members of the MIB_IF_ROW2 Structure in the MIB_IF_TABLE2 Structure pointed To by the Table parameter 
;are returned from the top of the filter stack when this parameter is specified. Calling the GetIfTable2Ex function with the Level parameter set to 
; MibIfTableNormal retrieves the same results as calling the GetIfTable2 function.

;#MibIfTableRaw ; The values of statistics and state returned in members of the MIB_IF_ROW2 Structure in the MIB_IF_TABLE2 Structure pointed To by the Table
;parameter are returned directly For the Interface being queried.

Enumeration
  #TUNNEL_TYPE_NONE = 0
  #TUNNEL_TYPE_OTHER = 1
  #TUNNEL_TYPE_DIRECT = 2
  #TUNNEL_TYPE_6TO4 = 11
  #TUNNEL_TYPE_ISATAP = 13
  #TUNNEL_TYPE_TEREDO = 14
  #TUNNEL_TYPE_IPHTTPS = 15
EndEnumeration

Enumeration ; IF_OPER_STATUS - the type in MIB_IF_ROW2
  #IfOperStatusUp = 1
  #IfOperStatusDown
  #IfOperStatusTesting
  #IfOperStatusUnknown
  #IfOperStatusDormant
  #IfOperStatusNotPresent
  #IfOperStatusLowerLayerDown
EndEnumeration

Enumeration ; IP_PREFIX_ORIGIN
  #IpPrefixOriginOther = 0
  #IpPrefixOriginManual
  #IpPrefixOriginWellKnown
  #IpPrefixOriginDhcp
  #IpPrefixOriginRouterAdvertisement
  #IpPrefixOriginUnchanged = 16
EndEnumeration

; Bit values of IP_ADAPTER_UNICAST_ADDRESS Flags field.
#IP_ADAPTER_ADDRESS_DNS_ELIGIBLE = $1
#IP_ADAPTER_ADDRESS_TRANSIENT = $2

Enumeration ;NET_ADDRESS_FORMAT
  #NET_ADDRESS_FORMAT_UNSPECIFIED = 0
  #NET_ADDRESS_DNS_NAME
  #NET_ADDRESS_IPV4
  #NET_ADDRESS_IPV6
EndEnumeration

Enumeration ; #MIB_IPNET_TYPE
  #MIB_IPNET_TYPE_OTHER   = 1
  #MIB_IPNET_TYPE_INVALID = 2
  #MIB_IPNET_TYPE_DYNAMIC = 3
  #MIB_IPNET_TYPE_STATIC  = 4
EndEnumeration

Enumeration ; #Scope_LEVEL
  #ScopeLevelInterface      = 1
  #ScopeLevelLink           = 2
  #ScopeLevelSubnet         = 3
  #ScopeLevelAdmin          = 4
  #ScopeLevelSite           = 5
  #ScopeLevelOrganization   = 8
  #ScopeLevelGlobal         = 14
  #ScopeLevelCount          = 16
EndEnumeration

Enumeration ; IP_PREFIX_ORIGIN flags
  #IpPrefixOriginOther                 = 0
  #IpPrefixOriginManual
  #IpPrefixOriginWellKnown
  #IpPrefixOriginDhcp
  #IpPrefixOriginRouterAdvertisement
  #IpPrefixOriginUnchanged             = 16
EndEnumeration

Enumeration ;IP_SUFFIX_ORIGIN
  #IpSuffixOriginOther              = 0
  #IpSuffixOriginManual
  #IpSuffixOriginWellKnown
  #IpSuffixOriginDhcp
  #IpSuffixOriginLinkLayerAddress
  #IpSuffixOriginRandom
  #IpSuffixOriginUnchanged          = 16
EndEnumeration

Enumeration ;IP_DAD_STATE
  #IpDadStateInvalid      = 0
  #IpDadStateTentative
  #IpDadStateDuplicate
  #IpDadStateDeprecated
  #IpDadStatePreferred
EndEnumeration

Enumeration ; MIB_IPSTATS_FORWARDING
  #MIB_IP_FORWARDING     = 1
  #MIB_IP_NOT_FORWARDING = 2
EndEnumeration


;***************************************************************************
; ; utility and support procedures from here
;***************************************************************************

Procedure.s NDISMedium(in_media_type.i)

Select in_media_type
  Case #NdisMedium802_3
    ndismedium$ = "An Ethernet (802.3) network."
  Case #NdisMedium802_5
    ndismedium$ = "A Token Ring (802.5) network."
  Case #NdisMediumFddi
    ndismedium$ = "A Fiber Distributed Data Interface (FDDI) network."
  Case #NdisMediumWan
    ndismedium$ = "A wide area network (WAN). This type covers various forms of point-to-point and WAN NICs, as well as variant address/header formats that must be negotiated between the protocol driver and the underlying driver after the binding is established."
  Case #NdisMediumLocalTalk
    ndismedium$ = "A LocalTalk network."
  Case #NdisMediumDix    ;defined For convenience, Not a real medium
    ndismedium$ = "An Ethernet network for which the drivers use the DIX Ethernet header format."
  Case #NdisMediumArcnetRaw
    ndismedium$ = "An ARCNET network."
  Case #NdisMediumArcnet878_2
    ndismedium$ = "An ARCNET (878.2) network."
  Case #NdisMediumAtm
    ndismedium$ = "An ATM network."
  Case #NdisMediumWirelessWan
    ndismedium$ = "A wireless network. Can also be for Mobile Broadband only on Windows 7."
  Case #NdisMediumIrda
    ndismedium$ = "An infrared (IrDA) network."
  Case #NdisMediumBpc
    ndismedium$ = "A broadcast PC network."
  Case #NdisMediumCoWan
    ndismedium$ = "A wide area network in a connection-oriented environment."
  Case #NdisMedium1394
    ndismedium$ = "An IEEE 1394 (fire wire) network."
  Case #NdisMediumInfiniBand
    ndismedium$ = "An InfiniBand network."
  Case #NdisMediumTunnel
    ndismedium$ = "A tunnel network."
  Case #NdisMediumNative802_11
    ndismedium$ = "A native IEEE 802.11 network."
  Case #NdisMediumLoopback
    ndismedium$ = "An NDIS loopback network."
  Case #NdisMediumWiMAX
    ndismedium$ = "A WiMax newtwork."
  Case #NdisMediumIP
    ndismedium$ = "Plain/Simple IP network."
  Default
    ndismedium$ = "The Media Type is unknown."
    ;Case #NdisMediumMax ; Not a real medium, defined As an upper-bound
EndSelect

ProcedureReturn ndismedium$

EndProcedure

Procedure.s NDIS_Physical_Medium(in_phys_medium_type.i)

  Select in_phys_medium_type
    Case #NdisPhysicalMediumUnspecified
      physmedia$ = "The physical medium is unspecified. (Note: Also a normal condition for non-hardware interfaces.)"
    Case #NdisPhysicalMediumWirelessLan
      physmedia$ = "Packets are transferred over a wireless LAN network through a miniport driver that conforms to the 802.11 interface specification."
    Case #NdisPhysicalMediumCableModem
      physmedia$ = "Packets are transferred over a DOCSIS-based cable network."
    Case #NdisPhysicalMediumPhoneLine
      physmedia$ = "Packets are transferred over standard phone lines. This includes HomePNA media, for example."
    Case #NdisPhysicalMediumPowerLine
      physmedia$ = "Packets are transferred over wiring that is connected to a power distribution system."
    Case #NdisPhysicalMediumDSL      ; includes ADSL And UADSL (G.Lite)
      physmedia$ = "Packets are transferred over a Digital Subscriber Line (DSL) network. This includes ADSL, UADSL (G.Lite), and SDSL, for example."
    Case #NdisPhysicalMediumFibreChannel
      physmedia$ = "Packets are transferred over a Fibre Channel interconnect."
    Case #NdisPhysicalMedium1394
      physmedia$ = "Packets are transferred over an IEEE 1394 bus."
    Case #NdisPhysicalMediumWirelessWan
      physmedia$ = "Packets are transferred over a Wireless WAN link. This includes CDPD, CDMA and GPRS, for example."
    Case #NdisPhysicalMediumNative802_11
      physmedia$ = "Packets are transferred over a wireless LAN network through a miniport driver that conforms to the Native 802.11 interface. Note: The Native 802.11 Interface is supported in NDIS 6.0 And later versions."
    Case #NdisPhysicalMediumBluetooth
      physmedia$ = "Packets are transferred over a Bluetooth network. Bluetooth is a short-range wireless technology that uses the 2.4 GHz spectrum."
    Case #NdisPhysicalMediumInfiniband
      physmedia$ = "Packets are transferred over an Infiniband interconnect."
    Case #NdisPhysicalMediumWiMax
      physmedia$ = "Packets are transferred over a WiMax network. "
    Case #NdisPhysicalMediumUWB
      physmedia$ = "Packets are transferred over an ultra wide band network."
    Case #NdisPhysicalMedium802_3
      physmedia$ = "Packets are transferred over an Ethernet (802.3) network."
    Case #NdisPhysicalMedium802_5
      physmedia$ = "Packets are transferred over a Token Ring (802.5) network."
    Case #NdisPhysicalMediumIrda
      physmedia$ = "Packets are transferred over an infrared (IrDA) network."
    Case #NdisPhysicalMediumWiredWAN
      physmedia$ = "Packets are transferred over a wired WAN network."
    Case #NdisPhysicalMediumWiredCoWan
      physmedia$ = "Packets are transferred over a wide area network in a connection-oriented environment."
    Case #NdisPhysicalMediumOther
      physmedia$ = "Packets are transferred over a network that is not described by other possible values."
    Default
      physmedia$ = "The physical medium is unknown."
      ;Case #NdisPhysicalMediumMax       ; Not a real physical type defined As an upper-bound
  EndSelect
    
ProcedureReturn physmedia$
 
EndProcedure

Procedure.s AccessType(in_acces_type.i)
  
Select in_acces_type
  Case #NET_IF_ACCESS_LOOPBACK
    accesstype$ = "Loopback access type. This access type indicates that the interface loops back transmit data as receive data."
  Case #NET_IF_ACCESS_BROADCAST
    accesstype$ = "LAN access type which includes Ethernet. This access type indicates the interface provides native support for multicast or broadcast services."
  Case #NET_IF_ACCESS_POINT_TO_POINT
    accesstype$ = "Point-to-point access that supports CoNDIS/WAN, except for non-broadcast multi-access (NBMA) interfaces."
  Case #NET_IF_ACCESS_POINT_TO_MULTI_POINT
    accesstype$ = "Point-to-multipoint access that supports non-broadcast multi-access (NBMA) media, including the 'RAS Internal' interface, and native (non-LANE) ATM."
  Case #NET_IF_ACCESS_MAXIMUM
    accesstype$ = "Type of access is unspecific, unknown, or not defined."
  Default
    accesstype$ = "Type of access is unspecific, unknown, or not defined."
  ; #NET_IF_ACCESS_MAXIMUM = 5 ; The maximum possible value for the NET_IF_ACCESS_TYPE enumeration type. This is not a legal value for AccessType member.
EndSelect

ProcedureReturn accesstype$

EndProcedure

Procedure.l IntFromAddress(ip$)
   ProcedureReturn inet_addr_(ip$)
EndProcedure

Procedure.s AddressFromInt(ip.l)
   ProcedureReturn PeekS (inet_ntoa_(ip))
EndProcedure

Procedure.s ShowAPIError(CheckReturnValue) 
  Buffer.s = Space (4096) 
  NumberOfChars = FormatMessage_(#FORMAT_MESSAGE_FROM_SYSTEM, 0, CheckReturnValue, 0, Buffer.s, Len(Buffer.s), 0) 
  ProcedureReturn Left (Buffer.s, NumberOfChars-2) 
EndProcedure

Procedure.s ReadMIBRowBitField(number.l, index.l, length) 
  Protected bitfield$ 
  bitfield$=RSet(Bin(number), 32, "0")
  ProcedureReturn Mid(bitfield$, 32-index, length)
EndProcedure

Procedure.s Availibility_Info(availinfo.i)

  Select availinfo
  
    Case 1
      Avail_Stat$ = "Other"
    Case 2
      Avail_Stat$ = "Unknown"
    Case 3
      Avail_Stat$ = "Running or Full Power"
    Case 4
      Avail_Stat$ = "Warning"
    Case 5
      Avail_Stat$ = "In Test"
    Case 6
      Avail_Stat$ = "Not Applicable"
    Case 7
      Avail_Stat$ = "Power Off"
    Case 8
      Avail_Stat$ = "Offline"
    Case 9
      Avail_Stat$ = "Off Duty"
    Case 10
      Avail_Stat$ = "Degraded"
    Case 11
      Avail_Stat$ = "Not Installed"
    Case 12
      Avail_Stat$ = "Install Error"
    Case 13
      Avail_Stat$ = "Power Save - Unknown (The device is known to be in a power save mode, but its exact status is unknown.)"
    Case 14
      Avail_Stat$ = "Power Save - Low Power Mode (The device is in a power save state, but still functioning, and may exhibit degraded performance.)"
    Case 15
      Avail_Stat$ = "Power Save - Standby (The device is not functioning, but could be brought to full power quickly.)"
    Case 16
      Avail_Stat$ = "Power Cycle"
    Case 17
      Avail_Stat$ = "Power Save - Warning (The device is in a warning state, but also in a power save mode.)"
  
  EndSelect

ProcedureReturn Avail_Stat$

EndProcedure

Procedure.s ConfigManager_ErrorCode(cm_ec.i)

  Select cm_ec
  
    Case 0
      Error_Code_Type$ = "Device is working properly"
    Case 1
      Error_Code_Type$ = "Device is not configured correctly."
    Case 2
      Error_Code_Type$ = "Windows cannot load the driver for this device."
    Case 3
      Error_Code_Type$ = "Driver For this device might be corrupted, or the system may be low on memory or other resources."
    Case 4
      Error_Code_Type$ = "Device is not working properly. One of its drivers or the registry might be corrupted."
    Case 5
      Error_Code_Type$ = "Driver for the device requires a resource that Windows cannot manage."
    Case 6
      Error_Code_Type$ = "Boot configuration for the device conflicts with other devices."
    Case 7
      Error_Code_Type$ = "Cannot filter."
    Case 8
      Error_Code_Type$ = "Driver loader for the device is missing."
    Case 9
      Error_Code_Type$ = "Device is not working properly. The controlling firmware is incorrectly reporting the resources for the device."
    Case 10
      Error_Code_Type$ = "Device cannot start."
    Case 11
      Error_Code_Type$ = "Device failed."
    Case 12
      Error_Code_Type$ = "Device cannot find enough free resources to use."
    Case 13
      Error_Code_Type$ = "Windows cannot verify the device's resources."
    Case 14
      Error_Code_Type$ = "Device cannot work properly Until the computer is restarted."
    Case 15
      Error_Code_Type$ = "Device is not working properly due to a possible re-enumeration problem."
    Case 16
      Error_Code_Type$ = "Windows cannot identify all of the resources that the device uses."
    Case 17
      Error_Code_Type$ = "Device is requesting an unknown resource type."
    Case 18
      Error_Code_Type$ = "Device drivers must be reinstalled."
    Case 19
      Error_Code_Type$ = "Failure using the VxD loader."
    Case 20
      Error_Code_Type$ = "Registry might be corrupted."
    Case 21
      Error_Code_Type$ = "System failure. If changing the device driver is ineffective, see the hardware documentation. Windows is removing the device."
    Case 22
      Error_Code_Type$ = "Device is disabled."
    Case 23
      Error_Code_Type$ = "System failure. If changing the device driver is ineffective, see the hardware documentation."
    Case 24
      Error_Code_Type$ = "Device is not present, not working properly, or does not have all of its drivers installed."
    Case 25
      Error_Code_Type$ = "Windows is still setting up the device."
    Case 26
      Error_Code_Type$ = "Windows is still setting up the device."
    Case 27
      Error_Code_Type$ = "Device does not have a valid log configuration."
    Case 28
      Error_Code_Type$ = "Device drivers are not installed."
    Case 29
      Error_Code_Type$ = "Device is disabled. The device firmware did not provide the required resources."
    Case 30
      Error_Code_Type$ = "Device is using an IRQ resource that another device is using."
    Case 31
      Error_Code_Type$ = "Device is not working properly. Windows cannot load the required device drivers."
    
  EndSelect

ProcedureReturn Error_Code_Type$

EndProcedure

Procedure.s ConvertUnicodeToAnsi(in_pointer)
  Buffer.s=Space(512)
  WideCharToMultiByte_(#CP_ACP,0,in_pointer,-1,@Buffer,512,0,0)
  ProcedureReturn Buffer
EndProcedure

Procedure ConvertAnsiToUnicode(in_string.s)
  *uniout = AllocateMemory(Len(in_string)*4) 
  MultiByteToWideChar_(#CP_ACP, 0, in_string, -1, *uniout, Len(in_string))  
  ProcedureReturn *uniout  
EndProcedure

; string to WCHAR
Procedure MakeBSTR(String$) 
  Unicode$ = Space(Len(String$)*2+2) 
  MultiByteToWideChar_(#CP_ACP, 0, @String$, -1, @Unicode$, Len(String$)*2+2) 
  ProcedureReturn SysAllocString_(@Unicode$) 
EndProcedure

Last edited by SFSxOI on Mon Aug 22, 2011 5:59 pm, edited 6 times in total.
The advantage of a 64 bit operating system over a 32 bit operating system comes down to only being twice the headache.
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Re: More than u ever wanted to know - Interfaces and Adapter

Post by SFSxOI »

This is the test bed code - Part 1 (too long for one post - see following posts):

Part 1

Code: Select all

XIncludeFile "interfaceinfo_enums_and_types.pbi"


Structure SOCKADDR_STORAGE ;->Structure SOCKADDR_STORAGE
  ss_family.i
  __ss_pad1.c[6]
  __ss_align.q
  __ss_pad2.c[112]
EndStructure

Structure SOCKET_ADDRESS ;->Structure SOCKET_ADDRESS
*lpSockaddr.SOCKADDR_STORAGE
  iSockaddrLength.l
EndStructure

Structure IP_ADAPTER_DNS_SERVER_ADDRESS_LENGTH
  Length.l
  Reserved.i
EndStructure

Structure IP_ADAPTER_DNS_SERVER_ADDRESS  ;->Structure IP_ADAPTER_DNS_SERVER_ADDRESS 
  StructureUnion
    Alignment.q
    sLength.IP_ADAPTER_DNS_SERVER_ADDRESS_LENGTH
  EndStructureUnion
*Next.IP_ADAPTER_DNS_SERVER_ADDRESS
Address.SOCKET_ADDRESS
EndStructure

Structure IP_ADAPTER_MULTICAST_ADDRESS_FLAGS
  Length.i
  Flags.i
EndStructure

Structure IP_ADAPTER_MULTICAST_ADDRESS  ;->Structure IP_ADAPTER_MULTICAST_ADDRESS
  StructureUnion
    Alignment.q
    sFlagsLength.IP_ADAPTER_MULTICAST_ADDRESS_FLAGS
  EndStructureUnion
*Next.IP_ADAPTER_MULTICAST_ADDRESS
Address.SOCKET_ADDRESS
EndStructure

Structure IP_ADAPTER_ANYCAST_ADDRESS_FLAGS
  Length.l
  Flags.i
EndStructure

Structure IP_ADAPTER_ANYCAST_ADDRESS  ;->Structure IP_ADAPTER_ANYCAST_ADDRESS
  StructureUnion
    Alignment.q
    sFlagsLength.IP_ADAPTER_ANYCAST_ADDRESS_FLAGS
  EndStructureUnion
  *Next.IP_ADAPTER_ANYCAST_ADDRESS
  Address.SOCKET_ADDRESS
EndStructure

Structure IP_ADAPTER_UNICAST_ADDRESS_FLAGS
  Length.l
  Flags.i
EndStructure

Structure IP_ADAPTER_UNICAST_ADDRESS  ;->Structure IP_ADAPTER_UNICAST_ADDRESS
  StructureUnion
    Alignment.q
    sFlagsLength.IP_ADAPTER_UNICAST_ADDRESS_FLAGS
  EndStructureUnion
  *Next.IP_ADAPTER_UNICAST_ADDRESS
  Address.SOCKET_ADDRESS
  PrefixOrigin.i
  SuffixOrigin.i
  DadState.i
  ValidLifetime.i
  PreferredLifetime.i
  LeaseLifetime.i
  OnLinkPrefixLength.b
EndStructure

Structure IP_ADAPTER_DNS_SUFFIX  ;->Structure IP_ADAPTER_DNS_SUFFIX
*Next.IP_ADAPTER_DNS_SUFFIX
String.w[#MAX_DNS_SUFFIX_STRING_LENGTH]
EndStructure

Structure IP_ADAPTER_PREFIX_FLAGS
  Length.i
  Flags.i ; This member is reserved and should be set to zero - per MSDN
EndStructure

Structure IP_ADAPTER_PREFIX  ;->Structure IP_ADAPTER_PREFIX
  StructureUnion
    Alignment.q
    sFlagsLength.IP_ADAPTER_PREFIX_FLAGS
  EndStructureUnion
  *Next.IP_ADAPTER_PREFIX
  Address.SOCKET_ADDRESS
  PrefixLength.i
EndStructure

Structure IP_ADAPTER_GATEWAY_ADDRESS_LENGTH
  Length.l
  Reserved.i
EndStructure

Structure IP_ADAPTER_GATEWAY_ADDRESS  ;->Structure IP_ADAPTER_GATEWAY_ADDRESS
  StructureUnion
    Alignment.q
    sLength.IP_ADAPTER_GATEWAY_ADDRESS_LENGTH
  EndStructureUnion
  *Next.IP_ADAPTER_GATEWAY_ADDRESS
  Address.SOCKET_ADDRESS
EndStructure

Structure IP_ADAPTER_WINS_SERVER_ADDRESS_LENGTH
  Length.l
  Reserved.i
EndStructure

Structure IP_ADAPTER_WINS_SERVER_ADDRESS  ;->Structure IP_ADAPTER_WINS_SERVER_ADDRESS
  StructureUnion
    Alignment.q
    sLength.IP_ADAPTER_WINS_SERVER_ADDRESS_LENGTH
  EndStructureUnion
  *Next.IP_ADAPTER_WINS_SERVER_ADDRESS
  Address.SOCKET_ADDRESS
EndStructure

Structure IF_LUID  ;->Structure IF_LUID
  Reserved.q[24]
  NetLuidIndex.q[24]
  IfType.q[16]
EndStructure

Structure IP_ADAPTER_ADDRESSES_FLAGS
  DdnsEnabled.b[1]
  RegisterAdapterSuffix.b[1]
  Dhcpv4Enabled.b[1]
  ReceiveOnly.b[1]
  NoMulticast.b[1]
  Ipv6OtherStatefulConfig.b[1]
  NetbiosOverTcpipEnabled.b[1]
  Ipv4Enabled.b[1]
  Ipv6Enabled.b[1]
  Ipv6ManagedAddressConfigurationSupported.b[1]
EndStructure

Structure IP_ADAPTER_ADDRESSES_IF_INDEX
  Length.i
  IfIndex.i
EndStructure

;length of the IP_ADAPTER_ADDRESS struct = 376 for Windows 7 in Pure basic
Structure IP_ADAPTER_ADDRESSES  ;->Structure IP_ADAPTER_ADDRESSES
  StructureUnion
    Alignment.q
    sIndexLength.IP_ADAPTER_ADDRESSES_IF_INDEX
  EndStructureUnion
*Next.IP_ADAPTER_ADDRESSES
*AdapterName ; unicode
*FirstUnicastAddress.IP_ADAPTER_UNICAST_ADDRESS
*FirstAnycastAddress.IP_ADAPTER_ANYCAST_ADDRESS
*FirstMulticastAddress.IP_ADAPTER_MULTICAST_ADDRESS
*FirstDnsServerAddress.IP_ADAPTER_DNS_SERVER_ADDRESS
*DnsSuffix;.PWCHAR
*Description;.PWCHAR ; in unicode - WideCharToMultiByte
*FriendlyName;.PWCHAR ; in unicode
PhysicalAddress.b[#MAX_ADAPTER_ADDRESS_LENGTH]
PhysicalAddressLength.i
StructureUnion
  Flags.i
  *pFlags.IP_ADAPTER_ADDRESSES_FLAGS
EndStructureUnion
Mtu.i
IfType.i
OperStatus.i ;l
Ipv6IfIndex.i
ZoneIndices.i[16] ; The SCOPE_LEVEL enumeration
*FirstPrefix.IP_ADAPTER_PREFIX
TransmitLinkSpeed.q
ReceiveLinkSpeed.q
*FirstWinsServerAddress.IP_ADAPTER_WINS_SERVER_ADDRESS
*FirstGatewayAddress.IP_ADAPTER_GATEWAY_ADDRESS
Ipv4Metric.i
Ipv6Metric.i
StructureUnion ;-> IF_LUID union - is another name for NET_LUID
  Value.q
  *Info.IF_LUID
EndStructureUnion
Dhcpv4Server.SOCKET_ADDRESS
CompartmentId.i[#IF_COMPARTMENT_ID_PRIMARY]
NetworkGuid.b[16]
ConnectionType.i
TunnelType.i
Dhcpv6Server.SOCKET_ADDRESS
Dhcpv6ClientDuid.b[#MAX_DHCPV6_DUID_LENGTH]
Dhcpv6ClientDuidLength.i
Dhcpv6Iaid.i
*FirstDnsSuffix.IP_ADAPTER_DNS_SUFFIX
EndStructure

Structure MIB_IF_ROW2_FLAGS
  HardwareInterface.b ;index 0
  FilterInterface.b;index 1
  ConnectorPresent.b;index 2
  NotAuthenticated.b;index 3
  NotMediaConnected.b;index 4
  Paused.b;index 5
  LowPower.b;index 6
  EndPointInterface.b;index 7
EndStructure

Structure NET_LUID  ;->Structure NET_LUID
  Reserved.q[24]
  NetLuidIndex.q[24]
  IfType.q[16]
EndStructure

Structure MIB_IF_ROW2  ;->Structure MIB_IF_ROW2
  StructureUnion ;-> NET_LUID union - is another name for IF_LUID
    Value.q 
    *Info.NET_LUID
  EndStructureUnion
  InterfaceIndex.i
  InterfaceGuid.b[16]
  Alias.w[#IF_MAX_STRING_SIZE +1]
  Description.w[#IF_MAX_STRING_SIZE +1]
  PhysicalAddressLength.i
  PhysicalAddress.b[#IF_MAX_PHYS_ADDRESS_LENGTH]
  PermanentPhysicalAddress.b[#IF_MAX_PHYS_ADDRESS_LENGTH]
  Mtu.i
  Type.i
  TunnelType.i
  MediaType.i
  PhysicalMediumType.i
  AccessType.i
  DirectionType.i
  *InterfaceAndOperStatusFlags.MIB_IF_ROW2_FLAGS
  OperStatus.i
  AdminStatus.i
  MediaConnectState.i
  NetworkGuid.b[16]
  ConnectionType.i
  TransmitLinkSpeed.q
  ReceiveLinkSpeed.q
  InOctets.q
  InUcastPkts.q
  InNUcastPkts.q
  InDiscards.q
  InErrors.q
  InUnknownProtos.q
  InUcastOctets.q
  InMulticastOctets.q
  InBroadcastOctets.q
  OutOctets.q
  OutUcastPkts.q
  OutNUcastPkts.q
  OutDiscards.q
  OutErrors.q
  OutUcastOctets.q
  OutMulticastOctets.q
  OutBroadcastOctets.q
  OutQLen.q ; not currently used
EndStructure

Structure MIB_IF_TABLE2  ;->Structure MIB_IF_TABLE2
  NumEntries.i
  Table.MIB_IF_ROW2[256]
EndStructure

Structure IP_ADDR_STRING  ;->Structure IP_ADDR_STRING 
  *Next.IP_ADDR_STRING 
  IpAddress.b[16] 
  IpMask.b[16] 
  Context.l 
EndStructure

Structure IP_PER_ADAPTER_INFO  ;->Structure IP_PER_ADAPTER_INFO
  AutoconfigEnabled.i
  AutoconfigActive.i
  *CurrentDnsServer.IP_ADDR_STRING
  DnsServerList.IP_ADDR_STRING
EndStructure

Structure IP_ADAPTER_INFO  ;->Structure IP_ADAPTER_INFO 
  *Next.IP_ADAPTER_INFO
  ComboIndex.l 
  AdapterName.b[#MAX_ADAPTER_NAME_LENGTH+4] 
  Description.b[#MAX_ADAPTER_DESCRIPTION_LENGTH+4] 
  AddressLength.l 
  Address.b[#MAX_ADAPTER_ADDRESS_LENGTH]
  Index.l 
  Type.l 
  DhcpEnabled.l 
  CurrentIpAddressPTR.l 
  IpAddressList.IP_ADDR_STRING 
  GatewayList.IP_ADDR_STRING 
  DhcpServer.IP_ADDR_STRING 
  HaveWins.l 
  PrimaryWinsServer.IP_ADDR_STRING 
  SecondaryWinsServer.IP_ADDR_STRING
  LeaseObtained.l 
  LeaseExpires.l 
EndStructure

Structure FIXED_INFO  ;->Structure FIXED_INFO
  HostName.b[#MAX_HOSTNAME_LEN + 4]
  DomainName.b[#MAX_DOMAIN_NAME_LEN + 4]
  *CurrentDnsServer.IP_ADDR_STRING
  DnsServerList.IP_ADDR_STRING
  NodeType.l
  ScopeId.b[#MAX_SCOPE_ID_LEN + 4]
  EnableRouting.l
  EnableProxy.l
  EnableDns.l
EndStructure

Structure MIB_IPNETROW  ;->Structure MIB_IPNETROW per win 7 sdk
  dwIndex.i
  dwPhysAddrLen.i
  bPhysAddr.b[#MAXLEN_PHYSADDR]
  dwAddr.i
  StructureUnion
    dwType.i ; // Old field name was just a DWORD.
    Type.i ; // New field name uses the enum type.
  EndStructureUnion
EndStructure

Structure MIB_IPNETTABLE  ;->Structure MIB_IPNETTABLE
  dwNumEntries.i
  table.MIB_IPNETROW[256] ; max num table entries in array
EndStructure

Structure MIB_IPSTATS
  StructureUnion
    dwForwarding.i
    Forwarding.i
  EndStructureUnion
  dwDefaultTTL.i
  dwInReceives.i
  dwInHdrErrors.i
  dwInAddrErrors.i
  dwForwDatagrams.i
  dwInUnknownProtos.i
  dwInDiscards.i
  dwInDelivers.i
  dwOutRequests.i
  dwRoutingDiscards.i
  dwOutDiscards.i
  dwOutNoRoutes.i
  dwReasmTimeout.i
  dwReasmReqds.i
  dwReasmOks.i
  dwReasmFails.i
  dwFragOks.i
  dwFragFails.i
  dwFragCreates.i
  dwNumIf.i
  dwNumAddr.i
  dwNumRoutes.i
EndStructure

Structure MIB_IPADDRROW
   dwAddr.l
   dwIndex.l
   dwMask.l
   dwBCastAddr.l
   dwReasmSize.l
   unused1.w
   wType.w
EndStructure

Structure MIB_IPADDRTABLE
   dwNumEntries.l
   Table.MIB_IPADDRROW[10]
EndStructure
 
Structure Scratch_Utility
  num_interfaces.i
  NodeType.s
  EnableRouting.s
  EnableProxy.s
  EnableDns.s
  HostName.s
  DomainName.s
  ScopeId.s
EndStructure

Global MyUtility.Scratch_Utility
Last edited by SFSxOI on Sun Aug 21, 2011 9:49 pm, edited 2 times in total.
The advantage of a 64 bit operating system over a 32 bit operating system comes down to only being twice the headache.
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Re: More than u ever wanted to know - Interfaces and Adapter

Post by SFSxOI »

part 2 - append to bottom of part 1 above

Code: Select all

Procedure CheckInetConnect(check_con_url$)
  ; check_con_url$ = "Internal" if using the ones already provided 
  ; if want to use another instead of internal check_con_url$ = "www.your_site.ext" i.e..."www.mysite.com", "www.mysite.org" etc...
  ; the http:// is added in the procedure
    
  Protected pingurl_a$, pingurl_b$, pingurl_c$, pingurl_d$
  Protected hPing_a,i, hPing_b.i
  
  check_conurl$ = "http://" + check_con_url$
  
  If check_con_url$ = "Internal"
  pingurl_a$ = "http://www.yahoo.com"
  pingurl_b$ = "http://www.google.com"
  pingurl_c$ = "http://www.google.de"
  pingurl_d$ = "http://www.dw-world.de"
  
  Select InternetCheckConnection_(@pingurl_a$,1,0) ; if we can't see this one then try another
    Case #False
      If InternetCheckConnection_(@pingurl_b$,1,0) = #True
        hPing_a = #True
      Else
        hPing_a = #False
      EndIf
    Case #True
      hPing_a = #True
    Default
  EndSelect
  
  Select hPing_a
    Case #False ; we try again for other areas in the world in case there is some sort of weird internet thing going on
      If InternetCheckConnection_(@pingurl_c$, 1, 0) = #True
        hPing_b = #True
      ElseIf InternetCheckConnection_(@pingurl_d$, 1, 0) = #True ; and for the last time
        hPing_b = #True
      Else
        hPing_b = #False
      EndIf
    Case #True
      hPing_b = #True
    Default
  EndSelect
  ; if none of the above responded it's a pretty sure bet that your not really able to use the internet at the time 
  Select hPing_b
    Case #True
      ProcedureReturn #True
    Case #False
      ProcedureReturn #False
    Default
      ProcedureReturn #False
  EndSelect
  
Else
  ProcedureReturn InternetCheckConnection_(@check_conurl$,1,0)
EndIf

EndProcedure

Procedure.s SubIPNetInfo(in_index.i, ipaddrin$, cherrypick.i)

pdwSize.i = 0
dwResult.i
IFindex.i

*pIPAddrTable.MIB_IPADDRTABLE = AllocateMemory(SizeOf(MIB_IPADDRTABLE))
  
dwResult = GetIpAddrTable_(*pIPAddrTable, @pdwSize, #True) ; call it the first time to get the required size - fails with #ERROR_INSUFFICIENT_BUFFER but we have the correct size

If dwResult = #ERROR_INSUFFICIENT_BUFFER
  
  *pIPAddrTable = ReAllocateMemory(*pIPAddrTable, pdwSize)
  dwRetVal = GetIpAddrTable_(*pIPAddrTable, @pdwSize, #True) ; call it the second time to get the info
  
  If dwRetVal = #NO_ERROR
    
    For i = 0 To *pIPAddrTable\dwNumEntries ; to - 1
      
      IFindex = *pIPAddrTable\Table[i]\dwIndex
      If IFindex = in_index And ipaddrin$ = PeekS(inet_ntoa_ (*pIPAddrTable\Table[i]\dwAddr));> 0 for the rest but we are cherry picking and only interested in a specific interface/adapter
        
        Select cherrypick
          Case 1 ; IP address
            ProcedureReturn PeekS(inet_ntoa_ (*pIPAddrTable\Table[i]\dwAddr))
          Case 2 ; subnet mask
            ProcedureReturn PeekS(inet_ntoa_(*pIPAddrTable\Table[i]\dwMask))
          Case 3 ; type
            type = *pIPAddrTable\Table[i]\wType
            If type & #MIB_IPADDR_PRIMARY
            ProcedureReturn " Primary IPv4 IP address for Adapter/Interface."
            EndIf
            If type & #MIB_IPADDR_DYNAMIC
              ProcedureReturn " Dynamically-allocated IPv4 IP address"
            EndIf
            If type & #MIB_IPADDR_DISCONNECTED
              ProcedureReturn " Address is on disconnected interface"
            EndIf
            If type & #MIB_IPADDR_DELETED
              ProcedureReturn " Address is being deleted"
            EndIf
            If type & #MIB_IPADDR_TRANSIENT
              ProcedureReturn " Transient address"
            EndIf
            If type & #MIB_IPADDR_DNS_ELIGIBLE
              ProcedureReturn " Address is published in DNS"
            EndIf
          Case 4 ; Part of subnet
            mask = *pIPAddrTable\Table[i]\dwMask
            msk$ = PeekS(inet_ntoa_(*pIPAddrTable\Table[i]\dwMask))
            subnet$ = msk$
            If mask = IntFromAddress(subnet$)
              ProcedureReturn "Part of subnet " + subnet$
            Else
              ProcedureReturn "Not part of subnet " + subnet$
            EndIf
          Case 5 ; Network address 
            ProcedureReturn PeekS(inet_ntoa_(*pIPAddrTable\Table[i]\dwAddr & *pIPAddrTable\Table[i]\dwMask))
          Default
        EndSelect
        
      EndIf
      
    Next

  EndIf
EndIf

If *pIPAddrTable
FreeMibTable(*pIPAddrTable)
*pIPAddrTable = #Null
EndIf

End
EndProcedure

Procedure.s Get_IpStatistics(cherry_pick.i)
dwRetval.i
*pStats.MIB_IPSTATS = AllocateMemory(SizeOf(MIB_IPSTATS))

If *pStats = #Null
  Debug "Unable to allocate memory for MIB_IPSTATS"
  MessageRequester("Error - Get_IpStatistics", "Unable to allocate memory for MIB_IPSTATS",  #MB_ICONWARNING|#PB_MessageRequester_Ok)
  CloseLibrary(Lib_iphlpapi)
  CloseLibrary(Lib_Winsock)
  CloseLibrary(Lib_Ntdll)
  WSACleanup_()
  End
EndIf

dwRetval = GetIpStatistics_(*pStats)

If dwRetval <> #NO_ERROR
  MessageRequester("Error - GetIpStatistics call failed with error : ", ShowAPIError(dwRetval),  #MB_ICONWARNING|#PB_MessageRequester_Ok)
  CloseLibrary(Lib_iphlpapi)
  CloseLibrary(Lib_Winsock)
  CloseLibrary(Lib_Ntdll)
  WSACleanup_()
  End
  
Else
  
  
  If cherry_pick = 1
  Select *pStats\dwForwarding
    Case #MIB_IP_FORWARDING
      ProcedureReturn "IP forwarding enabled"
    Case #MIB_IP_NOT_FORWARDING
      ProcedureReturn "IP forwarding disabled"
    Default
      ProcedureReturn "IP forwarding unknown value = " + Str(*pStats\dwForwarding)
  EndSelect
  EndIf

    If cherry_pick = 2 
            
            Debug "Default initial TTL : " + Str(*pStats\dwDefaultTTL)
    
            Debug "Number of received datagrams : " + Str(*pStats\dwInReceives)
            Debug "Number of received datagrams with header errors : " + Str(*pStats\dwInHdrErrors)
            Debug "Number of received datagrams with address errors : " + Str(*pStats\dwInAddrErrors)
    
            Debug "Number of datagrams forwarded : " + Str(*pStats\dwForwDatagrams)
    
            Debug "Number of received datagrams with an unknown protocol : " + Str(*pStats\dwInUnknownProtos)
            Debug "Number of received datagrams discarded : " + Str(*pStats\dwInDiscards)
            Debug "Number of received datagrams delivered : " + Str(*pStats\dwInDelivers)
    
            Debug "Number of outgoing datagrams requested to transmit : " + Str(*pStats\dwOutRequests)
            Debug "Number of outgoing datagrams discarded for routing : " + Str(*pStats\dwRoutingDiscards)
            Debug "Number of outgoing datagrams discarded : " + Str(*pStats\dwOutDiscards)
            Debug "Number of outgoing datagrams with no route to destination discarded : " + Str(*pStats\dwOutNoRoutes)
    
            Debug "Fragment reassembly timeout : " + Str(*pStats\dwReasmTimeout)
            Debug "Number of datagrams that required reassembly : " + Str(*pStats\dwReasmReqds)
            Debug "Number of datagrams successfully reassembled : " + Str(*pStats\dwReasmOks)
            Debug "Number of datagrams that could not be reassembled : " + Str(*pStats\dwReasmFails)
    
            Debug "Number of datagrams fragmented successfully : " + Str(*pStats\dwFragOks)
            Debug "Number of datagrams not fragmented and discarded : " + Str(*pStats\dwFragFails)
            Debug "Number of fragments created : " + Str(*pStats\dwFragCreates)
    
            Debug "Number of interfaces : " + Str(*pStats\dwNumIf)
            Debug "Number of IP addresses : " + Str(*pStats\dwNumAddr)
            Debug "Number of routes : " + Str(*pStats\dwNumRoutes)
            
    EndIf
      
        
EndIf
      
If *pStats
  FreeMemory(*pStats)
EndIf

EndProcedure

Procedure GetIp_NetTable()
i.i
x.i
*pIpNetTable.MIB_IPNETTABLE = #Null
dwSize.i = 0
dwRetVal.i = 0
dwResult.i
if_index.i

;#True = sort in ascending order by IP address
;#False = dont sort in ascending

dwResult = GetIpNetTable(#Null, @dwSize, #True) ; call it the second time to get needed size
If dwResult = #ERROR_INSUFFICIENT_BUFFER
  *pIpNetTable = AllocateMemory(dwSize)
  dwRetVal = GetIpNetTable(*pIpNetTable, @dwSize, #True) ; call it the second time to get the info
  If dwRetVal = #NO_ERROR Or dwRetVal = #ERROR_NO_DATA
    
    Debug "Number of entries in IPv4 ARP table : " + Str(*pIpNetTable\dwNumEntries) ; num entries includes the loop back interface entries
    
    For i = 0 To *pIpNetTable\dwNumEntries -1
      
      if_index = *pIpNetTable\table[i]\dwIndex
      
      *BufferAddrToString = AllocateMemory(256)
      RtlIpv4AddressToString(@*pIpNetTable\table[i]\dwAddr, *BufferAddrToString)
      IPaddr$ = PeekS(*BufferAddrToString)
      FreeMemory(*BufferAddrToString)
      
      macPhysicalAddress$="" 
        For x=0 To *pIpNetTable\table[i]\dwPhysAddrLen-1 
          If x 
            macPhysicalAddress$+":" 
          EndIf 
          byte.b=PeekB(@*pIpNetTable\table[i]\bPhysAddr[x])
          If byte>=0 
            macPhysicalAddress$+RSet(Hex(byte),2,"0") 
          Else 
            macPhysicalAddress$+RSet(Hex(byte+256),2,"0") 
          EndIf 
        Next
        
        Select *pIpNetTable\table[i]\dwType
          Case #MIB_IPNET_TYPE_OTHER
            arpentry$ = " Entry is other"
          Case #MIB_IPNET_TYPE_INVALID
            arpentry$ = " Entry is an invalid ARP type. This can indicate an unreachable or incomplete ARP entry."
          Case #MIB_IPNET_TYPE_DYNAMIC
            arpentry$ = " Entry is a dynamic ARP type."
          Case #MIB_IPNET_TYPE_STATIC
            arpentry$ = " Entry is a static ARP type."
          Default
            arpentry$ = " Entry ARP type is unknown."
        EndSelect
        
        Debug "Adapter/Interface Index " + Str(if_index) + " -  IPv4 address is : " + IPaddr$ + " === Remote (on subnet) MAC Address is : " + macPhysicalAddress$ + " ======= Type : " + arpentry$
        
    Next
    
  EndIf
EndIf

FreeMibTable(@*pIpNetTable)
 
EndProcedure

Procedure GetIfTableNumEnt()
  
  *TableNum.MIB_IF_TABLE2 = #Null
  
  GetIfTable2(@*TableNum)
  
  If *TableNum\NumEntries <> 0
    NumEntries.i = *TableNum\NumEntries
    FreeMibTable(*TableNum)
  EndIf
  
  If *TableNum\NumEntries = 0
    Debug "There are no Adapters, Interface's, Miniport's, Filters, or Scheduler's in this system !!! "
    FreeMibTable(*TableNum)
    CloseLibrary(Lib_iphlpapi)
    CloseLibrary(Lib_Winsock)
    CloseLibrary(Lib_Ntdll)
    End
  EndIf
  
  Debug "There are a total of " + Str(NumEntries) + " network or connection related Adapters, Interfaces, Miniports, Filters, or Scheduler's, in this system."
  Debug "Overall inventory of these items is shown below ::::"
  Debug "*************************************************************************************************************************************"
      
  For O = 1 To NumEntries 
  
*pIfRowOtherIf.MIB_IF_ROW2 = AllocateMemory(SizeOf(MIB_IF_ROW2))

Lib_ZeroMemory = OpenLibrary(#PB_Any,"kernel32.dll")
  If Lib_ZeroMemory
    retVala = CallFunction(Lib_ZeroMemory, "RtlSecureZeroMemory", *pIfRowOtherIf, SizeOf(MIB_IF_ROW2))
    If retVala = #NO_ERROR
      retVala = #NO_ERROR
    Else
      CloseLibrary(Lib_ZeroMemory)
      MessageRequester("Error - ZeroMemory", ShowAPIError(retVala), #PB_MessageRequester_Ok)
      End
    EndIf
    CloseLibrary(Lib_ZeroMemory)
  EndIf
  
  *pIfRowOtherIf\InterfaceIndex = O ;Indx
  
  retval = GetIfEntry2(*pIfRowOtherIf)
  If retval = #NO_ERROR
    retval = #NO_ERROR
  Else
    CloseLibrary(Lib_iphlpapi)
    CloseLibrary(Lib_Winsock)
    CloseLibrary(Lib_Ntdll)
    MessageRequester("Error - GetIfEntry2", ShowAPIError(retval), #PB_MessageRequester_Ok)
    End
  EndIf
  
  Description$ = PeekS(@*pIfRowOtherIf\Description, -1, #PB_Unicode)
  IfIndex$ = Str(*pIfRowOtherIf\InterfaceIndex)
  ConnectionAlias$ = PeekS(@*pIfRowOtherIf\Alias, -1, #PB_Unicode)
      
      macPhysicalAddress$="" 
      For a=0 To *pIfRowOtherIf\PhysicalAddressLength -1
        If a
          macPhysicalAddress$+":"
        EndIf
        byte.b=PeekB(@*pIfRowOtherIf\PhysicalAddress+a)
        If byte>=0
          macPhysicalAddress$+RSet(Hex(byte),2,"0")
        Else
          macPhysicalAddress$+RSet(Hex(byte+256),2,"0")
        EndIf
      Next
      
      *BufInterfaceGuid = AllocateMemory(80)
      StringFromGUID2_(@*pIfRowOtherIf\InterfaceGuid, *BufInterfaceGuid, 80)
      Ifguid$ = PeekS(*BufInterfaceGuid, -1, #PB_Unicode)
      FreeMemory(*BufInterfaceGuid)
      
      If Description$ = ""
        Debug "Description : Previously installed but now removed, uninstalled, disabled, or misconfigured, Adapter or Interface." ; - Or - trojan/worm/virus/root kit back door, hook, Or other activity.
        ;If you did not remove, disable, or uninstall, an Adapter/Interface in the past or there is no configuration or operation issue with an Adapter/Interface, and operating system has all current updates, 
        ;and all drivers are current and WHQL compliant, you should check your system for trojan/worm/virus/root kit. This could also indicate an Adapter/Interface was not uninstalled correctly
        ;with an improper uninstallation of an Adapter/Interface being a likely cause for this phantom entry.
        ;In no trojan/worm/virus/root kit issues exist, and there is no misconfiguration issue with an Adapter/Interface, and you previously removed, uninstalled, disabled, an Adapter/Interface,
        ;there is no cause for concern as its normal for Windows to leave past entries in some cases and these entries do not cause problems.
        ;However, you should check the system For current updates and drivers to ensure these are current.
      Else
        Debug "Description : " + Description$
      EndIf
      Debug Description$ + " Index : " + IfIndex$
      If macPhysicalAddress$ = ""
        Debug Description$ + " MAC Address : None"
      Else
        Debug Description$ + " MAC Address : " + macPhysicalAddress$
      EndIf
      Debug Description$ + " Interface GUID : " + Ifguid$
      Debug Description$ + " Connection Alias : " + ConnectionAlias$
      Debug "++++++++++++++++++++++++++++++++++++"
  
  Next
  
  FreeMemory(*pIfRowOtherIf)

EndProcedure

Procedure Get_Network_Params()
  
  *pFixedInfo.FIXED_INFO
  ulOutBufLen.l
  dwRetVal.i
  *pIPAddr.IP_ADDR_STRING
  
  
  *pFixedInfo.FIXED_INFO = AllocateMemory(SizeOf(FIXED_INFO))
  If *pFixedInfo = #Null
    MessageRequester("Error - GetNetworkParams", "Error allocating memory needed to call GetNetworkParams", #PB_MessageRequester_Ok)
    End
  EndIf
  ulOutBufLen = SizeOf(FIXED_INFO)
  ;Make an initial call to GetNetworkParams and get necessary size into ulOutBufLen
  If GetNetworkParams_(*pFixedInfo, @ulOutBufLen) = #ERROR_BUFFER_OVERFLOW
    FreeMemory(*pFixedInfo)
    *pFixedInfo.FIXED_INFO = AllocateMemory(ulOutBufLen)
    If *pFixedInfo = #Null
      MessageRequester("Error - Get_Network_Params", "Error allocating memory needed to call GetNetworkParams - *pFixedInfo is NULL", #PB_MessageRequester_Ok)
      End
    EndIf
    ;Make a second call to populate structure with info we want
    dwRetVal = GetNetworkParams_(*pFixedInfo, @ulOutBufLen)
    If dwRetVal = #NO_ERROR
      
      Select *pFixedInfo\NodeType
        Case #BROADCAST_NODETYPE
          MyUtility\NodeType = "Broadcast"
        Case #PEER_TO_PEER_NODETYPE
          MyUtility\NodeType = "Peer To Peer"
        Case #MIXED_NODETYPE
          MyUtility\NodeType = "Mixed"
        Case #HYBRID_NODETYPE
          MyUtility\NodeType = "Hybrid"
        Default
      EndSelect
      
      MyUtility\ScopeId = PeekS(@*pFixedInfo\ScopeId)
      MyUtility\DomainName = PeekS(@*pFixedInfo\DomainName)
      MyUtility\HostName = PeekS(@*pFixedInfo\HostName)
      
      
  If *pFixedInfo\EnableRouting = #True
    MyUtility\EnableRouting = "Routing is enabled on system."
  Else
    MyUtility\EnableRouting = "Routing is not enabled on system."
  EndIf
  
  If *pFixedInfo\EnableProxy = #True
    MyUtility\EnableProxy = "System is acting as ARP proxy."
  Else
    MyUtility\EnableProxy = "System is not acting as ARP proxy."
  EndIf
  
  If *pFixedInfo\EnableDns = #True
    MyUtility\EnableDns = "DNS enabled on local system."
  Else
    MyUtility\EnableDns = "DNS is not enabled on local system."
  EndIf
  
Else
  MessageRequester("Error - Get_Network_Params", "Second call to GetNetworkParams failed : " + ShowAPIError(dwRetVal), #PB_MessageRequester_Ok)
  End
EndIf
EndIf

FreeMemory(*pFixedInfo.FIXED_INFO)

EndProcedure
Last edited by SFSxOI on Sun Aug 21, 2011 9:44 pm, edited 2 times in total.
The advantage of a 64 bit operating system over a 32 bit operating system comes down to only being twice the headache.
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Re: More than u ever wanted to know - Interfaces and Adapter

Post by SFSxOI »

Part 3 - append to bottom of part 2 above

Code: Select all

Procedure.s GetLeaseSub(in_index.i, lease_sub_get.i)

*pAdapterInfo.IP_ADAPTER_INFO
*pAdapter.IP_ADAPTER_INFO  = #Null
dwRetVal.i = 0
gotlease.i = #False

ulOutBufLen = SizeOf(IP_ADAPTER_INFO)
*pAdapterInfo = AllocateMemory(SizeOf(IP_ADAPTER_INFO))

If *pAdapterInfo = #Null
  Debug "Error allocating memory needed to call GetAdaptersinfo 1"
  End
EndIf

If GetAdaptersInfo_(0, @ulOutBufLen) = #ERROR_BUFFER_OVERFLOW
  FreeMemory(*pAdapterInfo)
  *pAdapterInfo = AllocateMemory(ulOutBufLen)
  If *pAdapterInfo = #Null
    Debug "Error allocating memory needed to call GetAdaptersinfo 2"
    End
  EndIf
  dwRetVal = GetAdaptersInfo_(*pAdapterInfo, @ulOutBufLen)
  If dwRetVal = #NO_ERROR
    *pAdapter = *pAdapterInfo
    Repeat 
      
      If *pAdapter\Index = in_index
        
        Select lease_sub_get
          Case 1
            ProcedureReturn PeekS(@*pAdapter\IpAddressList\IpMask)
          Case 2
            ProcedureReturn FormatDate("%mm/%dd/%yyyy %hh;%mm:%ss",*pAdapter\LeaseObtained)
          Case 3
            ProcedureReturn FormatDate("%mm/%dd/%yyyy %hh;%mm:%ss",*pAdapter\LeaseExpires)
          Default
        EndSelect
        
        gotlease = #True
      EndIf
    Until gotlease = #True
  EndIf
EndIf

EndProcedure

Procedure.s GetPermPhysMAC(mib_mac_ifindex.i)
  ; this procedure is really for something else later but we are putting it to work just to test for calls to procedures right now for the future procedure that will be here
  ; and to test multiple calls for the same procedure configured for different information
  
  
  Protected a.i, retval.i, retVala.i, ifIndex.i  
  ;a.i
  retval = 0
  retVala = 0
  ifIndex = mib_mac_ifindex
  *pIfRowmac.MIB_IF_ROW2 = AllocateMemory(SizeOf(MIB_IF_ROW2))
  
  ; per MSDN, MIB_IF_ROW2 structure must be cleared first upon entry 
  ; see the msdn - it uses SecureZeroMemory for this structure
  ; SecureZeroMemory is defined as RtlSecureZeroMemory
  Lib_ZeroMemory = OpenLibrary(#PB_Any,"kernel32.dll")
  If Lib_ZeroMemory
    retVala = CallFunction(Lib_ZeroMemory, "RtlSecureZeroMemory", *pIfRowmac, SizeOf(MIB_IF_ROW2))
    If retVala = #NO_ERROR
      retVala = #NO_ERROR
    Else
      CloseLibrary(Lib_ZeroMemory)
      MessageRequester("Error - ZeroMemory", ShowAPIError(retVala), #PB_MessageRequester_Ok)
      End
    EndIf
    CloseLibrary(Lib_ZeroMemory)
  EndIf
    
  ; upon entry to the GetIfEntry2 function either the interface index or the interface LUID must be set first immediately prior to calling the function
  *pIfRowmac\InterfaceIndex = ifIndex ; the index of the interface we want info for
  
  retval = GetIfEntry2(*pIfRowmac)
  If retval = #NO_ERROR
    retval = #NO_ERROR
  Else
    CloseLibrary(Lib_iphlpapi)
    CloseLibrary(Lib_Winsock)
    CloseLibrary(Lib_Ntdll)
    MessageRequester("Error - GetIfEntry2", ShowAPIError(retval), #PB_MessageRequester_Ok)
    End
  EndIf
  
      macPermPhysicalAddress$="" 
        For a=0 To *pIfRowmac\PhysicalAddressLength-1 
          If a 
            macPermPhysicalAddress$+":" 
          EndIf 
          byte.b=PeekB(@*pIfRowmac\PermanentPhysicalAddress+a) 
          If byte>=0 
            macPermPhysicalAddress$+RSet(Hex(byte),2,"0") 
          Else 
            macPermPhysicalAddress$+RSet(Hex(byte+256),2,"0") 
          EndIf 
        Next
        
        If macPermPhysicalAddress$ = ""
          ProcedureReturn " None"
        Else
          ProcedureReturn macPermPhysicalAddress$
        EndIf
        
      FreeMemory(*pIfRowmac)
      
EndProcedure

Procedure GetIfEntry2MIB(mib_ifindex.i)
  Protected a.i, retval.i, retVala.i, ifIndex.i
  Global hardwareIf.i
  
  ;a.i
  retval = 0
  retVala = 0
  ifIndex.i = mib_ifindex
  *pIfRow.MIB_IF_ROW2 = AllocateMemory(SizeOf(MIB_IF_ROW2))
  
  ; per MSDN, this structure must be cleared first upon entry 
  ; see the msdn - it uses SecureZeroMemory for this structure
  ; SecureZeroMemory is defined as RtlSecureZeroMemory
    
  Lib_ZeroMemory = OpenLibrary(#PB_Any,"kernel32.dll")
  If Lib_ZeroMemory
    retVala = CallFunction(Lib_ZeroMemory, "RtlSecureZeroMemory", *pIfRow, SizeOf(MIB_IF_ROW2))
    If retVala = #NO_ERROR
      retVala = #NO_ERROR
    Else
      CloseLibrary(Lib_ZeroMemory)
      MessageRequester("Error - ZeroMemory", ShowAPIError(retVala), #PB_MessageRequester_Ok)
      End
    EndIf
    CloseLibrary(Lib_ZeroMemory)
  EndIf
  
  ; upon entry to the GetIfEntry2 function either the interface index or the interface LUID must be set first immediately prior to calling the function
  *pIfRow\InterfaceIndex = ifIndex ; the index of the interface we want info for
  
  retval = GetIfEntry2(*pIfRow)
  If retval = #NO_ERROR
    retval = #NO_ERROR
  Else
    CloseLibrary(Lib_iphlpapi)
    CloseLibrary(Lib_Winsock)
    CloseLibrary(Lib_Ntdll)
    MessageRequester("Error - GetIfEntry2", ShowAPIError(retval), #PB_MessageRequester_Ok)
    End
  EndIf
  
  If FindString(PeekS(@*pifRow\Description, -1, #PB_Unicode), "Adapter", 1) = 0
    int_adap$ = "Interface"
  Else
    int_adap$ = "Adapter"
  EndIf
  
        Select *pIfRow\DirectionType
        Case #NET_IF_DIRECTION_SENDRECEIVE
          dirtectiontyp$ = int_adap$ + " Send and Receive - This direction type indicates the NDIS network interface can send and receive data."
        Case #NET_IF_DIRECTION_SENDONLY
          dirtectiontyp$ = int_adap$ + " Send only - This direction type indicates the NDIS network interface can only send data. "
        Case #NET_IF_DIRECTION_RECEIVEONLY
          dirtectiontyp$ = int_adap$ + " Receive only - This direction type indicates the NDIS network interface can only receive data."
        Default
          dirtectiontyp$ = int_adap$ + " Direction is unspecific, unknown, or not defined. If you see this you should check for issues or updates."
      EndSelect
      
      Debug dirtectiontyp$
      
      Select *pIfRow\AdminStatus
        Case #MIB_IF_ADMIN_STATUS_UP
          adminstat$ = "The " + int_adap$ + " is initialized and enabled but aot necessarily ready ao transmit/receive aata because it depends on the operational use status of the " + int_adap$
        Case #MIB_IF_ADMIN_STATUS_DOWN
          adminstat$ = "The " + int_adap$ +  " is down, and cannot be used to transmit or receive network data. "
        Case #MIB_IF_ADMIN_STATUS_TESTING
          adminstat$ = "The " + int_adap$ + " is in a test mode, and no network data can be transmitted or received."
        Default
          adminstat$ = int_adap$ + " Admin status is unknown"
      EndSelect
      
      Select *pIfRow\MediaConnectState
        Case #MediaConnectStateUnknown
          ConnectorPlugged$ = int_adap$ + " Connector status is unknown."
        Case #MediaConnectStateConnected
          ConnectorPlugged$ = int_adap$ + " Connector is plugged in."
        Case #MediaConnectStateDisconnected
          ConnectorPlugged$ = int_adap$ + " Connector is not plugged in. On wireless connections this may indicate you are not connected to a network."
        Default
          ConnectorPlugged$ = "Unable to detect " + int_adap$ + " Connector status or presence."
      EndSelect
      
        Select *pIfRow\OperStatus
         Case #IfOperStatusUp ;= 1
            oper_status$ = int_adap$ + " is up and able to pass packets."
         Case #IfOperStatusDown ;= 2
            oper_status$ = int_adap$ + " is down and not in a condition to pass packets."
         Case #IfOperStatusTesting ;= 3
            oper_status$ = int_adap$ + " is in testing mode."
         Case #IfOperStatusUnknown ;= 4
            oper_status$ = int_adap$ + " operational status is unknown."
         Case #IfOperStatusDormant ;= 5
            oper_status$ = int_adap$ + " is not up, but is in a pending state waiting for some external event"
         Case #IfOperStatusNotPresent ;= 6
            oper_status$ = int_adap$ + " is down specifically because some component is not present in the managed system."
         Case #IfOperStatusLowerLayerDown ;= 7
           oper_status$ = "This " + int_adap$ + " runs on top of one or more other " + int_adap$ + " 's and this " + int_adap$ + " is down specifically because one or more of these lower-layer " + int_adap$ + "'s are down"
         Default
           oper_status$ = int_adap$ + " operational status is unknown, or " + int_adap$ + " is in a fault or malfunction condition."
       EndSelect
       
       Debug oper_status$
       
       ; small mention blurp in rfc2863 - http://www.ietf.org/rfc/rfc2863.txt - but applicapable to hardware interfaces only
       If Val(ReadMIBRowBitField(*pIfRow\InterfaceAndOperStatusFlags, 0, 1)) = 1
         If *pIfRow\AdminStatus = 1 And *pIfRow\OperStatus <> 1
           Debug int_adap$ + " Fault Status : The " + int_adap$ + " is possibly in a fault condition."
         Else
           Debug int_adap$ + " Fault Status : The " + int_adap$ + " does not appear to be in a fault condition."
         EndIf
       EndIf
            
       ;**********read the bit field in the InterfaceAndOperStatusFlags.MIB_IF_ROW2_LH_FLAGS structure ***************************
       If Val(ReadMIBRowBitField(*pIfRow\InterfaceAndOperStatusFlags, 0, 1)) = 1 ; hardwareinterface$
         hardwareIf = #True 
         MIBhardwareinterface$ = int_adap$ + " is a hardware " + int_adap$
       Else
         hardwareIf = #False
         MIBhardwareinterface$ = int_adap$ + " is not a hardware " + int_adap$ + " and is a software/logical construct " + int_adap$ 
       EndIf
       
       If Val(ReadMIBRowBitField(*pIfRow\InterfaceAndOperStatusFlags, 1, 1)) = 1 ; MIBfilterinterface
         MIBfilterinterface$ = int_adap$ + " is a Filter Interface"
       Else
         MIBfilterinterface$ = int_adap$ + " is not a Filter Interface"
       EndIf
       
       If Val(ReadMIBRowBitField(*pIfRow\InterfaceAndOperStatusFlags, 2, 1)) = 1 ; MIBconnectorpresent
         MIBconnectorpresent$ = int_adap$ + " has a connector present"
       Else
         MIBconnectorpresent$ = int_adap$ + " does not have a connector present"
       EndIf
       
       If Val(ReadMIBRowBitField(*pIfRow\InterfaceAndOperStatusFlags, 3, 1)) = 1
         MIBportauthenticated$ = int_adap$ + " port is not authenticated. If this is a wireless device, this may indicate not connected to network."
       Else
         MIBportauthenticated$ = int_adap$ + " port is authenticated."
       EndIf
       
       If Val(ReadMIBRowBitField(*pIfRow\InterfaceAndOperStatusFlags, 4, 1)) = 1
         MIBmediaconnected$ = int_adap$ + " is not media connected."
       Else
         MIBmediaconnected$ = int_adap$ + " is media connected."
       EndIf
       
       If Val(ReadMIBRowBitField(*pIfRow\InterfaceAndOperStatusFlags, 5, 1)) = 1
         MIBintfacepaused$ = int_adap$ + " is paused."
       Else
         MIBintfacepaused$ = int_adap$ + " is not paused."
       EndIf
       
       If Val(ReadMIBRowBitField(*pIfRow\InterfaceAndOperStatusFlags, 6, 1)) = 1
         MIBintfacelowpower$ = int_adap$ + " is at low power."
       Else
         MIBintfacelowpower$ = int_adap$ + " is not at low power."
       EndIf
       
       If Val(ReadMIBRowBitField(*pIfRow\InterfaceAndOperStatusFlags, 7, 1)) = 1
         MIBifendpoint$ = int_adap$ + " is an End Point device (for example, a smart phone) and not a true interface that connects to a network."
       Else
         MIBifendpoint$ = int_adap$ + " is not an End Point device (for example, a smart phone) and is a true interface that connects to a network."
       EndIf
       
       Debug MIBhardwareinterface$
       Debug MIBfilterinterface$
       Debug MIBconnectorpresent$
       Debug ConnectorPlugged$
       Debug MIBportauthenticated$
       Debug MIBintfacepaused$
       Debug MIBintfacelowpower$
       Debug MIBifendpoint$
        
        
      
      Debug int_adap$ + " Admin Status : " + adminstat$
      Debug int_adap$ + " Direction Type : " + dirtectiontyp$
      Debug int_adap$ + " Media Type : " + NDISMedium(*pIfRow\MediaType)
      Debug int_adap$ + " Physical Medium Type : " + NDIS_Physical_Medium(*pIfRow\PhysicalMediumType)
      Debug int_adap$ + " Media Connect Status : " + MIBmediaconnected$
      Debug int_adap$ + " Access Type : " + AccessType(*pIfRow\AccessType)
      
      FreeMemory(*pIfRow)
      
EndProcedure
Last edited by SFSxOI on Sun Aug 21, 2011 8:33 pm, edited 1 time in total.
The advantage of a 64 bit operating system over a 32 bit operating system comes down to only being twice the headache.
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Re: More than u ever wanted to know - Interfaces and Adapter

Post by SFSxOI »

Part 4 - append to bottom of part 3 above

Code: Select all

Procedure GetInterfaceInfo()
  
  ; we use WSAStartup through out instead of PB InitNetwork so we can ensure control of the winsock version being used per requirement
  ; we want to ensure we use the highest version of winsock for later interaction with other winsock version specific procedures per requirement with our 
  ; modified winsock also
WSAStart.i = WSAStartup_($0202,@wsaData.WSADATA) ; $0202 is for winsock 2.2 and up

dwRetVal.i = 0
got_buffer.i = #False
;buff.c = 100
outBufLen.i = 15000 ;15KB is recomended by MS at http://msdn.microsoft.com/en-us/library/aa365915(VS.85).aspx for a pre-allocated amount
*pAddresses.IP_ADAPTER_ADDRESSES = #Null
*pCurrAddresses.IP_ADAPTER_ADDRESSES = #Null
*pUnicast.IP_ADAPTER_UNICAST_ADDRESS = #Null
*pAnycast.IP_ADAPTER_ANYCAST_ADDRESS = #Null
*pMulticast.IP_ADAPTER_MULTICAST_ADDRESS = #Null
*pDnServer.IP_ADAPTER_DNS_SERVER_ADDRESS = #Null
*pPrefix.IP_ADAPTER_PREFIX = #Null
*pGatewayAddress.IP_ADAPTER_GATEWAY_ADDRESS = #Null
*pDhcpv4Server.SOCKET_ADDRESS = #Null
*pDhcpv6Server.SOCKET_ADDRESS = #Null
*pDnsSuffix.IP_ADAPTER_DNS_SUFFIX = #Null
*pWinsServer.IP_ADAPTER_WINS_SERVER_ADDRESS = #Null
*pAddresses.IP_ADAPTER_ADDRESSES = AllocateMemory(outBufLen)


If Lib_iphlpapi And Lib_Winsock
  
  Repeat ; #AF_UNSPEC - to get both IPv4 and IPv6
    dwRetVal = GetAdaptersAddresses(#AF_UNSPEC, #GAA_FLAG_INCLUDE_PREFIX|#GAA_FLAG_INCLUDE_GATEWAYS, #Null, *pAddresses, @outBufLen)
    Select dwRetVal
      Case #NO_ERROR
        got_buffer = #True ; Can exit repeat loop now
      Case #ERROR_BUFFER_OVERFLOW
        buf_retry.i = buf_retry + 1 ; has always gotten it on the first try and this comes up 0 but ya never know
        FreeMemory(*pAddresses)
        *pAddresses.IP_ADAPTER_ADDRESSES = ReAllocateMemory(*pAddresses.IP_ADAPTER_ADDRESSES, outBufLen) ; ; Increase buffer size to MS recommeded pre-allocation and try again
      Default
        MessageRequester("Error - GetAdaptersAddresses failed : ", ShowAPIError(dwRetVal),  #MB_ICONWARNING|#PB_MessageRequester_Ok)
        CloseLibrary(Lib_iphlpapi)
        CloseLibrary(Lib_Winsock)
        CloseLibrary(Lib_Ntdll)
        WSACleanup_()
        End
    EndSelect
    If buf_retry > 3
      Break
      CloseLibrary(Lib_iphlpapi)
      CloseLibrary(Lib_Winsock)
      CloseLibrary(Lib_Ntdll)
      WSACleanup_()
      MessageRequester("Error - GetAdaptersAddresses failed : ", "More than three passes getting buffer",  #MB_ICONWARNING|#PB_MessageRequester_Ok)
      End
    EndIf
    Delay(1)
  Until got_buffer = #True
    
  dwRetVal = GetAdaptersAddresses(#AF_UNSPEC, #GAA_FLAG_INCLUDE_PREFIX|#GAA_FLAG_INCLUDE_GATEWAYS, #Null, *pAddresses, @outBufLen)

  If dwRetVal = #NO_ERROR
    
    *pCurrAddresses = *pAddresses
        
    Get_Network_Params()
    
    Debug "************Overall System Information*************"
    Debug "System Host Name : " + MyUtility\HostName
    Debug "System Domain Name : " + MyUtility\DomainName
    Debug "System Node Type : " + MyUtility\NodeType
    Debug "System Routing : " + MyUtility\EnableRouting
    Debug "System ARP Proxy : " + MyUtility\EnableProxy
    Debug "System DNS enabled status : " + MyUtility\EnableDns
    Debug "System IP Forwarding : " + Get_IpStatistics(1)
    
    If CheckInetConnect("Internal") = #True
      InternetConnect$ = "The system can connect to the internet."
    Else
      InternetConnect$ = "The system can not connect to the internet."
    EndIf
    Debug "System Internet Connection Status : " + InternetConnect$
    Debug "********************************************"
    
    GetIfTableNumEnt()
    
    Debug ""
    Debug "**********************************************************************"
    Debug "Adapters or Interfaces with IP address assignment, or in use, detail shown below ::::"
    Debug "**********************************************************************"
    
    ; start the big loop here
    While *pCurrAddresses ;And *pCurrAddresses\PhysicalAddressLength >= 6 And Val(ReadMIBRowBitField(*pCurrAddresses\pFlags, 2, 1)) = 1 ; just get the ones with DHCP enable and for hardware only and we make sure there is a mac address, want hardware and not everything
            
      descrip$ = PeekS(*pCurrAddresses\Description, -1, #PB_Unicode)
      
      If FindString(descrip$, "Adapter", 1) = 0
        int_adap$ = "Interface"
        z = z + 1
      Else
        int_adap$ = "Adapter"
        y = y + 1
      EndIf
      
      If int_adap$ = "Interface"
        Debug "This is " + int_adap$ + " Entry # " + Str(z)
        Debug "----------"
      EndIf
      
      If int_adap$ = "Adapter"
        Debug "This is " + int_adap$ + " Entry # " + Str(y)
        Debug "----------"
      EndIf
      
      If int_adap$ <> "Adapter" And int_adap$ <> "Interface"
        int_adap$ = "UNKNOWN INTERFACE/ADAPTER"
        u = u + 1
      EndIf
      
      NameInterfaceGUID$ = PeekS(*pCurrAddresses\AdapterName)
      Debug int_adap$ + " Description : " + descrip$
      ; if a description or other info appears but no Interface GUID appears then we have a problem
      Debug int_adap$ + " Name (Interface GUID) : " + NameInterfaceGUID$
      ; if the Interface GUID appears we should be able to trace it to the full system path name in the registry - send to registry routines if trace needed
      Debug int_adap$ + " full system path name : " + "\DEVICE\TCPIP_" + NameInterfaceGUID$
            
      ; get the network GUID
      ; the GUID is a wide string - The string that represents the GUID includes enclosing braces and '-' = 38 characters in the GUID
      ; in C++ this is 38 + 1 = 39 but in Pure Basic it comes out to 39 + 1.
      ; The buffer needs to have space for 39 wide characters + 1 = 2 x num chr wide = 2 * (39 + 1) = 80 for the buffer
      *BufNetworkGuid = AllocateMemory(80)
      NetGUIDLen.i = StringFromGUID2_(@*pCurrAddresses\NetworkGuid, *BufNetworkGuid, 80)
      netwrkguid$ = PeekS(*BufNetworkGuid, -1, #PB_Unicode)
      FreeMemory(*BufNetworkGuid)
      Debug int_adap$ + " Network GUID : " + netwrkguid$
      ipv4_InterfaceIndex.i = *pCurrAddresses\sIndexLength\IfIndex
      ipv6_InterfaceIndex.i = *pCurrAddresses\Ipv6IfIndex
      
      NetInfIndex$ = Str(*pCurrAddresses\sIndexLength\IfIndex)
      
      Debug int_adap$ + " Index (IPv4) : " + Str(ipv4_InterfaceIndex)
      ; its possible for the IPv6 and IPv4 index to be different depending on adapter/interface type - no immediate cause for alarm if this is known to be true
      ; but if its known to not be true then check it out as subject may be using special filtering to avoid detection on network
      Debug int_adap$ + " Index (IPv6) : " + Str(ipv6_InterfaceIndex)
      
      *BufInterfaceName = AllocateMemory(#IF_NAMESIZE+1)
      if_indextoname(ipv4_InterfaceIndex, *BufInterfaceName)
      Debug int_adap$ + " IPv4 Name : " + PeekS(*BufInterfaceName)
      FreeMemory(*BufInterfaceName)
      
      *BufInterfaceName = AllocateMemory(#IF_NAMESIZE+1)
      if_indextoname(ipv6_InterfaceIndex, *BufInterfaceName)
      Debug int_adap$ + " IPv6 Name : " + PeekS(*BufInterfaceName)
      FreeMemory(*BufInterfaceName)
      
      Debug int_adap$ + " Connection Friendly Name : " + PeekS(*pCurrAddresses\FriendlyName, -1, #PB_Unicode)
      
      If *pCurrAddresses\Mtu = -1
        Debug int_adap$ + " MTU : NONE or Not Applicapable"
      Else
        Debug int_adap$ + " MTU : " + Str(*pCurrAddresses\Mtu)
      EndIf
      
      ; The MAC address's
      macPhysicalAddress$ = ""
      If *pCurrAddresses\PhysicalAddressLength >= 6
        macPhysicalAddress$="" 
        For x=0 To *pCurrAddresses\PhysicalAddressLength-1 
          If x 
            macPhysicalAddress$+":" 
          EndIf 
          byte.b=PeekB(@*pCurrAddresses\PhysicalAddress+x) 
          If byte>=0 
            macPhysicalAddress$+RSet(Hex(byte),2,"0") 
          Else 
            macPhysicalAddress$+RSet(Hex(byte+256),2,"0") 
          EndIf 
        Next
      EndIf
      
      
        If macPhysicalAddress$ = ""
          Debug int_adap$ + " Current Physical Address (MAC Address) : None"
        Else
          Debug int_adap$ + " Current Physical Address (MAC Address) : " + macPhysicalAddress$
        EndIf
        ; then we get the Perm MAC as a NIC can have a changed set MAC and a Perm (default) MAC - if current MAC and perm MAC are different
        ; we know the MAC has been changed or if changed then if same still then the NIC does not have a burned in perm MAC
        Debug int_adap$ + " Permanent Physical Address (MAC Address) : " + GetPermPhysMAC(*pCurrAddresses\sIndexLength\IfIndex)
              
        ; these are speed settings for the interface as set at the time of run, not the speed in use
        Debug int_adap$ + " Transmit Speed Setting: " + Str(PeekQ(@*pCurrAddresses\TransmitLinkSpeed)) + " bits per second"
        Debug int_adap$ + " Receive Speed Setting : " + Str(PeekQ(@*pCurrAddresses\ReceiveLinkSpeed)) + " bits per second"
      
       Select *pCurrAddresses\ConnectionType
         Case #NET_IF_CONNECTION_DEDICATED
           NET_IF_CONNECTION$ = "Dedicated - Comes up automatically when media sense is TRUE. For example, an Ethernet connection is dedicated."
         Case #NET_IF_CONNECTION_PASSIVE
           NET_IF_CONNECTION$ = "Passive - Remote end must bring up the connection To the local station. For example, a RAS Interface is passive."
         Case #NET_IF_CONNECTION_DEMAND
           NET_IF_CONNECTION$ = "Demand-dial - Comes up in response to local action (for example, sending a packet)."
         Case #NET_IF_CONNECTION_MAXIMUM
           NET_IF_CONNECTION$ = "NET_IF_CONNECTION_MAXIMUM - Maximum possible value for connection yype. Testing Purposes - not a legal value for Connection Type."
         Default
           NET_IF_CONNECTION$ = "Not a legal value for Connection Type."
       EndSelect
       
       Select *pCurrAddresses\TunnelType ; this may not work properly with multiple hardware interfaces in system for some reason
         Case #TUNNEL_TYPE_NONE ;0
           TunnelTyp$ = "NONE: Not a tunnel."
         Case #TUNNEL_TYPE_OTHER ;1
           TunnelTyp$ = "None of the known tunnel types."
         Case #TUNNEL_TYPE_DIRECT ;2 
           TunnelTyp$ = "A packet encapsulated directly within a normal IP header, with no intermediate header, and unicast o the remote tunnel endpoint."
         Case #TUNNEL_TYPE_6TO4 ;11
           TunnelTyp$ = "An IPv6 packet encapsulated directly within an IPv4 header, with no intermediate header, and unicast to the destination determined by the 6to4 protocol."
         Case #TUNNEL_TYPE_ISATAP ;13
           TunnelTyp$ = "An IPv6 packet encapsulated directly within an IPv4 header, With no intermediate header, and unicast to the destination determined by the ISATAP protocol."
         Case #TUNNEL_TYPE_TEREDO ;14
           TunnelTyp$ = "Teredo encapsulation for IPv6 packets."
         Case #TUNNEL_TYPE_IPHTTPS ;15
           TunnelTyp$ = "IP over HTTPS encapsulation for IPv6 packets."
         Default
           TunnelTyp$ = "Unknown."
       EndSelect
      
      Debug int_adap$ + " Connection Type : " + NET_IF_CONNECTION$
      Debug int_adap$ + " TunnelType : " + TunnelTyp$
      If Len(PeekS(*pCurrAddresses\DnsSuffix, -1, #PB_Unicode)) > 1
        Debug int_adap$ + " Dns Suffix : " + PeekS(*pCurrAddresses\DnsSuffix, -1, #PB_Unicode)
      Else
        Debug int_adap$ + " Dns Suffix : NONE"
      EndIf
      
;*************************************************************************

; flags bit field for IP_ADAPTER_ADDRESSES structure at IP_ADAPTER_ADDRESSES_FLAGS

       If Val(ReadMIBRowBitField(*pCurrAddresses\pFlags, 2, 1)) = 1
         Dhcpenab$ = int_adap$ + " Dynamic Host Configuration Protocol (DHCP) is enabled"
       Else
         Dhcpenab$ = int_adap$ + " Dynamic Host Configuration Protocol (DHCP) is not enabled" 
       EndIf
       Debug Dhcpenab$

       If Val(ReadMIBRowBitField(*pCurrAddresses\pFlags, 0, 1)) = 1
         DDNS$ = int_adap$ + " Dynamic DNS is enabled"
       Else
         DDNS$ = int_adap$ + " Dynamic DNS is not enabled"
       EndIf
       Debug DDNS$       
       
       If Val(ReadMIBRowBitField(*pCurrAddresses\pFlags, 1, 1)) = 1
         RggAdapSuf$ = int_adap$ + " configured to register the DNS suffix."
       Else
         RggAdapSuf$ = int_adap$ + " not configured to register the DNS suffix."
       EndIf
       Debug RggAdapSuf$
       
       If Val(ReadMIBRowBitField(*pCurrAddresses\pFlags, 3, 1)) = 1
         RxOnly$ = int_adap$ + " is a receive-only " + int_adap$
       Else
         RxOnly$ = int_adap$ + " is not a receive-only " + int_adap$
       EndIf
       Debug RxOnly$
       
       If Val(ReadMIBRowBitField(*pCurrAddresses\pFlags, 4, 1)) = 1
         Multicast$ = int_adap$ + " is not a multicast recipient."
       Else
         Multicast$ = int_adap$ + " is a multicast recipient."
       EndIf
       Debug Multicast$
       
       If Val(ReadMIBRowBitField(*pCurrAddresses\pFlags, 6, 1)) = 1
         NetBiosTCP$ = int_adap$ + " NetBIOS over TCP/IP enabled."
       Else
         NetBiosTCP$ = int_adap$ + " NetBIOS over TCP/IP not enabled."
       EndIf
       Debug NetBiosTCP$
       
       If Val(ReadMIBRowBitField(*pCurrAddresses\pFlags, 7, 1)) = 1
         IfIpv4Enabled$ = int_adap$ + " enabled for IPv4."
       Else
         IfIpv4Enabled$ = int_adap$ + " not enabled for IPv4."
       EndIf
       Debug IfIpv4Enabled$
       
       If Val(ReadMIBRowBitField(*pCurrAddresses\pFlags, 8, 1)) = 1
         IfIpv6Enabled$ = int_adap$ + " enabled for IPv6."
       Else
         IfIpv6Enabled$ = int_adap$ + " not enabled for IPv6."
       EndIf
       Debug IfIpv6Enabled$
       
       If Val(ReadMIBRowBitField(*pCurrAddresses\pFlags, 5, 1)) = 1
         OtherIPV6State$ = int_adap$ + " has other IPv6-specific stateful configuration information."
       Else
         OtherIPV6State$ = int_adap$ + " does not have other IPv6-specific stateful configuration information."
       EndIf
       Debug OtherIPV6State$
       
       If Val(ReadMIBRowBitField(*pCurrAddresses\pFlags, 9, 1)) = 1
         IfIpv6Managed$ = int_adap$ + " enabled for IPv6 managed address configuration."
       Else
         IfIpv6Managed$ = int_adap$ + " not enabled for IPv6 managed address configuration."
       EndIf
       Debug IfIpv6Managed$
       
       ; then we get the rest of the status and operation info we want to display
       GetIfEntry2MIB(*pCurrAddresses\sIndexLength\IfIndex)

       ;**************************************************************************
       Debug "******************************************************************************"
              
       ;....Address\iSockaddrLength normally equal 16 for IPv4 and 28 for IPv6
       
       ; lets get some address info now - the Unicast IP's are the ones the interface is using
        
       If Val(ReadMIBRowBitField(*pCurrAddresses\pFlags, 2, 1)) = 1 ; (is dhcp enabled on interface?); if DHCP is not enabled/used then we don't bother to get the DHCP server addresses
         
       *pDhcpv4Server = *pCurrAddresses\Dhcpv4Server 
       If *pDhcpv4Server <> #Null; if there is no Dhcpv4 Server
         ;If *pDhcpv4Server\lpSockaddr\ss_family = #AF_INET ; don't use this line unless actually using a DHCP IPv4 server because the pointer will be null
         bufferlenDHCPAddr=0
         If WSAAddressToString(*pDhcpv4Server\lpSockaddr, *pDhcpv4Server\iSockaddrLength, #Null, -1, @bufferlenDHCPAddr) = #SOCKET_ERROR
           If bufferlenDHCPAddr
             *pBufferDHCPAddr = AllocateMemory(bufferlenDHCPAddr)
             If *pBufferDHCPAddr And WSAAddressToString(*pDhcpv4Server\lpSockaddr, *pDhcpv4Server\iSockaddrLength, #Null,*pBufferDHCPAddr, @bufferlenDHCPAddr) = 0
               DHCPIPv4Server$ = PeekS(*pBufferDHCPAddr)
               Debug descrip$ + " using DHCP IPv4 Server Address : " + DHCPIPv4Server$
               ;Debug "**************************************************"
             Else
               ;MessageRequester("Error - Get DHCP IPv4 Address failed : ", ShowAPIError(WSAGetLastError_()),  #MB_ICONWARNING|#PB_MessageRequester_Ok)
               ;Debug "Get DHCP IPv4 Address failed : " + ShowAPIError(WSAGetLastError_())
             EndIf
           EndIf
           If *pBufferDHCPAddr
             FreeMemory(*pBufferDHCPAddr)
           EndIf
         EndIf
         ;EndIf ; for ;If *pDhcpv4Server\lpSockaddr\ss_family = #AF_INET
       EndIf
        
        *pDhcpv6Server = *pCurrAddresses\Dhcpv6Server
        If *pDhcpv6Server <> #Null; if there is no Dhcpv6 Server
          ;If *pDhcpv6Server\lpSockaddr\ss_family = #AF_INET6; don't use this line unless actually using a DHCP IPv6 server because the pointer will be null
          bufferlenDHCPIp6Addr=0
          If WSAAddressToString(*pDhcpv6Server\lpSockaddr, *pDhcpv6Server\iSockaddrLength, #Null, -1, @bufferlenDHCPIp6Addr) = #SOCKET_ERROR
            If bufferlenDHCPIp6Addr
              *pBufferDHCPIp6Addr = AllocateMemory(bufferlenDHCPIp6Addr)
              If *pBufferDHCPIp6Addr And WSAAddressToString(*pDhcpv6Server\lpSockaddr, *pDhcpv6Server\iSockaddrLength, #Null,*pBufferDHCPIp6Addr, @bufferlenDHCPIp6Addr) = 0
                DHCPIPv6Server$ = PeekS(*pBufferDHCPIp6Addr)
                Debug descrip$ + " using DHCP IPv6 Server Address : " + DHCPIPv6Server$
                ;Debug "**************************************************"
              Else
                ;MessageRequester("Error - Get DHCP IPv6 Address failed : ", ShowAPIError(WSAGetLastError_()),  #MB_ICONWARNING|#PB_MessageRequester_Ok)
                ;Debug "Get DHCP IPv6 Address failed : " + ShowAPIError(WSAGetLastError_())
              EndIf
            EndIf
            If *pBufferDHCPIp6Addr
              FreeMemory(*pBufferDHCPIp6Addr)
            EndIf
            ;Debug "**************************************************"
          EndIf
        ;EndIf ;for If *pDhcpv6Server\lpSockaddr\ss_family = #AF_INET6
        EndIf
    EndIf ; if no DHCP enabled for interface we just don't show anything for DHCP servers
    
      
      *pWinsServer = *pCurrAddresses\FirstWinsServerAddress
      If *pWinsServer <> #Null
        While *pWinsServer <> #Null
          WinsServer.i = WinsServer + 1
          *pWinsServer = *pWinsServer\Next
        Wend
        Debug "Number of " + descrip$ + " Wins Server Addresses : " + Str(WinsServer)
        WinsServer = 0
      EndIf
      
      ; get pMulticast
      *pWinsServer = *pCurrAddresses\FirstWinsServerAddress
      If *pWinsServer <> #Null
        While  *pWinsServer <> #Null
          Select *pWinsServer\Address\lpSockaddr\ss_family
            Case #AF_INET
              inet$ = "IPv4"
            Case #AF_INET6
              inet$ = "IPv6"
            Case #AF_UNSPEC
              inet$ = "IP version unspecific - not IPv4 or IPv6"
            Default
              inet$ = "IP version unspecific or unknown"
          EndSelect
          ; apply the filtering we want for either IPv4 or IPv6 - comment out to get both
          ;If @*pWinsServer\Address\lpSockaddr\ss_family = #AF_INET6 
          ;If @*pWinsServer\Address\lpSockaddr\ss_family = #AF_INET
          bufferlenWinsAddr=0
          If WSAAddressToString(*pWinsServer\Address\lpSockaddr, *pWinsServer\Address\iSockaddrLength, #Null, -1, @bufferlenWinsAddr) = #SOCKET_ERROR
            If bufferlenWinsAddr
              *pBufferWinsAddr = AllocateMemory(bufferlenWinsAddr)
              If *pBufferWinsAddr And WSAAddressToString(*pWinsServer\Address\lpSockaddr, *pWinsServer\Address\iSockaddrLength, #Null,*pBufferWinsAddr, @bufferlenWinsAddr) = 0
                Debug descrip$ + " Wins Server Address " + "(" + inet$ + ") : "  + PeekS(*pBufferWinsAddr)
              EndIf
            EndIf
          EndIf
          *pWinsServer = *pWinsServer\Next
        Wend
        If *pBufferWinsAddr
          FreeMemory(*pBufferWinsAddr)
        EndIf
        Debug "**************************************************"
      EndIf
      
      ; get gateway
      *pGatewayAddress = *pCurrAddresses\FirstGatewayAddress
      If *pGatewayAddress <> #Null
        While *pGatewayAddress <> #Null
          Select *pGatewayAddress\Address\lpSockaddr\ss_family
            Case #AF_INET
              inet$ = "IPv4"
            Case #AF_INET6
              inet$ = "IPv6"
            Case #AF_UNSPEC
              inet$ = "IP version unspecific - not IPv4 or IPv6"
            Default
              inet$ = "IP version unspecific or unknown"
          EndSelect
          ; apply filtering - comment out to get both
          ;If *pGatewayAddress\Address\lpSockaddr\ss_family = #AF_INET
          ;If *pGatewayAddress\Address\lpSockaddr\ss_family = #AF_INE6
          bufferlenGWAddr=0
          If WSAAddressToString(*pGatewayAddress\Address\lpSockaddr, *pGatewayAddress\Address\iSockaddrLength, #Null, -1, @bufferlenGWAddr) = #SOCKET_ERROR
            If bufferlenGWAddr
              *pBufferGWAddr = AllocateMemory(bufferlenGWAddr)
              If *pBufferGWAddr And WSAAddressToString(*pGatewayAddress\Address\lpSockaddr, *pGatewayAddress\Address\iSockaddrLength, #Null,*pBufferGWAddr, @bufferlenGWAddr) = 0
                Debug descrip$ + " using Gateway Server Address " + "(" + inet$ + ") : "  + PeekS(*pBufferGWAddr)
              EndIf
            EndIf
          EndIf
          *pGatewayAddress = *pGatewayAddress\Next
        Wend
        If *pBufferGWAddr
          FreeMemory(*pBufferGWAddr)
        EndIf
        Debug "**************************************************"
      EndIf
      
      *pDnServer = *pCurrAddresses\FirstDnsServerAddress
      If *pDnServer <> #Null
        While *pDnServer <> #Null
          DnsServer.i = DnsServer + 1
          Select *pDnServer\Address\lpSockaddr\ss_family
            Case #AF_INET
              inetdns$ = "IPv4"
            Case #AF_INET6
              inetdns$ = "IPv6"
            Case #AF_UNSPEC
              inetdns$ = "IP version unspecific - not IPv4 or IPv6"
            Default
              inetdns$ = "IP version unspecific or unknown"
          EndSelect
          *pDnServer = *pDnServer\Next
        Wend
        Debug "Number of " + descrip$ + " " + inetdns$ + " DNS Addresses : " + Str(DnsServer)
        DnsServer = 0
      EndIf
      
      *pDnServer = *pCurrAddresses\FirstDnsServerAddress
      If *pDnServer <> #Null
        While *pDnServer <> #Null
          Select *pDnServer\Address\lpSockaddr\ss_family
            Case #AF_INET
              inet$ = "IPv4"
            Case #AF_INET6
              inet$ = "IPv6"
            Case #AF_UNSPEC
              inet$ = "IP version unspecific - not IPv4 or IPv6"
            Default
              inet$ = "IP version unspecific or unknown"
          EndSelect
          ; apply filtering - comment out to get both
          ;If *pDnServer\Address\lpSockaddr\ss_family = #AF_INET
          ;If *pDnServer\Address\lpSockaddr\ss_family = #AF_INET6
          bufferlenDnAddr=0
          If WSAAddressToString(*pDnServer\Address\lpSockaddr, *pDnServer\Address\iSockaddrLength, #Null, -1, @bufferlenDnAddr) = #SOCKET_ERROR
            If bufferlenDnAddr
              *pBufferDnAddr = AllocateMemory(bufferlenDnAddr)
              If *pBufferDnAddr And WSAAddressToString(*pDnServer\Address\lpSockaddr, *pDnServer\Address\iSockaddrLength, #Null,*pBufferDnAddr, @bufferlenDnAddr) = 0
                Debug descrip$ + " use available DNS Address " + "(" + inet$ + ") : "  + PeekS(*pBufferDnAddr)
              EndIf
            EndIf
          EndIf
          *pDnServer = *pDnServer\Next
        Wend
        If *pBufferDnAddr
          FreeMemory(*pBufferDnAddr)
        EndIf
        Debug "**************************************************"
      EndIf
      
      *pUnicast = *pCurrAddresses\FirstUnicastAddress
      If *pUnicast <> #Null
        While *pUnicast <> #Null
          Unicast.i = Unicast + 1
          *pUnicast = *pUnicast\Next
        Wend
        Debug "Number of " + descrip$ + " Unicast Addresses : " + Str(Unicast)
        Unicast = 0
      EndIf
      
      ; gets unicast - this is connection interface IP's 
      *pUnicast = *pCurrAddresses\FirstUnicastAddress
      If *pUnicast <> #Null
        While *pUnicast <> #Null
          zon.i = zon + 1
          Select *pUnicast\Address\lpSockaddr\ss_family
            Case #AF_INET
              inet$ = "IPv4"
            Case #AF_INET6
              inet$ = "IPv6"
            Case #AF_UNSPEC
              inet$ = "IP version unspecific - not IPv4 or IPv6"
            Default
              inet$ = "IP version unspecific or unknown"
          EndSelect
          
          Select *pUnicast\sFlagsLength\Flags
            Case #IP_ADAPTER_ADDRESS_DNS_ELIGIBLE
              unicastflag$ = "The IP address is legal to appear in DNS."
            Case #IP_ADAPTER_ADDRESS_TRANSIENT
              unicastflag$ = "The IP address is a cluster address and should not be used by most applications."
            Default
          EndSelect
          
          Select *pUnicast\PrefixOrigin
            Case #IpPrefixOriginOther
              prefixorgflag$ = "The IP prefix was provided by a source other than those defined in enumeration."
            Case #IpPrefixOriginManual
              prefixorgflag$ = "The IP address prefix was manually specified."
            Case #IpPrefixOriginWellKnown
              prefixorgflag$ = "The IP address prefix is from a well known source."
            Case #IpPrefixOriginDhcp
              prefixorgflag$ = "The IP address prefix was provided by DHCP settings."
            Case #IpPrefixOriginRouterAdvertisement
              prefixorgflag$ = "The IP address prefix was obtained through a router advertisement (RA)."
            Case #IpPrefixOriginUnchanged
              prefixorgflag$ = "The IP address prefix should be unchanged."
            Default
              prefixorgflag$ = "The IP prefix origin is unknown."
          EndSelect
          
          Select *pUnicast\SuffixOrigin
            Case #IpSuffixOriginOther
              suffixorgflags$ = "The IP address suffix was provided by a source other than those defined in enumeration."
            Case #IpSuffixOriginManual
              suffixorgflags$ = "The IP address suffix was manually specified."
            Case #IpSuffixOriginWellKnown
              suffixorgflags$ = "The IP address suffix is from a well known source."
            Case #IpSuffixOriginDhcp
              suffixorgflags$ = "The IP address suffix was provided by DHCP settings."
            Case #IpSuffixOriginLinkLayerAddress
              suffixorgflags$ = "The IP address suffix was obtained from the link-layer address."
            Case #IpSuffixOriginRandom
              suffixorgflags$ = "The IP address suffix was obtained from a random source."
            Case #IpSuffixOriginUnchanged
              suffixorgflags$ = "The IP address suffix should be unchanged."
            Default
              suffixorgflags$ = "The IP address suffix origin is unknown."
          EndSelect
          
          Select *pUnicast\DadState ; Dad = Duplicate Address Detection
              Case #IpDadStateInvalid
                DadState$ = "The DAD state is invalid."
              Case #IpDadStateTentative
                DadState$ = "The DAD state is tentative."
              Case #IpDadStateDuplicate
                DadState$ = "A duplicate IP address has been detected."
              Case #IpDadStateDeprecated
                DadState$ = "The IP address has been deprecated."
              Case #IpDadStatePreferred
                DadState$ = "The IP address is the preferred address."
              Default
                DadState$ = "The DAD state is unknown."
          EndSelect
          ; apply filtering - comment out to get both
          ;If @*pUnicast\Address\lpSockaddr\ss_family = #AF_INET
          ;If @*pUnicast\Address\lpSockaddr\ss_family = #AF_INET6
          bufferlenUniAddr=0
          If WSAAddressToString(*pUnicast\Address\lpSockaddr, *pUnicast\Address\iSockaddrLength, #Null, -1, @bufferlenUniAddr) = #SOCKET_ERROR
            If bufferlenUniAddr
              *pBufferUniAddr = AllocateMemory(bufferlenUniAddr)
              If *pBufferUniAddr And WSAAddressToString(*pUnicast\Address\lpSockaddr, *pUnicast\Address\iSockaddrLength, #Null, *pBufferUniAddr, @bufferlenUniAddr) = 0
                
                Debug descrip$ + " Unicast Addresses " + "(" + inet$ + ") : "  + PeekS(*pBufferUniAddr)
                NetInfIndex.i = *pCurrAddresses\sIndexLength\IfIndex
                
                If *pUnicast\Address\lpSockaddr\ss_family = #AF_INET
                  ipunicastaddr$ = PeekS(*pBufferUniAddr)
                  Debug descrip$ + " Unicast Addresses " + ipunicastaddr$ + " is : " + SubIPNetInfo(NetInfIndex, ipunicastaddr$, 3)
                EndIf
                
                ; this assumes that adpater/interface is IPv 6 capable, ours are IPv6 capable so we are not concerned for other non-IPv6-capable                
                If *pUnicast\Address\lpSockaddr\ss_family = #AF_INET6 And hardwareIf = #True And Val(ReadMIBRowBitField(*pCurrAddresses\pFlags, 2, 1)) = 1 
                  ; we are only concerned with DUID for hardware adapters/interfaces and the DHCP DUID
                  ; and DUID is only applicapable for IPv6 - so we set up a simple filter so this only appears with IPv6 sections on hardware adapters/interfaces with DHCP
                  
                  If *pUnicast\ValidLifetime = -1 And *pUnicast\PreferredLifetime = -1 And *pUnicast\LeaseLifetime <> -1 Or *pCurrAddresses\Dhcpv6ClientDuidLength > #MAX_DHCPV6_DUID_LENGTH
                    ; no actual IPv6 use configured so instead of Dhcpv6ClientDuidLength we assign the default windows length of 14 for non-configured
                    ; if ValidLifetime and PreferredLifetime = -1 and LeaseLifetime <> -1 then we know we are using the windows default
                    ; and IPv6 use is not configured or in use
                    Dhcpv6ClientDuid$=""
                    For a=0 To 13
                      If a
                        Dhcpv6ClientDuid$+"-"
                      EndIf
                      byte.b=PeekB(@*pCurrAddresses\Dhcpv6ClientDuid[a])
                      If byte>=0
                        Dhcpv6ClientDuid$+RSet(Hex(byte,#PB_Byte),2,"0")
                      Else
                        Dhcpv6ClientDuid$+RSet(Hex(byte+256,#PB_Byte),2,"0")
                      EndIf
                    Next
                    Debug "Dhcpv6 Client Duid : " + Dhcpv6ClientDuid$
                    ;Debug "Dhcpv6 IAID : " + Str(@*pCurrAddresses\Dhcpv6Iaid) ; ARGhhhhhh... forget it, structure doesn't get it for some reason, don't need anyway
                  EndIf
                  
                  If *pUnicast\ValidLifetime <> -1 And *pUnicast\PreferredLifetime <> -1 And *pUnicast\LeaseLifetime <> -1 And *pCurrAddresses\Dhcpv6ClientDuidLength <= #MAX_DHCPV6_DUID_LENGTH
                    ; if ValidLifetime, PreferredLifetime, and LeaseLifetime, <> -1 then we have configured IPv6 use and can use Dhcpv6ClientDuidLength now to
                    ; account for cariable lenght of the Dhcpv6ClientDuid
                    Dhcpv6ClientDuid$=""
                    For a=0 To *pCurrAddresses\Dhcpv6ClientDuidLength-1
                      If a
                        Dhcpv6ClientDuid$+"-"
                      EndIf
                      byte.b=PeekB(@*pCurrAddresses\Dhcpv6ClientDuid[a])
                      If byte>=0
                        Dhcpv6ClientDuid$+RSet(Hex(byte,#PB_Byte),2,"0")
                      Else
                        Dhcpv6ClientDuid$+RSet(Hex(byte+256,#PB_Byte),2,"0")
                      EndIf
                    Next
                    Debug "Dhcpv6 Client Duid : " + Dhcpv6ClientDuid$
                    ;Debug "Dhcpv6 IAID : " + Str(*pCurrAddresses\Dhcpv6Iaid) ; ARGhhhhhh... forget it, structure doesn't get it for some reason, don't need anyway
                  EndIf
                  ; and finally we are going to do a very simple. but not fool proof, check for a mis-configuration or another in-use issue with IPv6
                  If *pUnicast\ValidLifetime <> -1 And *pUnicast\PreferredLifetime <> -1 And *pUnicast\LeaseLifetime <> -1 And *pCurrAddresses\Dhcpv6ClientDuidLength > #MAX_DHCPV6_DUID_LENGTH
                    Debug int_adap$ + " " + descrip$ + " is not configured correctly, or another issue exist, for IPv 6 use - DHCPV6 DUID exceeded the max limit of 130"
                  EndIf
                  
                  EndIf
                
                Debug unicastflag$ + prefixorgflag$ + suffixorgflags$ + DadState$ ;+ " " + ScopeLevel$
                
                If *pUnicast\ValidLifetime = -1
                  Debug int_adap$ + " Address Valid Life time : Not Applicapable"
                Else
                  Debug int_adap$ + " Address Valid Life time : " + Str(*pUnicast\ValidLifetime) + " seconds" + " (" + Str((0.000277777778) * (*pUnicast\ValidLifetime)) + " hours)"
                EndIf
                If *pUnicast\PreferredLifetime = -1
                  Debug int_adap$ + " Address Preferred Life time : Not Applicapable"
                Else
                  Debug int_adap$ + " Address Preferred Life time : " + Str(*pUnicast\PreferredLifetime) + " seconds" + " (" + Str((0.000277777778) * (*pUnicast\PreferredLifetime)) + " hours)"
                EndIf
                Debug int_adap$ + " Address Lease Life time : " + Str(*pUnicast\LeaseLifetime) + " seconds" + " (" + Str((0.000277777778) * (*pUnicast\LeaseLifetime)) + " hours)"
                
                If FindString(descrip$, "Teredo", 1) > 0
                  TeredoPort.i
                  torport.i = GetTeredoPort(@TeredoPort)
                  Select torport
                      Case #NO_ERROR
                        torp$ = Str(TeredoPort)
                      Case #ERROR_NOT_READY
                        torp$ =  "The device is not ready. The Teredo client is not started on the local computer."
                      Case #ERROR_NOT_SUPPORTED
                        torp$ = "The request is not supported. There is no IPv6 stack on the local computer."
                      Default
                        torp$ =  ShowAPIError(torport)
                    EndSelect
                    Debug int_adap$ + " Toredo Port : " + torp$
                  EndIf
                  
                If *pUnicast\PreferredLifetime <> -1 And *pUnicast\ValidLifetime <> -1 And Val(ReadMIBRowBitField(*pCurrAddresses\pFlags, 2, 1)) = 1
                  If *pUnicast\Address\lpSockaddr\ss_family = #AF_INET
                    Debug "Current IPv4 Address Subnet for " + descrip$ + " : " + GetLeaseSub(NetInfIndex, 1)
                  EndIf
                  Debug "DHCP Lease Obtained : " + GetLeaseSub(NetInfIndex, 2)
                  Debug "DHCP Lease Expires : " + GetLeaseSub(NetInfIndex, 3)
                EndIf
                Debug "================"
              EndIf
            EndIf
          EndIf
          *pUnicast = *pUnicast\Next
        Wend
        If *pBufferUniAddr
          FreeMemory(*pBufferUniAddr)
        EndIf
        Debug "**************************************************"
      EndIf
      
      *pPrefix = *pCurrAddresses\FirstPrefix
      If *pPrefix <> #Null
        *pPrefix\sFlagsLength\Flags = 0 ; not used - reserved - should be set to 0 per MSDN
        While *pPrefix <> #Null
          Prefix.i = Prefix + 1
          *pPrefix = *pPrefix\Next
        Wend
        Debug "Number of " + descrip$ + " Prefix entries : " + Str(Prefix)
        Prefix = 0
      EndIf
      
      *pPrefix = *pCurrAddresses\FirstPrefix
      If *pPrefix <> #Null
        *pPrefix\sFlagsLength\Flags = 0 ; not used - reserved - should be set to 0 per MSDN
        While *pPrefix <> #Null
          Select *pPrefix\Address\lpSockaddr\ss_family
            Case #AF_INET
              inet$ = "IPv4"
            Case #AF_INET6
              inet$ = "IPv6"
            Case #AF_UNSPEC
              inet$ = "IP version unspecific - not IPv4 or IPv6"
            Default
              inet$ = "IP version unspecific or unknown"
          EndSelect
          bufferlenPFAddr=0
          If WSAAddressToString(*pPrefix\Address\lpSockaddr, *pPrefix\Address\iSockaddrLength, #Null, -1, @bufferlenPFAddr) = #SOCKET_ERROR
            If bufferlenPFAddr
              *pBufferPFAddr = AllocateMemory(bufferlenPFAddr)
              If *pBufferPFAddr And WSAAddressToString(*pPrefix\Address\lpSockaddr, *pPrefix\Address\iSockaddrLength, #Null, *pBufferPFAddr, @bufferlenPFAddr) = 0
                Debug descrip$ + " Prefix Address " + "(" + inet$ + ") : "  + PeekS(*pBufferPFAddr)
              EndIf
            EndIf
          EndIf
          *pPrefix = *pPrefix\Next
        Wend
        If *pBufferPFAddr
          FreeMemory(*pBufferPFAddr)
        EndIf
        Debug "**************************************************"
      EndIf
      
      *pMulticast = *pCurrAddresses\FirstMulticastAddress
      If *pMulticast <> #Null
        While *pMulticast <> #Null
          Multicast.i = Multicast + 1
          *pMulticast = *pMulticast\Next
        Wend
        Debug "Number of " + descrip$ + " Multicast Addresses : " + Str(Multicast)
        Multicast = 0
      EndIf
      
      ; get pMulticast
      *pMulticast = *pCurrAddresses\FirstMulticastAddress
      If *pMulticast <> #Null
        While  *pMulticast <> #Null
          Select *pMulticast\Address\lpSockaddr\ss_family
            Case #AF_INET
              inet$ = "IPv4"
            Case #AF_INET6
              inet$ = "IPv6"
            Case #AF_UNSPEC
              inet$ = "IP version unspecific - not IPv4 or IPv6"
            Default
              inet$ = "IP version unspecific or unknown"
          EndSelect
          
          Select *pMulticast\sFlagsLength\Flags
            Case #IP_ADAPTER_ADDRESS_DNS_ELIGIBLE
              multicastflag$ = "The IP address is legal to appear in DNS."
            Case #IP_ADAPTER_ADDRESS_TRANSIENT
              multicastflag$ = "The IP address is a cluster address and should not be used by most applications."
            Default
          EndSelect
          ;If @*pMulticast\Address\lpSockaddr\ss_family = #AF_INET6
          bufferlenMultiAddr=0
          If WSAAddressToString(*pMulticast\Address\lpSockaddr, *pMulticast\Address\iSockaddrLength, #Null, -1, @bufferlenMultiAddr) = #SOCKET_ERROR
            If bufferlenMultiAddr
              *pBufferMultiAddr = AllocateMemory(bufferlenMultiAddr)
              If *pBufferMultiAddr And WSAAddressToString(*pMulticast\Address\lpSockaddr, *pMulticast\Address\iSockaddrLength, #Null,*pBufferMultiAddr, @bufferlenMultiAddr) = 0
                If *pMulticast\sFlagsLength\Flags = 1 Or *pMulticast\sFlagsLength\Flags = 2
                  Debug descrip$ + " Multicast Address " + "(" + inet$ + ") : "  + PeekS(*pBufferMultiAddr) + " (" + multicastflag$ + ")"
                Else
                  Debug descrip$ + " Multicast Address " + "(" + inet$ + ") : "  + PeekS(*pBufferMultiAddr)
                EndIf
              EndIf
            EndIf
          EndIf
          *pMulticast = *pMulticast\Next
        Wend
        If *pBufferMultiAddr
          FreeMemory(*pBufferMultiAddr)
        EndIf
        Debug "**************************************************"
      EndIf
      
      *pAnycast = *pCurrAddresses\FirstAnycastAddress
      If *pAnycast <> #Null
        While *pAnycast <> #Null
          Anycast.i = Anycast + 1
          *pAnycast = *pAnycast\Next
        Wend
        Debug "Number of " + descrip$ + " Anycast Addresses : " + Str(Anycast)
        Anycast = 0
      EndIf
      
      *pAnycast = *pCurrAddresses\FirstAnycastAddress
      If *pAnycast <> #Null
        While  *pAnycast <> #Null
          Select @*pAnycast\Address\lpSockaddr\ss_family
            Case #AF_INET
              inet$ = "IPv4"
            Case #AF_INET6
              inet$ = "IPv6"
            Case #AF_UNSPEC
              inet$ = "IP version unspecific - not IPv4 or IPv6"
            Default
              inet$ = "IP version unspecific or unknown"
          EndSelect
          
          Select *pAnycast\sFlagsLength\Flags
            Case #IP_ADAPTER_ADDRESS_DNS_ELIGIBLE
              anycastflag$ = "The IP address is legal to appear in DNS."
            Case #IP_ADAPTER_ADDRESS_TRANSIENT
              anycastflag$ = "The IP address is a cluster address and should not be used by most applications."
            Default
          EndSelect
          ; apply filtering - comment out to get both
          ;If @*pAnycast\Address\lpSockaddr\ss_family = #AF_INET
          ;If @*pAnycast\Address\lpSockaddr\ss_family = #AF_INET;
          bufferlenAny=0
          If WSAAddressToString(*pAnycast\Address\lpSockaddr, *pAnycast\Address\iSockaddrLength, #Null, -1, @bufferlenAny) = #SOCKET_ERROR
            If bufferlenAny
              *pBufferAny = AllocateMemory(bufferlenAny)
              If *pBufferAny And WSAAddressToString(*pAnycast\Address\lpSockaddr, *pAnycast\Address\iSockaddrLength, #Null, *pBufferAny, @bufferlenAny) = 0
                Debug descrip$ + " Anycast Address " + "(" + inet$ + ") : "  + PeekS(*pBufferAny) + " (" + anycastflag$ + ")"
              EndIf
            EndIf
          EndIf
          *pAnycast = *pAnycast\Next
        Wend
        If *pBufferAny
          FreeMemory(*pBufferAny)
        EndIf
        Debug "**************************************************"
      EndIf
      
      ;********************************************** the big loop ends - time to wave bye bye*************************** 
     
   *pCurrAddresses = *pCurrAddresses\Next
     
      Debug "******************************************************************************"
      
      Delay(1)  
   Wend
   FreeMemory(*pAddresses)
   
   Debug "====================================================================="
   Debug "Definitions - According to MS definitions ::"
   Debug "An Adapter is normally a physical hardware construct - an Interface is normally a software/logical construct."
   Debug "There is a one-to-one correspondence between interfaces and adapters. An interface is an IP-level abstraction, whereas an adapter is a datalink-level abstraction."
   Debug "There may be multiple interfaces per adapter"
   Debug "Network Interface Cards (NIC) receive information from the OS, and do the rest." 
   Debug "Adapters are the bare minimum for network connection and need to be controlled by interfaces in the system."
   Debug "Adapters are generally slower than NIC's because they need to check with the interface's before doing anything."
   Debug "**************************************************"
   
   Debug "**************** IPv4 IP ARP Table ***************"
   
   GetIp_NetTable()
   
   Debug ""
   Debug "**************** IP Statistics ***************"
   Get_IpStatistics(2)
   Debug "**************************************************"
   
   
 Else
   Debug "Get Adapters Addresses  Failed"
  CloseLibrary(Lib_iphlpapi)
  CloseLibrary(Lib_Winsock)
  CloseLibrary(Lib_Ntdll)
  WSACleanup_()
  End
 EndIf
 
Else
  
  If Lib_iphlpapi = 0
    MessageRequester("Error - IP Helper", "Failed to open library for IP Helper",  #MB_ICONWARNING|#PB_MessageRequester_Ok)
    If Lib_Winsock
      CloseLibrary(Lib_Winsock)
    EndIf
    If Lib_Ntdll
      CloseLibrary(Lib_Ntdll)
    EndIf
    WSACleanup_()
    End
  EndIf
  
  If Lib_Winsock = 0
    MessageRequester("Error - Winsock", "Failed to open library for winsock",  #MB_ICONWARNING|#PB_MessageRequester_Ok)
    If Lib_iphlpapi
      CloseLibrary(Lib_iphlpapi)
    EndIf
    If Lib_Ntdll
      CloseLibrary(Lib_Ntdll)
    EndIf
    WSACleanup_()
    End
  EndIf
  
  If Lib_Ntdll = 0
    MessageRequester("Error - Ntdll", "Failed to open library for Ntdll",  #MB_ICONWARNING|#PB_MessageRequester_Ok)
    If Lib_iphlpapi
      CloseLibrary(Lib_iphlpapi)
    EndIf
    If Lib_Winsock
      CloseLibrary(Lib_Winsock)
    EndIf
    WSACleanup_()
    End
  EndIf
  
  If WSAStartup <> 0
    MessageRequester("Error - Winsock", "Failed to start winsock at WSAStartup.",  #MB_ICONWARNING|#PB_MessageRequester_Ok)
    If Lib_iphlpapi
      CloseLibrary(Lib_iphlpapi)
    EndIf
    If Lib_Winsock
      CloseLibrary(Lib_Winsock)
    EndIf
    If Lib_Ntdll
      CloseLibrary(Lib_Ntdll)
    EndIf
    End
  EndIf
  

EndIf

CloseLibrary(Lib_iphlpapi)
CloseLibrary(Lib_Winsock)
CloseLibrary(Lib_Ntdll)
WSACleanup_()

;Notes:

; per requirement 'Silent Fail' - implemented later


;Client DUID Notes:

; example: DHCPv6 Client DUID. . . . . . . . : 00-01-00-01-15-60-D4-F8- 00-1B-FC-DB-2B-16
 
;By default, unless IPv6 is configuered otherwise, the type of DUID generated is a weird "link-layer plus type/index to which assigned and used plus time/date chose by system plus windows system MAC address". 
;This is indicated by a leading 00:01 in the DUID above host entry. The 01-15 is the type and index of the adapter/interface to which assigned and used. 
;The 60-D4-F8 is the time which is a time and date chosen by the system - in the example 60-D4-F8 = 96212248 = Or 01/18/1973 13:01:28 EDT (ironically this is an epoch time/date :)
;The 00-1B-FC-DB-2B-16 is the Windows Genuine Advantage "MAC"="00-1B-FC-DB-2B-16;" entry located in the registry at:

;"[HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\InternetRegistry\REGISTRY\USER\S-1-5-21-3865607270-2620457810-2029971197-1000\Software\Microsoft\Windows Genuine Advantage]" 

;And ...

;"[HKEY_USERS\S-1-5-21-3865607270-2620457810-2029971197-1000\Software\Microsoft\Internet Explorer\InternetRegistry\REGISTRY\USER\S-1-5-21-3865607270-2620457810-2029971197-1000\Software\Microsoft\Windows Genuine Advantage]" 

;These contribute, with any of the interface/adapters network GUID's, to form a unique identifier for the computer upon which Windows 7 is installed. 


EndProcedure

If LoadLibraries() = #True
  GetInterfaceInfo()
Else
  Debug "Could not get a library"
  End
EndIf

The advantage of a 64 bit operating system over a 32 bit operating system comes down to only being twice the headache.
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Re: More than u ever wanted to know - Interfaces and Adapter

Post by SFSxOI »

And thats the test bed code.

A note on the MIB_IF_ROW2 structure: If you plan to use any of the values below the ConnectionType.i member, all of these are quads. To read them correctly you will need to insert a 4 byte pad directly below the ConnectionType.i member (in between the ConnectionType and TransmitLinkSpeed members) , like shown below:

Code: Select all

Structure MIB_IF_ROW2  ;->Structure MIB_IF_ROW2
  ;////rest of structure above this as shown in the code
  ConnectionType.i
  pad.l  ;<<<<<<<<<<<<<< The four byte pad - a long .l shown here - just name it pad.l
  TransmitLinkSpeed.q
  ReceiveLinkSpeed.q
  InOctets.q
  InUcastPkts.q
  InNUcastPkts.q
  InDiscards.q
  InErrors.q
  InUnknownProtos.q
  InUcastOctets.q
  InMulticastOctets.q
  InBroadcastOctets.q
  OutOctets.q
  OutUcastPkts.q
  OutNUcastPkts.q
  OutDiscards.q
  OutErrors.q
  OutUcastOctets.q
  OutMulticastOctets.q
  OutBroadcastOctets.q
  OutQLen.q ; not currently used
EndStructure


The you can just do a simple :

Code: Select all

; using the TransmitLinkSpeed member for an example

Debug Str(*pIfRowOctets\TransmitLinkSpeed)

; or if you perfer you can do this

Debug PeekQ(@*pIfRowOctets\TransmitLinkSpeed)

; either will work
to read the value.

If you do not use the four byte pad, the numbers you get from these structure members will not be correct no matter how you read them without the four byte pad. I did not need to use these in my project so it was not included in the test bed code.

Now a note on the IP_ADAPTER_ADDRESSES structure, the length of this structure is supposed to be 376, not a byte more or less. If you change anything in the structure, a lot of it will appear to be working properly but there will be subtle signs that it is not working properly. Usually when its not working after a change in the structure, one of the Index vales will be wrong (either for the IP 6 or IP 4 index's), the connection type may be wrong, and the tunnel type may be wrong, or all of these may be wrong, but if you change something there will be something that is not correct when you try to read a value, even making something non-pointer will upset the structure. If you changed something in the structure thinking you wanted to use a '.l' instead of a '.i', save yourself a lot of trouble trying to figure out why a value is not correct and simply do not deviate from the way i've presented the structure here. Also, for the Dhcpv6ClientDuidLength.i and the Dhcpv6Iaid.i members, these only work when an IPv6 adapter is configured for using DHCPv6, however, you can get the Dhcpv6ClientDuid (see the code for how to do that) even though this is not supposed to work either unless the adapter is configured for DHCPv6.
Last edited by SFSxOI on Mon Aug 22, 2011 10:44 pm, edited 15 times in total.
The advantage of a 64 bit operating system over a 32 bit operating system comes down to only being twice the headache.
User avatar
idle
Always Here
Always Here
Posts: 5042
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: More than u ever wanted to know - Interfaces and Adapter

Post by idle »

Thanks, yes that's more information than I wanted to know!
Nice contribution.
Windows 11, Manjaro, Raspberry Pi OS
Image
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Re: More than u ever wanted to know - Interfaces and Adapter

Post by SFSxOI »

Oh yeah, another note too. I took out the code that will get the MAC address of any computer on the network or on the internet, and not just in your own subnet. The MAC address stuff you see in the code (mostly for the IP table stuff) I posted is for the MAC address of computers in your own subnet, and if its outside the subnet the MAC returned will probably be the last point on your subnet befofe leaving your subnet and going out to the rest of the internet, and not that of the target computer outside the subnet.

However, I can't give you what I ended up using to get the MAC address of any computer, in your subnet of not, but if any of you are conversant with C# and want to convert something to Pure Basic that will get the MAC address of any computer anywhere...well..... hint > I used a variation of this type of code with SNMP > http://www.java2s.com/Code/CSharp/Netwo ... ddress.htm
The advantage of a 64 bit operating system over a 32 bit operating system comes down to only being twice the headache.
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: More than u ever wanted to know - Interfaces and Adapters

Post by IdeasVacuum »

Just tried this mammoth code in PB6.00 LTS on Windows7 64

[22:44:36] [COMPILER] Syntax check finished (3178 lines)
[22:44:39] Waiting for executable to start...
[22:44:39] Executable type: Windows - x64 (64bit, Unicode)
[22:44:39] Executable started.
[22:44:39] [ERROR] TestBed.pb (Line: 733)
[22:44:39] [ERROR] Invalid memory access. (read error at address 76115968)

Line 733:

Code: Select all

byte.b=PeekB(@*pIfRowOtherIf\PhysicalAddress+a)
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: More than u ever wanted to know - Interfaces and Adapters

Post by IdeasVacuum »

I think PB6 has outgrown this code as it offers a Serial library. Mind you, the example SerialPort.pb must be the shortest in history :mrgreen:
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
Post Reply