使用一个Makefile, 动态,静态连接libpcap
发布日期:2021-06-30 22:17:17 浏览次数:2 分类:技术文章

本文共 20982 字,大约阅读时间需要 69 分钟。

前言

调试bug时,怀疑到libpcap的静态和动态连接上,当时是改了2个版本的Makefile.

网上有资料,可以向Makefile传入参数,在一个Makefile中实现不同的编译流程。
用了半天,将这个实验做完了。
收获了一个可以动态配置的灵活的Makefile.

工程下载点

Makefile

# ==============================================================================# @file makefile# ==============================================================================# @note #   test case - see value from Makefile commandline or in the Makefile#       make PCAP_LINK_TYPE=static clean#       make PCAP_LINK_TYPE=dynamic cleanMY_MAKE_FILE_PATH_NAME = $(MAKEFILE_LIST)# is give make file cmd PCAP_LINK_TYPE ?IS_PARAM_VALID_PCAP_LINK_TYPE = 0# is link to libpcap.so ?IS_LINK_TO_LIB_PCAP_SO = 0# is link to libpcap.a ?IS_LINK_TO_LIB_PCAP_A = 0PCAP_LINK_TYPE_SO = dynamicPCAP_LINK_TYPE_A = staticifdef PCAP_LINK_TYPE    ifeq ($(PCAP_LINK_TYPE_SO), $(PCAP_LINK_TYPE))        IS_PARAM_VALID_PCAP_LINK_TYPE = 1        IS_LINK_TO_LIB_PCAP_SO = 1    else ifeq ($(PCAP_LINK_TYPE_A), $(PCAP_LINK_TYPE))        IS_PARAM_VALID_PCAP_LINK_TYPE = 1        IS_LINK_TO_LIB_PCAP_A = 1    else        IS_PARAM_VALID_PCAP_LINK_TYPE = 0    endifelse    IS_PARAM_VALID_PCAP_LINK_TYPE = 0endifBIN = test_libpcap_link_toLINE80 = --------------------------------------------------------------------------------CC = g++ -std=c++98CFLAGS = -Wall -gINC = -I. -I./lib_pcap/include/LIBPATH = -L./lib_pcap/lib/ -L/usr/lib/ -L/usr/local/lib/ifeq (1, $(IS_LINK_TO_LIB_PCAP_SO))    LIBS = -lstdc++ -lpthread -lm -fPIC -lpcapelse ifeq (1, $(IS_LINK_TO_LIB_PCAP_A))    LIBS = ./lib_pcap/lib/libpcap.a -lstdc++ -lpthread -lm -fPICelse    LIBS = endifDEPEND_CODE_DIR = ./empty_dir \DEPEND_CODE_SRC = $(shell find $(DEPEND_CODE_DIR) -name '*.cpp')DEPEND_CODE_OBJ = $(DEPEND_CODE_SRC:.cpp=.o)ROOT_CODE_SRC = $(shell find ./ -name '*.cpp')ROOT_CODE_OBJ = $(ROOT_CODE_SRC:.cpp=.o)SUB_CODE_DIR = ./socket_easySUB_CODE_SRC = $(shell find $(SUB_CODE_DIR) -name '*.cpp')SUB_CODE_OBJ = $(SUB_CODE_SRC:.cpp=.o).PHONY: helphelp:    clear    @echo "usage:"    @echo    @echo "libpcap.so dynamic link to program output"    @echo "make PCAP_LINK_TYPE=\"${PCAP_LINK_TYPE_SO}\" rebuild"    @echo    @echo "libpcap.a static link to program output"    @echo "make PCAP_LINK_TYPE=\"${PCAP_LINK_TYPE_A}\" rebuild".PHONY: cleanclean:    clear    @echo    @echo    @echo    @echo    @echo    @echo    @echo    @echo    @echo    @echo    @echo    @echo    @echo    @echo    @echo    @echo    @echo    @echo    @echo    @echo    @echo    @echo    @echo    @echo    @echo    @echo make clean    @echo $(LINE80)    @echo "@file $(MY_MAKE_FILE_PATH_NAME)"    @echo "PCAP_LINK_TYPE_SO = $(PCAP_LINK_TYPE_SO)"    @echo "PCAP_LINK_TYPE_A = $(PCAP_LINK_TYPE_A)"    @echo "PCAP_LINK_TYPE = $(PCAP_LINK_TYPE)"    @echo "IS_PARAM_VALID_PCAP_LINK_TYPE = $(IS_PARAM_VALID_PCAP_LINK_TYPE)"    @echo "IS_LINK_TO_LIB_PCAP_SO = $(IS_LINK_TO_LIB_PCAP_SO)"    @echo "IS_LINK_TO_LIB_PCAP_A = $(IS_LINK_TO_LIB_PCAP_A)"    @echo $(LINE80)    rm -f $(BIN) $(ROOT_CODE_OBJ) $(DEPEND_CODE_OBJ) $(SUB_CODE_OBJ)    rm -rf /usr/lib/$(BIN)    rm -rf ./$(BIN).PHONY: allall:$(BIN)    @echo $(LINE80)    @echo make all    chmod 777 $(BIN)    find . -name $(BIN)$(BIN) : $(ROOT_CODE_OBJ) $(DEPEND_CODE_OBJ) $(SUB_CODE_OBJ)    $(CC) $(CFLAGS) -o $@ $^ $(SHLIBS) $(INC) $(LIBPATH) $(LIBS).cpp.o:    $(CC) -c $(CFLAGS) $^ -o $@ $(INC) $(LIBPATH) $(LIBS).PHONY: rebuildrebuild:    make -f $(MY_MAKE_FILE_PATH_NAME) cleanifeq (1, $(IS_PARAM_VALID_PCAP_LINK_TYPE))    @echo $(LINE80)    make -f $(MY_MAKE_FILE_PATH_NAME) all    chmod 775 ./$(BIN)    cp ./lib_pcap/lib/libpcap.so.1 /usr/lib/    ldconfig    ldd ./$(BIN)else    @echo $(LINE80)    @echo "error : make file command line input error, please see help"     @echo "please run => make help"     @echo $(LINE80)endif

测试程序-使用了libpcap接口

// @file main.cpp// view date time// date "+DATE: %m/%d/%y%nTIME: %H:%M:%S"// set date time// date -s "2018-3-13 14:25:00"// build prj// make PCAP_LINK_TYPE="static" rebuild// make PCAP_LINK_TYPE="dynamic" rebuild#include 
#include
#include
#include
#include
#include
#include
#include
#include "my_syslog.h"#include "pcap.h"#ifndef SAFE_DELETE#define SAFE_DELETE(p) \ if (NULL != (p)) { \ delete (p); \ (p) = NULL; \ }#endif // #ifndef SAFE_DELETEvoid init();void uninit();int fn_test();int main(int argc, char** argv){ init(); fn_test(); uninit(); MYLOG_D("THE END"); return EXIT_SUCCESS;}int fn_test(){ pcap_if_t* alldevs = NULL; pcap_if_t* d = NULL; int inum = 0; int i = 0; pcap_t* adhandle = NULL; char errbuf[PCAP_ERRBUF_SIZE] = { '\0'}; MYLOG_D(">> testcase()"); do { MYLOG_D("pcap_lib_version() = %s", pcap_lib_version()); /* Retrieve the device list */ if (pcap_findalldevs(&alldevs, errbuf) == -1) { MYLOG_D("Error in pcap_findalldevs: %s", errbuf); break; } /* Print the list */ for (d = alldevs; NULL != d; d = d->next) { MYLOG_D("%d. %s (%s)", ++i, d->name, (NULL != d->description) ? d->description : "No description available"); } if (0 == i) { MYLOG_D("No interfaces found! Make sure WinPcap is installed."); break; } // printf("Enter the interface number (1-%d):",i); // scanf("%d", &inum); inum = 1; if (inum < 1 || inum > i) { MYLOG_D("Interface number out of range."); /* Free the device list */ pcap_freealldevs(alldevs); break; } /* Jump to the selected adapter */ for (d = alldevs, i = 0; i < (inum - 1); d = d->next, i++); /* Open the device */ /* Open the adapter */ adhandle = pcap_open_live(d->name, // name of the device -1, // portion of the packet to capture. // 65536 grants that the whole packet will be captured on all the MACs. 1, // promiscuous mode (nonzero means promiscuous) -1, // read timeout errbuf // error buffer ); if (NULL == adhandle) { MYLOG_D("Unable to open the adapter. %s is not supported by WinPcap", d->name); break; } MYLOG_D("listening on [%s]...", d->name); /* start the capture */ // pcap_loop(adhandle, 0, packet_handler, NULL); } while (0); /* At this point, we don't need any more the device list. Free it */ if (NULL != alldevs) { pcap_freealldevs(alldevs); alldevs = NULL; } if (NULL != adhandle) { pcap_close(adhandle); adhandle = NULL; } return 0;}void init(){ int i = 0; ns_syslog::open_syslog("test_new"); // 设置控制变量中的日志条件, 实际应用中, 是从配置文件读取的控制开关 ns_syslog::g_log_condition.b_EMERG = false; ns_syslog::g_log_condition.b_CRIT = true; ns_syslog::g_log_condition.b_ALERT = true; ns_syslog::g_log_condition.b_ERR = true; ns_syslog::g_log_condition.b_WARNING = true; ns_syslog::g_log_condition.b_NOTICE = true; ns_syslog::g_log_condition.b_INFO = true; ns_syslog::g_log_condition.b_DEBUG = true; // 根据控制变量, 设置日志的mask // 在实际应用中, 这里可以是动态设置, e.g. 配置文件检测线程发现配置变了, 需要变更某些级别的日志记录结果 ns_syslog::set_log_level( ns_syslog::g_log_condition.b_EMERG, ns_syslog::g_log_condition.b_ALERT, ns_syslog::g_log_condition.b_CRIT, ns_syslog::g_log_condition.b_ERR, ns_syslog::g_log_condition.b_WARNING, ns_syslog::g_log_condition.b_NOTICE, ns_syslog::g_log_condition.b_INFO, ns_syslog::g_log_condition.b_DEBUG); // clear screen (print 25 empty line) for (i = 0; i < 25; i++) { MYLOG_D(""); }}void uninit(){ ns_syslog::close_syslog();}/** run resultFeb 20 16:57:34 debian750devmin test_new[28878]: [DEBUG : main.cpp.56 : fn_test()] : >> testcase()Feb 20 16:57:34 debian750devmin test_new[28878]: [DEBUG : main.cpp.58 : fn_test()] : pcap_lib_version() = libpcap version 1.8.1Feb 20 16:57:34 debian750devmin test_new[28878]: [DEBUG : main.cpp.71 : fn_test()] : 1. eth0 (No description available)Feb 20 16:57:34 debian750devmin test_new[28878]: [DEBUG : main.cpp.71 : fn_test()] : 2. any (Pseudo-device that captures on all interfaces)Feb 20 16:57:34 debian750devmin test_new[28878]: [DEBUG : main.cpp.71 : fn_test()] : 3. lo (No description available)Feb 20 16:57:34 debian750devmin test_new[28878]: [DEBUG : main.cpp.71 : fn_test()] : 4. nflog (Linux netfilter log (NFLOG) interface)Feb 20 16:57:34 debian750devmin test_new[28878]: [DEBUG : main.cpp.71 : fn_test()] : 5. nfqueue (Linux netfilter queue (NFQUEUE) interface)Feb 20 16:57:34 debian750devmin test_new[28878]: [DEBUG : main.cpp.71 : fn_test()] : 6. usbmon1 (USB bus number 1)Feb 20 16:57:34 debian750devmin test_new[28878]: [DEBUG : main.cpp.71 : fn_test()] : 7. usbmon2 (USB bus number 2)Feb 20 16:57:34 debian750devmin kernel: [714254.278799] device eth0 entered promiscuous modeFeb 20 16:57:34 debian750devmin test_new[28878]: [DEBUG : main.cpp.108 : fn_test()] : listening on [eth0]...Feb 20 16:57:34 debian750devmin test_new[28878]: [DEBUG : main.cpp.43 : main()] : THE ENDFeb 20 16:57:34 debian750devmin kernel: [714254.281525] device eth0 left promiscuous mode*/

辅助文件-日志

// @file my_syslog.h// @brief syslog日志宏的定义#include 
#include
#include
#include
#include
#include
namespace ns_syslog {typedef struct _tag_log_condition { bool b_EMERG; bool b_ALERT; bool b_CRIT; bool b_ERR; bool b_WARNING; bool b_NOTICE; bool b_INFO; bool b_DEBUG; _tag_log_condition() { b_EMERG = false; b_ALERT = false; b_CRIT = false; b_ERR = false; b_WARNING = false; b_NOTICE = false; b_INFO = false; b_DEBUG = false; }} TAG_LOG_CONDITION;extern TAG_LOG_CONDITION g_log_condition;// ----------------------------------------------------------------------------// syslog macro// ----------------------------------------------------------------------------#define MYLOG_EMERG(fmt, ...) \if (ns_syslog::g_log_condition.b_EMERG) { \syslog(LOG_EMERG, "[%s : %s.%d : %s()] : " fmt, "EMERG", __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__); \}#define MYLOG_EM(fmt, ...) \if (ns_syslog::g_log_condition.b_EMERG) { \syslog(LOG_INFO, "[%s : %s.%d : %s()] : " fmt, "EMERG", __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__); \}// ----------------------------------------------------------------------------#define MYLOG_ALERT(fmt, ...) \if (ns_syslog::g_log_condition.b_ALERT) { \syslog(LOG_ALERT, "[%s : %s.%d : %s()] : " fmt, "ALERT", __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__); \}#define MYLOG_A(fmt, ...) \if (ns_syslog::g_log_condition.b_ALERT) { \syslog(LOG_INFO, "[%s : %s.%d : %s()] : " fmt, "ALERT", __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__); \}// ----------------------------------------------------------------------------#define MYLOG_CRIT(fmt, ...) \if (ns_syslog::g_log_condition.b_CRIT) { \syslog(LOG_CRIT, "[%s : %s.%d : %s()] : " fmt, "CRIT", __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__); \}#define MYLOG_C(fmt, ...) \if (ns_syslog::g_log_condition.b_CRIT) { \syslog(LOG_INFO, "[%s : %s.%d : %s()] : " fmt, "CRIT", __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__); \}// ----------------------------------------------------------------------------#define MYLOG_ERR(fmt, ...) \if (ns_syslog::g_log_condition.b_ERR) { \syslog(LOG_ERR, "[%s : %s.%d : %s()] : " fmt, "ERR", __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__); \}#define MYLOG_E(fmt, ...) \if (ns_syslog::g_log_condition.b_ERR) { \syslog(LOG_INFO, "[%s : %s.%d : %s()] : " fmt, "ERR", __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__); \}// ----------------------------------------------------------------------------#define MYLOG_WARNING(fmt, ...) \if (ns_syslog::g_log_condition.b_WARNING) { \syslog(LOG_WARNING, "[%s : %s.%d : %s()] : " fmt, "WARNING", __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__); \}#define MYLOG_W(fmt, ...) \if (ns_syslog::g_log_condition.b_WARNING) { \syslog(LOG_INFO, "[%s : %s.%d : %s()] : " fmt, "WARNING", __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__); \}// ----------------------------------------------------------------------------#define MYLOG_NOTICE(fmt, ...) \if (ns_syslog::g_log_condition.b_NOTICE) { \syslog(LOG_NOTICE, "[%s : %s.%d : %s()] : " fmt, "NOTICE", __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__); \}#define MYLOG_N(fmt, ...) \if (ns_syslog::g_log_condition.b_NOTICE) { \syslog(LOG_INFO, "[%s : %s.%d : %s()] : " fmt, "NOTICE", __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__); \}// ----------------------------------------------------------------------------#define MYLOG_INFO(fmt, ...) \if (ns_syslog::g_log_condition.b_INFO) { \syslog(LOG_INFO, "[%s : %s.%d : %s()] : " fmt, "INFO", __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__); \}#define MYLOG_I(fmt, ...) \if (ns_syslog::g_log_condition.b_INFO) { \syslog(LOG_INFO, "[%s : %s.%d : %s()] : " fmt, "INFO", __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__); \}// ----------------------------------------------------------------------------#define MYLOG_DEBUG(fmt, ...) \if (ns_syslog::g_log_condition.b_DEBUG) { \syslog(LOG_DEBUG, "[%s : %s.%d : %s()] : " fmt, "DEBUG", __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__); \}#define MYLOG_D(fmt, ...) \if (ns_syslog::g_log_condition.b_DEBUG) { \syslog(LOG_INFO, "[%s : %s.%d : %s()] : " fmt, "DEBUG", __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__); \}// ----------------------------------------------------------------------------void open_syslog(const char* pszLogOwner);void set_log_level( bool b_EMERG = false, bool b_CRIT = false, bool b_ALERT = false, bool b_ERR = false, bool b_WARNING = false, bool b_NOTICE = false, bool b_INFO = false, bool b_DEBUG = false);void close_syslog();} // namespace ns_syslog {
// @file my_syslog.cpp// @brief syslog日志宏的实现#include "my_syslog.h"namespace ns_syslog {TAG_LOG_CONDITION g_log_condition;void open_syslog(const char* pszLogOwner){    openlog(((NULL != pszLogOwner) ? pszLogOwner : "my_syslog"), LOG_NOWAIT | LOG_PID, LOG_LOCAL1);}void set_log_level(    bool b_EMERG,    bool b_CRIT,    bool b_ALERT,    bool b_ERR,    bool b_WARNING,    bool b_NOTICE,    bool b_INFO,    bool b_DEBUG){    int i_mask = 0;    if (b_EMERG) {        // LOG_EMERG 日志会阻塞控制台程序, 必须要使这个条件为false, 不能执行这里        // LOG_EMERG 不仅是记录到日志, 还打印到正在运行的程序上, 阻塞了程序的执行. 不能用这种日志        i_mask |= LOG_MASK(LOG_EMERG);        }    if (b_ALERT) {        i_mask |= LOG_MASK(LOG_ALERT);    }    if (b_CRIT) {        i_mask |= LOG_MASK(LOG_CRIT);    }    if (b_ERR) {        i_mask |= LOG_MASK(LOG_ERR);    }    if (b_WARNING) {        i_mask |= LOG_MASK(LOG_WARNING);    }    if (b_NOTICE) {        i_mask |= LOG_MASK(LOG_NOTICE);    }    if (b_INFO) {        i_mask |= LOG_MASK(LOG_INFO);    }    if (b_DEBUG) {        i_mask |= LOG_MASK(LOG_DEBUG);    }    setlogmask(i_mask);}void close_syslog(){    closelog();}} // namespace ns_syslog {

编译和运行过程

// @file readme.txt// --------------------------------------------------------------------------------make help// --------------------------------------------------------------------------------usage:libpcap.so dynamic link to program outputmake PCAP_LINK_TYPE="dynamic" rebuildlibpcap.a static link to program outputmake PCAP_LINK_TYPE="static" rebuild// --------------------------------------------------------------------------------make PCAP_LINK_TYPE="dynamic" rebuild// --------------------------------------------------------------------------------make clean--------------------------------------------------------------------------------@file  MakefilePCAP_LINK_TYPE_SO = dynamicPCAP_LINK_TYPE_A = staticPCAP_LINK_TYPE = dynamicIS_PARAM_VALID_PCAP_LINK_TYPE = 1IS_LINK_TO_LIB_PCAP_SO = 1IS_LINK_TO_LIB_PCAP_A = 0--------------------------------------------------------------------------------rm -f test_libpcap_link_to ./my_syslog.o ./main.o  rm -rf /usr/lib/test_libpcap_link_torm -rf ./test_libpcap_link_tomake[1]: Leaving directory `/home/dev'--------------------------------------------------------------------------------make -f  Makefile allfind: “./empty_dir”: 没有那个文件或目录find: “./socket_easy”: 没有那个文件或目录make[1]: Entering directory `/home/dev'g++ -std=c++98 -c -Wall -g my_syslog.cpp -o my_syslog.o -I. -I./lib_pcap/include/ -L./lib_pcap/lib/ -L/usr/lib/ -L/usr/local/lib/ -lstdc++ -lpthread -lm -fPIC -lpcapg++ -std=c++98 -c -Wall -g main.cpp -o main.o -I. -I./lib_pcap/include/ -L./lib_pcap/lib/ -L/usr/lib/ -L/usr/local/lib/ -lstdc++ -lpthread -lm -fPIC -lpcapg++ -std=c++98 -Wall -g -o test_libpcap_link_to my_syslog.o main.o  -I. -I./lib_pcap/include/ -L./lib_pcap/lib/ -L/usr/lib/ -L/usr/local/lib/ -lstdc++ -lpthread -lm -fPIC -lpcap--------------------------------------------------------------------------------make allchmod 777 test_libpcap_link_tofind . -name test_libpcap_link_to./test_libpcap_link_tomake[1]: Leaving directory `/home/dev'chmod 775 ./test_libpcap_link_tocp ./lib_pcap/lib/libpcap.so.1 /usr/lib/ldconfigldd ./test_libpcap_link_to    linux-vdso.so.1 =>  (0x00007fff9e9ff000)    libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00002b175fe61000)    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00002b1760168000)    libpcap.so.1 => /usr/lib/libpcap.so.1 (0x00002b1760385000)    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00002b17605c4000)    libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00002b1760846000)    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00002b1760a5d000)    /lib64/ld-linux-x86-64.so.2 (0x00002b175fc3f000)// --------------------------------------------------------------------------------make PCAP_LINK_TYPE="static" rebuild// --------------------------------------------------------------------------------make clean--------------------------------------------------------------------------------@file  MakefilePCAP_LINK_TYPE_SO = dynamicPCAP_LINK_TYPE_A = staticPCAP_LINK_TYPE = staticIS_PARAM_VALID_PCAP_LINK_TYPE = 1IS_LINK_TO_LIB_PCAP_SO = 0IS_LINK_TO_LIB_PCAP_A = 1--------------------------------------------------------------------------------rm -f test_libpcap_link_to ./my_syslog.o ./main.o  rm -rf /usr/lib/test_libpcap_link_torm -rf ./test_libpcap_link_tomake[1]: Leaving directory `/home/dev'--------------------------------------------------------------------------------make -f  Makefile allfind: “./empty_dir”: 没有那个文件或目录find: “./socket_easy”: 没有那个文件或目录make[1]: Entering directory `/home/dev'g++ -std=c++98 -c -Wall -g my_syslog.cpp -o my_syslog.o -I. -I./lib_pcap/include/ -L./lib_pcap/lib/ -L/usr/lib/ -L/usr/local/lib/ ./lib_pcap/lib/libpcap.a -lstdc++ -lpthread -lm -fPICg++: warning: ./lib_pcap/lib/libpcap.a: linker input file unused because linking not doneg++ -std=c++98 -c -Wall -g main.cpp -o main.o -I. -I./lib_pcap/include/ -L./lib_pcap/lib/ -L/usr/lib/ -L/usr/local/lib/ ./lib_pcap/lib/libpcap.a -lstdc++ -lpthread -lm -fPICg++: warning: ./lib_pcap/lib/libpcap.a: linker input file unused because linking not doneg++ -std=c++98 -Wall -g -o test_libpcap_link_to my_syslog.o main.o  -I. -I./lib_pcap/include/ -L./lib_pcap/lib/ -L/usr/lib/ -L/usr/local/lib/ ./lib_pcap/lib/libpcap.a -lstdc++ -lpthread -lm -fPIC--------------------------------------------------------------------------------make allchmod 777 test_libpcap_link_tofind . -name test_libpcap_link_to./test_libpcap_link_tomake[1]: Leaving directory `/home/dev'chmod 775 ./test_libpcap_link_tocp ./lib_pcap/lib/libpcap.so.1 /usr/lib/ldconfigldd ./test_libpcap_link_to    linux-vdso.so.1 =>  (0x00007fff354b1000)    libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00002b38e63bb000)    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00002b38e66c2000)    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00002b38e68df000)    libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00002b38e6b61000)    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00002b38e6d77000)    /lib64/ld-linux-x86-64.so.2 (0x00002b38e6199000)// --------------------------------------------------------------------------------// run result// --------------------------------------------------------------------------------Mar 24 15:39:17 debian750devmin test_new[7923]: [DEBUG : main.cpp.56 : fn_test()] : >> testcase()Mar 24 15:39:17 debian750devmin test_new[7923]: [DEBUG : main.cpp.58 : fn_test()] : pcap_lib_version() = libpcap version 1.8.1Mar 24 15:39:17 debian750devmin test_new[7923]: [DEBUG : main.cpp.71 : fn_test()] : 1. eth0 (No description available)Mar 24 15:39:17 debian750devmin test_new[7923]: [DEBUG : main.cpp.71 : fn_test()] : 2. any (Pseudo-device that captures on all interfaces)Mar 24 15:39:17 debian750devmin test_new[7923]: [DEBUG : main.cpp.71 : fn_test()] : 3. lo (No description available)Mar 24 15:39:17 debian750devmin test_new[7923]: [DEBUG : main.cpp.71 : fn_test()] : 4. nflog (Linux netfilter log (NFLOG) interface)Mar 24 15:39:17 debian750devmin test_new[7923]: [DEBUG : main.cpp.71 : fn_test()] : 5. nfqueue (Linux netfilter queue (NFQUEUE) interface)Mar 24 15:39:17 debian750devmin test_new[7923]: [DEBUG : main.cpp.71 : fn_test()] : 6. usbmon1 (USB bus number 1)Mar 24 15:39:17 debian750devmin test_new[7923]: [DEBUG : main.cpp.71 : fn_test()] : 7. usbmon2 (USB bus number 2)Mar 24 15:39:17 debian750devmin kernel: [ 7574.262626] device eth0 entered promiscuous modeMar 24 15:39:17 debian750devmin test_new[7923]: [DEBUG : main.cpp.108 : fn_test()] : listening on [eth0]...Mar 24 15:39:17 debian750devmin test_libpcap_link_to[7923]: [DEBUG : main.cpp.43 : main()] : THE ENDMar 24 15:39:17 debian750devmin kernel: [ 7574.264846] device eth0 left promiscuous mode

转载地址:https://lostspeed.blog.csdn.net/article/details/79678654 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:linux C : 子进程监听父进程使用的socket端口问题
下一篇:debug : linux C, 由rename API引起的内存被吃光

发表评论

最新留言

能坚持,总会有不一样的收获!
[***.219.124.196]2024年04月30日 13时27分42秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章