Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libnet_inet_checksum(): ip hdr len not inside packet #168

Open
kbh1860 opened this issue Oct 18, 2023 · 1 comment
Open

libnet_inet_checksum(): ip hdr len not inside packet #168

kbh1860 opened this issue Oct 18, 2023 · 1 comment
Assignees

Comments

@kbh1860
Copy link

kbh1860 commented Oct 18, 2023

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 ㅜㅜ

@troglobit
Copy link
Collaborator

I've been meaning to add basic support for IPv6 to https://github.com/libnet/nemesis/, so I can have a look at this in a few days and get back to you.

@troglobit troglobit self-assigned this Oct 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants