Module: Win32::Resolv::WsControl

Defined in:
lib/win32/resolv9x.rb

Defined Under Namespace

Modules: WSock32

Constant Summary collapse

WsControl =
WSock32.extern "int WsControl(int, int, void *, void *, void *, void *)", :stdcall
WSAGetLastError =
WSock32.extern "int WSAGetLastError(void)", :stdcall
MAX_TDI_ENTITIES =
512
IPPROTO_TCP =
6
WSCTL_TCP_QUERY_INFORMATION =
0
INFO_CLASS_GENERIC =
0x100
INFO_CLASS_PROTOCOL =
0x200
INFO_TYPE_PROVIDER =
0x100
ENTITY_LIST_ID =
0
GENERIC_ENTITY =
0
CL_NL_ENTITY =
0x301
IF_ENTITY =
0x200
ENTITY_TYPE_ID =
1
CL_NL_IP =
0x303
IF_MIB =
0x202
IF_MIB_STATS_ID =
1
IP_MIB_ADDRTABLE_ENTRY_ID =
0x102

Class Method Summary collapse

Class Method Details

.get_iflistObject



189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
# File 'lib/win32/resolv9x.rb', line 189

def self.get_iflist
  # Get TDI Entity List
  entities, size =
    wsctl(GENERIC_ENTITY, 0,
          INFO_CLASS_GENERIC,
          INFO_TYPE_PROVIDER,
          ENTITY_LIST_ID,
          MAX_TDI_ENTITIES * 8)  # sizeof(TDIEntityID)
  entities = entities[0, size].
               scan(/.{8}/).
               collect { |e| e.unpack('VV') }

  # Get MIB Interface List
  iflist = []
  ifcount = 0
  entities.each do |entity, instance|
    if( (entity & IF_ENTITY)>0 )
      ifcount += 1
      etype, = wsctl(entity, instance,
                     INFO_CLASS_GENERIC,
                     INFO_TYPE_PROVIDER,
                     ENTITY_TYPE_ID,
                     4)
      if( (API.unpackdw(etype) & IF_MIB)==IF_MIB )
        ifentry, = wsctl(entity, instance,
                         INFO_CLASS_PROTOCOL,
                         INFO_TYPE_PROVIDER,
                         IF_MIB_STATS_ID,
                         21 * 4 + 8 + 130)  # sizeof(IFEntry)
        iflist << [
          API.unpackdw(ifentry[0,4]),
          ifentry[20, 6]
        ]
      end
    end
  end

  # Get IP Addresses
  entities.each do |entity, instance|
    if entity == CL_NL_ENTITY
      etype, = wsctl(entity, instance,
                     INFO_CLASS_GENERIC,
                     INFO_TYPE_PROVIDER,
                     ENTITY_TYPE_ID,
                     4)
      if API.unpackdw(etype) == CL_NL_IP
        ipentries, = wsctl(entity, instance,
                           INFO_CLASS_PROTOCOL,
                           INFO_TYPE_PROVIDER,
                           IP_MIB_ADDRTABLE_ENTRY_ID,
                           24 * (ifcount+1))  # sizeof(IPAddrEntry)
        ipentries.scan(/.{24}/) do |ipentry|
          ipaddr, index = ipentry.unpack('VV')
          if ifitem = iflist.assoc(index)
            ifitem << ipaddr
          end
        end
      end
    end
  end
  iflist
end