3 * Copyright (C) 2010 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 # include <arpa/inet.h>
25 # include <ws2tcpip.h>
32 static int fd
; /* FD for IPv6 packet sender */
33 static char ipv6
[64]; /* temporary buffer used by ipv6_print () */
35 extern const char *inet_ntop (int af
, const void *src
, char *dst
, socklen_t cnt
);
38 /* compare two IPv6 address */
39 unsigned ipv6_cmp (ipv6_addr_t ip
, ipv6_addr_t ip2
)
42 for (i
= 0; i
< 8; i
++)
49 /* compare two IPv6 prefix address */
50 unsigned ipv6_cmp_prefix (ipv6_prefix_t pr
, ipv6_prefix_t ip
)
52 /* check valid prefix length */
57 for (i
= 0; i
< (pr
[15]/8); i
++)
64 /* print IPv6 address onto console */
65 char *ipv6_print (ipv6_addr_t ip
)
67 if (!inet_ntop (AF_INET6
, ip
, ipv6
, 64))
73 int ipv6_send (char *data
, int len
)
75 struct sockaddr_in6 sockaddr
;
76 struct proto_ipv6_t
*ip
= (struct proto_ipv6_t
*) data
;
78 /* prepare data for RAW socket */
79 sockaddr
.sin6_family
= AF_INET6
;
80 sockaddr
.sin6_port
= 0;
81 memcpy (&sockaddr
.sin6_addr
.s6_addr
, ip
->dest
, sizeof (ipv6_addr_t
));
84 if (sendto (fd
, data
, len
, 0, (struct sockaddr
*) &sockaddr
, sizeof (struct sockaddr_in6
)) != len
) {
94 /* initialize raw socket */
95 if ((fd
= socket (AF_INET6
, SOCK_RAW
, IPPROTO_RAW
)) == -1) {