#include #include #include #include #include #include #include #include #include #include #include #include #define MAX_PACKET_LEN 65507 // Max UDP payload size (practical) void print_socket_options(int fd) { int val; socklen_t len = sizeof(val); // SO_SNDBUF if (getsockopt(fd, SOL_SOCKET, SO_SNDBUF, &val, &len) == 0) { printf("Socket send buffer size (SO_SNDBUF): %d bytes\n", val); } else { perror("getsockopt SO_SNDBUF"); } // IPV6_DONTFRAG if (getsockopt(fd, IPPROTO_IPV6, IPV6_DONTFRAG, &val, &len) == 0) { printf("IPV6_DONTFRAG: %s\n", val ? "ENABLED (no fragmentation)" : "DISABLED (fragmentation allowed)"); } else { perror("getsockopt IPV6_DONTFRAG"); } } void print_interface_mtu(const char *ifname) { int sock; struct ifreq ifr; sock = socket(AF_INET6, SOCK_DGRAM, 0); if (sock < 0) { perror("socket (for ioctl)"); return; } memset(&ifr, 0, sizeof(ifr)); strncpy(ifr.ifr_name, ifname, IFNAMSIZ - 1); if (ioctl(sock, SIOCGIFMTU, &ifr) == 0) { printf("Interface MTU for %s: %d bytes\n", ifname, ifr.ifr_mtu); } else { perror("ioctl SIOCGIFMTU"); } close(sock); } int main(int argc, char *argv[]) { int fd; struct sockaddr_in6 sa6; socklen_t sa_len; char *buf; ssize_t n; size_t len = MAX_PACKET_LEN; const char *iface = "lo"; // Default interface (loopback) const char *target_ip = "::1"; // Default target if (argc > 1) { len = atoi(argv[1]); // Allow custom payload length } if (argc > 2) { iface = argv[2]; // Allow custom interface } printf("Attempting to send %zu bytes via IPv6 UDP\n", len); printf("Target: [%s]:9999\n", target_ip); printf("Interface: %s\n\n", iface); print_interface_mtu(iface); // Create IPv6 UDP socket fd = socket(AF_INET6, SOCK_DGRAM, 0); if (fd < 0) { perror("socket"); exit(EXIT_FAILURE); } print_socket_options(fd); // Set up destination address memset(&sa6, 0, sizeof(sa6)); sa6.sin6_family = AF_INET6; sa6.sin6_port = htons(9999); if (inet_pton(AF_INET6, target_ip, &sa6.sin6_addr) <= 0) { perror("inet_pton"); close(fd); exit(EXIT_FAILURE); } sa_len = sizeof(sa6); // Allocate and fill buffer buf = malloc(len); if (!buf) { perror("malloc"); close(fd); exit(EXIT_FAILURE); } memset(buf, 'X', len); // Send the packet n = sendto(fd, buf, len, 0, (struct sockaddr *)&sa6, sa_len); if (n < 0) { perror("sendto"); fprintf(stderr, "errno = %d (%s)\n", errno, strerror(errno)); } else { printf("\n✅ Sent %zd bytes successfully over IPv6 UDP\n", n); } free(buf); close(fd); return 0; }