/* * $smu-mark$ * $name: sendip6.c$ * $author: Matyas Koszik $ * $copyright: Copyright (C) 2006 by Matyas Koszik$ * $license: This software is under GPL version 2 of license$ * $date: Sun Apr 16 05:18:30 CEST 2006$ * $rev: 1$ */ #include #include #include #include #include #include #include #include "hping2.h" #include "globals.h" void send_ip6 (char *src, char *dst, char *data, unsigned int datalen) { char *packet; int result, packetsize; struct myip6hdr *ip6; packetsize = IP6HDR_SIZE + datalen; if ( (packet = malloc(packetsize)) == NULL) { perror("[send_ip] malloc()"); return; } memset(packet, 0, packetsize); ip6 = (struct myip6hdr*) packet; /* copy src and dst address */ memcpy(ip6->saddr, src, sizeof(ip6->saddr)); memcpy(ip6->daddr, dst, sizeof(ip6->daddr)); /* build ip header */ ip6->version = 6; // ip->tos = ip_tos; #if defined OSTYPE_FREEBSD || defined OSTYPE_NETBSD || defined OSTYPE_BSDI /* FreeBSD */ /* NetBSD */ ip6->paylen = datalen; #else /* Linux */ /* OpenBSD */ ip6->paylen = htons(datalen); #endif ip6->hoplimit = src_ttl; if (opt_rawipmode) ip6->nextheader = raw_ip_protocol; else if (opt_icmpmode) ip6->nextheader = 58; /* icmp */ else if (opt_udpmode) ip6->nextheader = 17; /* udp */ else ip6->nextheader = 6; /* tcp */ /* copies data */ memcpy(packet + IP6HDR_SIZE, data, datalen); if (opt_debug == TRUE) { unsigned int i; for (i=0; i