GetIfEntry函数的使用

luoshulin 2005-09-29 11:15:29
GetIfEntry函数的使用有人知道么,它用到的结构体需要怎么定义的阿?知道的能说说不?急需
...全文
198 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
luoshulin 2005-10-09
  • 打赏
  • 举报
回复
解决掉了结束咯
luoshulin 2005-09-29
  • 打赏
  • 举报
回复
阿不这个么这个我自己找的到九是用不来么
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 中。

其他信息: 无法封送 parameter #1。
time_is_life 2005-09-29
  • 打赏
  • 举报
回复
MIB_IFROW

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:

MIB_IF_TYPE_OTHER
MIB_IF_TYPE_ETHERNET
MIB_IF_TYPE_TOKENRING
MIB_IF_TYPE_FDDI
MIB_IF_TYPE_PPP
MIB_IF_TYPE_LOOPBACK
MIB_IF_TYPE_SLIP

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.

time_is_life 2005-09-29
  • 打赏
  • 举报
回复
GetIfEntry

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.


// Declare and initialize variables.
PMIB_IFTABLE ifTable;
PMIB_IFROW pMibIfRow;
DWORD dwSize = 0;
DWORD dwRetVal = 0;

// Allocate memory for our pointers.
ifTable = (MIB_IFTABLE*) malloc(sizeof(MIB_IFTABLE));
pMibIfRow = (MIB_IFROW*) malloc(sizeof(MIB_IFROW));

// 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.

Library Link to Iphlpapi.lib.

DLL Requires Iphlpapi.dll.

110,476

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧