RAW ソケット: でパケットをフィルタリングする方法はRAW Socket
? サーバープログラムでキャプチャしようとしUDP packets
ましたが、すべてのパケットを受信しました。Linux でパケットをフィルタリングする関数またはコマンドはありますか。
5789 次
2 に答える
0
#include <sys/socket.h>
#include <netinet/in.h>
raw_socket = socket(AF_INET, SOCK_RAW, int protocol);
このプロトコル フィールドを使用して、特定のパケットをキャプチャできます。
int fd = socket (PF_INET, SOCK_RAW, IPPROTO_TCP);
char buffer[8192]; /* single packets are usually not bigger than 8192 bytes */
while (read (fd, buffer, 8192) > 0)
{
printf ("Caught tcp packet: %s\n",
buffer+sizeof(struct iphdr)+sizeof(struct tcphdr));
}
上記のコードは、すべての TCP パケットをキャプチャします。同様にUDPにも使用できます
socket (PF_INET, SOCK_RAW, IPPROTO_UDP);
于 2014-05-23T07:26:48.870 に答える