Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Get device list (Microsoft Visual Studio 2010)

2025-04-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

Shulou(Shulou.com)06/01 Report--

Typically, the first thing you do when writing WinPcap-based applications is to get a list of connected network adapters. Both libpcap and WinPcap provide the pcap_findalldevs_ex () function to do this: this function returns a linked list of pcap_if structures, each of which contains the details of an adapter. It is worth noting that the data fields name and description represent an adapter name and a description that people can understand.

We use the Microsoft Visual Studio 2010 compiler tool to compile the program, find the device list under the module in the WinPcap document, click Open to get the program code to get the device list; open the Microsoft Visual Studio 2010 compilation tool, click on the file, create a new project, and then set the project name. The save path can be changed to the path you want to save, or you can use the default path, click OK, next step, finish. At this point, it will make an error when we compile the code inside, so then click on the item in the compiler-- > there is a * * attribute at the bottom (alt+F7).

Configure properties-- > inventory tool-- > input and output-- > embed list-- > No

In this way, the code can be run. We copy the program that WinPcap acquires the device list into the program, and replace everything except the header file. At this time, we can see that there is a wavy line under the function in the code. Yes, because we haven't set it up yet, look at the code first. The code is as follows:

/ / ListInterface.cpp: defines the entry point for the console application.

/ /

# include "stdafx.h"

# include "pcap.h"

Int _ tmain (int argc, _ TCHAR* argv [])

{

Pcap_if_t * alldevs

Pcap_if_t * d

Int iTunes 0

Char errbuf[PCAP _ ERRBUF_SIZE]

/ * get the list of local machines and equipment * /

If (pcap_findalldevs_ex (PCAP_SRC_IF_STRING, NULL / * auth is not needed * /, & alldevs, errbuf) =-1)

{

Fprintf (stderr, "Error in pcap_findalldevs_ex:% s\ n", errbuf)

Exit (1)

}

/ * print list * /

For (d = alldevs; d! = NULL; d = d-> next)

{

Printf ("d. S", + + I, d-> name)

If (d-> description)

Printf ("(% s)\ n", d-> description)

Else

Printf ("(No description available)\ n")

}

If (I = = 0)

{

Printf ("\ nNo interfaces found! Make sure WinPcap is installed.\ n")

Return 0

}

/ * the device list is no longer needed, release it * /

Pcap_freealldevs (alldevs)

}

Make the following settings for the compiler:

Project-- > * * attribute (alt+F7)

Configuration properties-- > Cramp Candle colors-- > General-- > attach include directory-- > (add the file path where the header file is located to the attached directory C:\ WpdPack\ Include)

Project-- > * * attribute (alt+F7)

Configure properties-- > linker-- > General-- > additional library directory-- > (add the directory where Packet.lib;wpcap.lib is located to the additional library directory C:\ WpdPack\ Lib)

Project-- > * * attribute (alt+F7)

Configure properties-- > linker-- > input-- > attach dependencies-- > supplement "; Packet.lib;wpcap.lib"

Project-- > * * attribute (alt+F7)

Configuration properties-- > Candlestick colors-- > preprocessor-- > preprocessor definition-- > supplement "; HAVE_REMOTE"

The following is the diagram of the obtained result:

Attachment: http://down.51cto.com/data/2368293

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 251

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Network Security

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report