You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
i want to send ipv6 packet, But there is some error my code
#include <libnet.h>
#include <pcap.h>
#include <string.h>
#pragma comment(lib, "packet.lib")
#pragma comment(lib, "wpcap.lib")
int main(int argc, char** argv) {
pcap_if_t* alldevs;
libnet_t* libnet_context;
char errbuf[LIBNET_ERRBUF_SIZE];
if (pcap_findalldevs(&alldevs, errbuf) == -1) {
fprintf(stderr, "Error : %s\n", errbuf);
return 1;
}
libnet_context = libnet_init(LIBNET_RAW6, alldevs->name, errbuf);
if (libnet_context == NULL) {
fprintf(stderr, "libnet_init() is failed : %s\n", errbuf);
return 1;
}
uint8_t icmp_payload[] = "\x90\x90\x90\x90\x90\x90\x90";
int payload_size = strlen((char*)icmp_payload);
struct libnet_in6_addr src_ip, dst_ip;
inet_pton(AF_INET6, "fe80::a14d:bcb7:e45a:4051", &src_ip);
inet_pton(AF_INET6, "fe80::1a40:9362:226f:33c1", &dst_ip);
// First, build the ICMPv6 header
libnet_ptag_t icmp_tag = LIBNET_PTAG_INITIALIZER;
icmp_tag = libnet_build_icmpv6_echo(
ICMP6_ECHO,
0x0,
0x0,
0x1,
0x0,
NULL,
0x0,
libnet_context,
icmp_tag
);
if (icmp_tag == -1) {
fprintf(stderr, "libnet_build_icmpv6_echo failed: %s\n", libnet_geterror(libnet_context));
libnet_destroy(libnet_context);
return 1;
}
// Next, build the destination options extension header
uint8_t options[8] = { 0 }; // This is a placeholder. You can use actual destination options if needed.
libnet_ptag_t dstopts_tag = LIBNET_PTAG_INITIALIZER;
dstopts_tag = libnet_build_ipv6_destopts(
IPPROTO_DSTOPTS,
payload_size,
icmp_payload,
payload_size,
libnet_context,
dstopts_tag
);
if (dstopts_tag == -1) {
fprintf(stderr, "libnet_build_ipv6_destopts failed: %s\n", libnet_geterror(libnet_context));
libnet_destroy(libnet_context);
return 1;
}
// Now build the IPv6 header with next header set to destination options
libnet_ptag_t ipv6_tag = LIBNET_PTAG_INITIALIZER;
ipv6_tag = libnet_build_ipv6(
0x0,
0x0,
LIBNET_ICMPV6_H + LIBNET_IPV6_DESTOPTS_H + payload_size, // add the length of the destination options header
IPPROTO_DSTOPTS,
64,
src_ip,
dst_ip,
NULL,
0,
libnet_context,
ipv6_tag
);
if (ipv6_tag == -1) {
fprintf(stderr, "libnet_build_ipv6 failed: %s\n", libnet_geterror(libnet_context));
libnet_destroy(libnet_context);
return 1;
}
int bytes_written = libnet_write(libnet_context);
if (bytes_written == -1) {
fprintf(stderr, "Failed to write to send packet : %s\n", libnet_geterror(libnet_context));
return 1;
}
else {
printf("%d bytes sent\n", bytes_written);
}
libnet_destroy(libnet_context);
return 0;
}
i wrote code like this in windows environment, but libnet_geterror() says to me libnet_inet_checksum(): ip hdr len not inside packet any one does know about this issue?? plz help me ㅜㅜ
The text was updated successfully, but these errors were encountered:
i want to send ipv6 packet, But there is some error my code
i wrote code like this in
windows
environment, butlibnet_geterror()
says to melibnet_inet_checksum(): ip hdr len not inside packet
any one does know about this issue?? plz help me ㅜㅜThe text was updated successfully, but these errors were encountered: