阿不这个么这个我自己找的到九是用不来么
GetIfEntry函数里要使用到的MIB_IFROW结构体需要怎么样申明我的申明是
public struct MIB_IFROW
{
public string wszName;
[MarshalAs(UnmanagedType.ByValTStr,SizeConst=MAX_INTERFACE_NAME_LEN)]
public Int32 dwIndex;
public Int32 dwType;
public Int32 dwMtu;
public Int32 dwSpeed;
public Int32 dwPhysAddrLen;
public byte[] bPhysAddr;
public Int32 dwAdminStatus;
public Int32 dwOperStatus;
public Int32 dwLastChange;
public Int32 dwInOctets;
public Int32 dwInUcastPkts;
public Int32 dwInNUcastPkts;
public Int32 dwInDiscards;
public Int32 dwInErrors;
public Int32 dwInUnknownProtos;
public Int32 dwOutOctets;
public Int32 dwOutUcastPkts;
public Int32 dwOutNUcastPkts;
public Int32 dwOutDiscards;
public Int32 dwOutErrors;
public Int32 dwOutQLen;
public Int32 dwDescrLen;
public byte[] bDescr;//[MAXLEN_IFDESCR];
}
使用的时候提示
未处理的“System.Runtime.InteropServices.MarshalDirectiveException”类型的异常出现在 networkcheck.exe 中。
The MIB_IFROW structure stores information about a particular interface.
typedef struct _MIB_IFROW { WCHAR wszName[MAX_INTERFACE_NAME_LEN]; DWORD dwIndex; DWORD dwType; DWORD dwMtu; DWORD dwSpeed; DWORD dwPhysAddrLen; BYTE bPhysAddr[MAXLEN_PHYSADDR]; DWORD dwAdminStatus; DWORD dwOperStatus; DWORD dwLastChange; DWORD dwInOctets; DWORD dwInUcastPkts; DWORD dwInNUcastPkts; DWORD dwInDiscards; DWORD dwInErrors; DWORD dwInUnknownProtos; DWORD dwOutOctets; DWORD dwOutUcastPkts; DWORD dwOutNUcastPkts; DWORD dwOutDiscards; DWORD dwOutErrors; DWORD dwOutQLen; DWORD dwDescrLen; BYTE bDescr[MAXLEN_IFDESCR];
} MIB_IFROW, *PMIB_IFROW;
Members
wszName
Pointer to a Unicode string that contains the name of the interface.
dwIndex
Specifies the index that identifies the interface.
dwType
Specifies the type of interface.
This member can be one of the following values:
dwMtu
Specifies the Maximum Transmission Unit (MTU).
dwSpeed
Specifies the speed of the interface in bits per second.
dwPhysAddrLen
Specifies the length of the physical address specified by the bPhysAddr member.
bPhysAddr
Specifies the physical address of the adapter for this interface.
dwAdminStatus
Specifies the interface is administratively enabled or disabled.
dwOperStatus
Specifies the operational status of the interface. This member can be one of the following values. Value Meaning
MIB_IF_OPER_STATUS_NON_OPERATIONAL LAN adapter has been disabled, for example because of an address conflict.
MIB_IF_OPER_STATUS_UNREACHABLE WAN adapter that is not connected.
MIB_IF_OPER_STATUS_DISCONNECTED For LAN adapters: network cable disconnected. For WAN adapters: no carrier.
MIB_IF_OPER_STATUS_CONNECTING WAN adapter that is in the process of connecting.
MIB_IF_OPER_STATUS_CONNECTED WAN adapter that is connected to a remote peer.
MIB_IF_OPER_STATUS_OPERATIONAL Default status for LAN adapters
dwLastChange
Specifies the length of time, in centaseconds (10^-2 sec), that elapsed between January 1, 1601, and the last change of the operational status of the interface (connection). The value rolls over after 2^32 centaseconds.
dwInOctets
Specifies the number of octets of data received through this interface.
dwInUcastPkts
Specifies the number of unicast packets received through this interface.
dwInNUcastPkts
Specifies the number of non-unicast packets received through this interface. Broadcast and multicast packets are included.
dwInDiscards
Specifies the number of incoming packets that were discarded even though they did not have errors.
dwInErrors
Specifies the number of incoming packets that were discarded because of errors.
dwInUnknownProtos
Specifies the number of incoming packets that were discarded because the protocol was unknown.
dwOutOctets
Specifies the number of octets of data sent through this interface.
dwOutUcastPkts
Specifies the number of unicast packets sent through this interface.
dwOutNUcastPkts
Specifies the number of non-unicast packets sent through this interface. Broadcast and multicast packets are included.
dwOutDiscards
Specifies the number of outgoing packets that were discarded even though they did not have errors.
dwOutErrors
Specifies the number of outgoing packets that were discarded because of errors.
dwOutQLen
Specifies the output queue length.
dwDescrLen
Specifies the length of the bDescr member.
bDescr
Contains a description of the interface.
Requirements
Client Requires Windows "Longhorn", Windows XP, Windows 2000 Professional, Windows NT Workstation 4.0 SP4 and later, Windows Me, or Windows 98.
Server Requires Windows Server "Longhorn", Windows Server 2003, Windows 2000 Server, or Windows NT Server 4.0 SP4 and later.
Header Declared in Iprtrmib.h.
The GetIfEntry function retrieves information for the specified interface on the local computer.
DWORD GetIfEntry(
PMIB_IFROW pIfRow
);
Parameters
pIfRow
[in, out] Pointer to a MIB_IFROW structure that, on successful return, receives information for an interface on the local computer. On input, set the dwIndex member of MIB_IFROW to the index of the interface for which to retrieve information.
Return Values
If the function succeeds, the return value is NO_ERROR.
If the function fails, use FormatMessage to obtain the message string for the returned error.
Example Code
The following example retrieves an entry from the interface table and prints the contents of the description property of that entry.
// Before calling GetIfEntry, we call GetIfTable to make
// sure there are entries to get.
// Make an initial call to GetIfTable to get the
// necessary size into dwSize
if (GetIfTable(ifTable, &dwSize, 0) == ERROR_INSUFFICIENT_BUFFER) {
GlobalFree(ifTable);
ifTable = (MIB_IFTABLE *) malloc (dwSize);
}
// Make a second call to GetIfTable to get the actual
// data we want.
if ((dwRetVal = GetIfTable(ifTable, &dwSize, 0)) == NO_ERROR) {
if (ifTable->dwNumEntries > 0) {
pMibIfRow->dwIndex = 1;
if ((dwRetVal = GetIfEntry(pMibIfRow)) == NO_ERROR) {
printf("\tDescription: %s\n", pMibIfRow->bDescr);
}
else {
printf("GetIfEntry failed.\n");
// Here you can use FormatMessage to find out why
// it failed.
}
}
}
else {
printf("\tGetIfTable failed.\n");
}
Requirements
Client Requires Windows "Longhorn", Windows XP, Windows 2000 Professional, Windows NT Workstation 4.0 SP4 and later, Windows Me, or Windows 98.
Server Requires Windows Server "Longhorn", Windows Server 2003, Windows 2000 Server, or Windows NT Server 4.0 SP4 and later.
Header Declared in Iphlpapi.h.