Subversion Repositories userdetect2

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
93 daniel-mar 1
unit iphlp;
2
 
3
interface
4
 
5
uses
6
  Windows;
7
 
8
const
9
  MAX_INTERFACE_NAME_LEN = $100;
10
  ERROR_SUCCESS = 0;
11
  MAXLEN_IFDESCR = $100;
12
  MAXLEN_PHYSADDR = 8;
13
 
14
  MIB_IF_OPER_STATUS_NON_OPERATIONAL = 0 ;
15
  MIB_IF_OPER_STATUS_UNREACHABLE = 1;
16
  MIB_IF_OPER_STATUS_DISCONNECTED = 2;
17
  MIB_IF_OPER_STATUS_CONNECTING = 3;
18
  MIB_IF_OPER_STATUS_CONNECTED = 4;
19
  MIB_IF_OPER_STATUS_OPERATIONAL = 5;
20
 
21
  MIB_IF_TYPE_OTHER = 1;
22
  MIB_IF_TYPE_ETHERNET = 6;
23
  MIB_IF_TYPE_TOKENRING = 9;
24
  MIB_IF_TYPE_FDDI = 15;
25
  MIB_IF_TYPE_PPP = 23;
26
  MIB_IF_TYPE_LOOPBACK = 24;
27
  MIB_IF_TYPE_SLIP = 28;
28
 
29
  MIB_IF_ADMIN_STATUS_UP = 1;
30
  MIB_IF_ADMIN_STATUS_DOWN = 2;
31
  MIB_IF_ADMIN_STATUS_TESTING = 3;
32
 
33
type
34
  MIB_IFROW = packed record
35
    wszName: Array[0 .. (MAX_INTERFACE_NAME_LEN*2-1)] of AnsiChar;
36
    dwIndex: LongInt;
37
    dwType: LongInt;
38
    dwMtu: LongInt;
39
    dwSpeed: LongInt;
40
    dwPhysAddrLen: LongInt;
41
    bPhysAddr: Array[0 .. (MAXLEN_PHYSADDR-1)] of Byte;
42
    dwAdminStatus: LongInt;
43
    dwOperStatus: LongInt;
44
    dwLastChange: LongInt;
45
    dwInOctets: LongInt;
46
    dwInUcastPkts: LongInt;
47
    dwInNUcastPkts: LongInt;
48
    dwInDiscards: LongInt;
49
    dwInErrors: LongInt;
50
    dwInUnknownProtos: LongInt;
51
    dwOutOctets: LongInt;
52
    dwOutUcastPkts: LongInt;
53
    dwOutNUcastPkts: LongInt;
54
    dwOutDiscards: LongInt;
55
    dwOutErrors: LongInt;
56
    dwOutQLen: LongInt;
57
    dwDescrLen: LongInt;
58
    bDescr: Array[0 .. (MAXLEN_IFDESCR - 1)] of AnsiChar;
59
  end;
60
 
61
const
62
  MAX_HOSTNAME_LEN    = 128;
63
  MAX_DOMAIN_NAME_LEN = 128;
64
  MAX_SCOPE_ID_LEN    = 256;
65
 
66
  MAX_ADAPTER_NAME_LENGTH        = 256;
67
  MAX_ADAPTER_DESCRIPTION_LENGTH = 128;
68
  MAX_ADAPTER_ADDRESS_LENGTH     = 8;
69
 
70
  IPHelper = 'iphlpapi.dll';
71
 
72
type
73
  PIPAddressString = ^TIPAddressString;
74
  PIPMaskString    = ^TIPAddressString;
75
  TIPAddressString = packed record
76
    _String: array[0..(4 * 4) - 1] of AnsiChar;
77
  end;
78
  TIPMaskString = TIPAddressString;
79
  PIPAddrString = ^TIPAddrString;
80
  TIPAddrString = packed record
81
    Next: PIPAddrString;
82
    IpAddress: TIPAddressString;
83
    IpMask: TIPMaskString;
84
    Context: DWORD;
85
  end;
86
  PFixedInfo = ^TFixedInfo;
87
  TFixedInfo = packed record
88
    HostName: array[0..MAX_HOSTNAME_LEN + 4 - 1] of AnsiChar;
89
    DomainName: array[0..MAX_DOMAIN_NAME_LEN + 4 - 1] of AnsiChar;
90
    CurrentDnsServer: PIPAddrString;
91
    DnsServerList: TIPAddrString;
92
    NodeType: UINT;
93
    ScopeId: array[0..MAX_SCOPE_ID_LEN + 4 - 1] of AnsiChar;
94
    EnableRouting,
95
    EnableProxy,
96
    EnableDns: UINT;
97
  end;
98
 
99
  IP_ADDRESS_STRING = packed record
100
    S: array [0..15] of AnsiChar;
101
  end;
102
  IP_MASK_STRING = IP_ADDRESS_STRING;
103
  PIP_MASK_STRING = ^IP_MASK_STRING;
104
 
105
  PIP_ADDR_STRING = ^IP_ADDR_STRING;
106
  IP_ADDR_STRING = packed record
107
    Next: PIP_ADDR_STRING;
108
    IpAddress: IP_ADDRESS_STRING;
109
    IpMask: IP_MASK_STRING;
110
    Context: DWORD;
111
  end;
112
 
113
  PIP_ADAPTER_INFO = ^IP_ADAPTER_INFO;
114
  IP_ADAPTER_INFO = packed record
115
    Next: PIP_ADAPTER_INFO;
116
    ComboIndex: DWORD;
117
    AdapterName: array [0..MAX_ADAPTER_NAME_LENGTH + 3] of AnsiChar;
118
    Description: array [0..MAX_ADAPTER_DESCRIPTION_LENGTH + 3] of AnsiChar;
119
    AddressLength: UINT;
120
    Address: array [0..MAX_ADAPTER_ADDRESS_LENGTH - 1] of BYTE;
121
    Index: DWORD;
122
    Type_: UINT;
123
    DhcpEnabled: UINT;
124
    CurrentIpAddress: PIP_ADDR_STRING;
125
    IpAddressList: IP_ADDR_STRING;
126
    GatewayList: IP_ADDR_STRING;
127
    DhcpServer: IP_ADDR_STRING;
128
    HaveWins: BOOL;
129
    PrimaryWinsServer: IP_ADDR_STRING;
130
    SecondaryWinsServer: IP_ADDR_STRING;
131
    LeaseObtained: Cardinal;
132
    LeaseExpires: Cardinal;
133
  end;
134
 
135
const
136
  ANY_SIZE = 1;
137
  {$EXTERNALSYM ANY_SIZE}
138
 
139
type
140
  PMIB_IFTABLE = ^MIB_IFTABLE;
141
  {$EXTERNALSYM PMIB_IFTABLE}
142
  _MIB_IFTABLE = record
143
    dwNumEntries: DWORD;
144
    table: array [0..ANY_SIZE - 1] of MIB_IFROW;
145
  end;
146
  {$EXTERNALSYM _MIB_IFTABLE}
147
  MIB_IFTABLE = _MIB_IFTABLE;
148
  {$EXTERNALSYM MIB_IFTABLE}
149
  TMibIftable = MIB_IFTABLE;
150
  PMibIftable = PMIB_IFTABLE;
151
 
152
function GetAdaptersInfo(pAdapterInfo: PIP_ADAPTER_INFO; var pOutBufLen: {P}ULONG): DWORD; stdcall;
153
function GetNetworkParams(pFixedInfo: PFixedInfo; var pOutBufLen: {P}ULONG): DWORD; stdcall;
154
function SendArp(DestIP, SrcIP: {IPAddr}Cardinal; pMacAddr: PULONG; var PhyAddrLen: {P}ULONG) : DWORD; stdcall;
155
function GetIfTable(pIfTable: PMIB_IFTABLE; var pdwSize: {P}ULONG; bOrder: BOOL): DWORD; stdcall;
156
 
157
implementation
158
 
159
function GetAdaptersInfo; external IPHelper Name 'GetAdaptersInfo';
160
function GetNetworkParams; external IPHelper Name 'GetNetworkParams';
161
function SendArp; external IPHelper name 'SendARP';
162
function GetIfTable; external IPHelper Name 'GetIfTable';
163
 
164
end.
165