环回中的嗅探会捕获外部流量吗?
Does sniffing in loopback capture outside traffic?
我有一个游戏服务器在某个端口上运行。 我学会了在环回上嗅数据包。因此,如果我从同一台计算机连接到它,则会捕获数据包。
但是有人可以从其他计算机连接,并且数据包不会被嗅探。
来自某台计算机的数据包必须通过我的一个接口。那么我是否应该也嗅探该接口,以便从我的计算机和其他计算机获取数据包?
这是我的程序
#define IP_HL(ip) (((ip)->ip_vhl) & 0x0f)
#define IP_V(ip) (((ip)->ip_vhl) >> 4)
#define _WINSOCK_DEPRECATED_NO_WARNINGS
#include <stdio.h>
#include <pcap.h>
#include <WS2tcpip.h>
#pragma comment(lib, "Ws2_32.lib")
void
got_packet(u_char* args, const struct pcap_pkthdr* header, const u_char* packet)
{
for (int i = 0; i < (*header).len; i++)
{
printf("%d ", (unsigned char)packet[i]);
}
printf("n");
return;
}
int main(int argc, char* argv[])
{
char* dev, errbuf[PCAP_ERRBUF_SIZE];
pcap_if_t* interfaces, * temp;
pcap_if_t* loopback = NULL;
int i= pcap_findalldevs(&interfaces,errbuf);
if (i == -1) {
fprintf(stderr, "Couldn't find default device: %sn", errbuf);
return(2);
}
for (temp = interfaces; temp; temp = temp->next)
{
printf("%d ", temp->flags);
printf("Name: %s with ", temp->name);
printf(" %s n", temp->description);
if (temp->flags % 2 == 1)
{
printf("Loopback device foundn");
loopback = temp;
}
}
if (loopback == NULL)
{
printf("No loopback device found.n Install npcap from nmap.org/npcap / ");
return 0;
}
struct bpf_program fp; /* The compiled filter expression */
pcap_t* handle;
char filter_exp[] = "port 8192"; /* The filter expression */
bpf_u_int32 net = NULL; /* The IP of our sniffing device */
struct pcap_pkthdr header; /* The header that pcap gives us */
const u_char* packet; /* The actual packet */
handle = pcap_open_live(loopback->name, BUFSIZ, 1, 5000, errbuf);
if (handle == NULL) {
fprintf(stderr, "Couldn't open device %s: %sn", loopback->name, errbuf);
return(2);
}
if (pcap_compile(handle, &fp, filter_exp, 0, net) == -1) {
fprintf(stderr, "Couldn't parse filter %s: %sn", filter_exp, pcap_geterr(handle));
return(2);
}
if (pcap_setfilter(handle, &fp) == -1) {
fprintf(stderr, "Couldn't install filter %s: %sn", filter_exp, pcap_geterr(handle));
return(2);
}
pcap_loop(handle, -1, got_packet, NULL);
pcap_close(handle);
return(0);
}
那么我是否也应该在该接口上嗅探以获取来自我的计算机和其他计算机的数据包?
是的,您可以使用这样做 - 或者,如果您在Linux 上运行,您可以在"任何"设备上捕获,这应该捕获所有接口上的流量。
相关文章:
- 在函数内部的声明中初始化数组,并在外部使用它
- 使外部项目可用于find_package CMake
- C++:Application.cpp中抛出了未解析的外部符号(解决方案在问题的末尾,供未来的读者参考)
- 使用外部SDK工具链文件在VisualStudio上生成项目编译错误
- C++:来自外部文件的Trivia
- 从函数角度看ID到文件路径的内部与外部映射
- C++:将外部库链接到dll库
- spdlog标头仅与外部fmt一起使用.spdlog错误:'内部':不是'fmt'
- 节俭并发:未解决的外部问题
- 如何在c++中从git建立外部库
- 未解析的外部符号_MsiLocateComponentW@12.
- 如何使用对C函数和类对象的外部调用来处理C++头文件
- 具有非整数边容量的最大流量的Dinic算法
- 具有外部"c"和程序集的未定义函数
- 为什么导入Mixed native/CLR lib.dll的本机C++应用程序没有在Mixed lib.dll中的外部变
- 在C++中使用 gRPC 时未解析的外部符号
- 在类函数中初始化外部作用域变量
- 如果全局变量默认是外部变量,为什么要添加"extern"关键字?
- 调用外部函数,无法指定类型 C++/MVS
- 环回中的嗅探会捕获外部流量吗?