如何用C++语言实现对本地网络流量的监控

aigo_1984 2008-03-29 11:41:59
如何用C++语言实现对本地网络流量监控的程序,想做成一个像迅雷那样的浮动窗口。窗口浮动在桌面上,可以实时现实网络流量。希望大家说说自己的思路,以及要用到的的库函数。谢谢
...全文
1135 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
greatws 2008-03-29
  • 打赏
  • 举报
回复
看下winpcap的例子程序,很简单,还能统计各种协议
KeSummer 2008-03-29
  • 打赏
  • 举报
回复
流量是指网卡发送和接收的数据包吗?就是和网络连接属性里的那个.
如果是的话可以使用GetIfTable,这个API会返回MIB_IFROW的系列结构体.如下:
  
Platform SDK: Management Information Base
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 XP, Windows 2000 Professional, Windows NT Workstation 4.0 SP4 and later, Windows Me, or Windows 98.
Server Requires Windows Server 2003, Windows 2000 Server, or Windows NT Server 4.0 SP4 and later.
Header Declared in Iprtrmib.h.


See Also
GetIfEntry, MIB_IFSTATUS, MIB_IFTABLE, MPR_INTERFACE_0

--------------------------------------------------------------------------------

Last updated: March 2005 | What did you think of this topic? | Order a Platform SDK CD
© Microsoft Corporation. All rights reserved. Terms of use.



Requirements
Client Requires Windows XP, Windows 2000 Professional, Windows NT Workstation 4.0 SP4 and later, Windows Me, or Windows 98.
Server Requires Windows Server 2003, Windows 2000 Server, or Windows NT Server 4.0 SP4 and later.
Header Declared in Iprtrmib.h.

See Also
GetIfEntry, MIB_IFSTATUS, MIB_IFTABLE, MPR_INTERFACE_0



里面的
dwIn***,dwOut***就是流过网卡的数据包,当然要加起来.
jackholy 2008-03-29
  • 打赏
  • 举报
回复
_WSAIOW(IOC_VENDOR,1)

18,363

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 网络编程
c++c语言开发语言 技术论坛(原bbs)
社区管理员
  • 网络编程
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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