Skip to content

Commit

Permalink
Added basic IPv6 support. In all places where IPv4 addresses were
Browse files Browse the repository at this point in the history
recognized before, the program now accepts hostnames or IPv6
addresses.  The parsing code has been mostly rewritten for this.  It
now has slightly better diagnostics as well.

Note that spoofing is not supported for IPv6 yet.  Unfortunately IPv6
raw sockets don't quite work in the same way as IPv4 raw sockets, so
supporting this won't be trivial.
  • Loading branch information
sleinen committed Sep 25, 2011
1 parent 6481e52 commit 294f34b
Show file tree
Hide file tree
Showing 9 changed files with 1,008 additions and 403 deletions.
4 changes: 2 additions & 2 deletions Makefile.am
Expand Up @@ -3,9 +3,9 @@
PACKAGE = samplicator

bin_PROGRAMS = samplicate
samplicate_SOURCES = samplicate.c samplicator.h rawsend.c rawsend.h read_config.c read_config.h
samplicate_SOURCES = samplicate.c samplicator.h rawsend.c rawsend.h read_config.c read_config.h inet.c inet.h
samplicate_LDADD = @LIBOBJS@

EXTRA_PROGRAMS = rawtest parsetest
rawtest_SOURCES = rawtest.c rawsend.c rawsend.h
parsetest_SOURCES = parsetest.c read_config.c rawsend.c read_config.h rawsend.h samplicator.h
parsetest_SOURCES = parsetest.c read_config.c rawsend.c read_config.h rawsend.h samplicator.h inet.c inet.h
1 change: 0 additions & 1 deletion configure.in
Expand Up @@ -8,7 +8,6 @@ AC_CHECK_LIB(socket,bind)
AC_STDC_HEADERS
AC_CHECK_HEADERS(stdlib.h unistd.h ctype.h arpa/inet.h netinet/in_systm.h sys/uio.h)
AC_CHECK_FUNCS(memcpy strchr)
AC_REPLACE_FUNCS(inet_aton)
AC_DEFINE([HAVE_STRUCT_IP], 1,
[Define if the system has `struct ip'.])
AC_DEFINE([HAVE_STRUCT_IPHDR], 1,
Expand Down
15 changes: 6 additions & 9 deletions parsetest.c
Expand Up @@ -58,9 +58,6 @@
#ifdef HAVE_CTYPE_H
# include <ctype.h>
#endif
#ifndef HAVE_INET_ATON
extern int inet_aton (const char *, struct in_addr *);
#endif

#include "samplicator.h"
#include "read_config.h"
Expand Down Expand Up @@ -90,7 +87,7 @@ check_receiver (receiver, addr, port, af, freq, ttl)
else if (af == AF_INET6)
check_int_equal (receiver->addrlen, sizeof (struct sockaddr_in6));
else
return test_fail ();
test_fail ();
check_address_equal ((struct sockaddr *) &receiver->addr, addr, port, af);
check_int_equal (receiver->freq, freq);
check_int_equal (receiver->ttl, ttl);
Expand Down Expand Up @@ -121,17 +118,15 @@ main (int argc, char **argv)
check_int_equal (ctx.fork, 0);
check_null (ctx.sources);

#ifdef NOTYET
check_int_equal (parse_cf_string ("1.2.3.4/30+ 6.7.8.9/1234\n", &ctx), -1);
#endif

check_int_equal (parse_cf_string ("1.2.3.4/255.255.255.252: 6.7.8.9/1234\n2.3.4.5: 7.8.9.0/4321", &ctx), 0);
check_int_equal (parse_cf_string ("1.2.3.4/255.255.255.252: 6.7.8.9/1234/10,237\n2.3.4.5: 7.8.9.0/4321", &ctx), 0);
check_int_equal (ctx.fork, 0);
if (check_non_null (sctx = ctx.sources))
{
check_source_address_mask (sctx, "1.2.3.4", "255.255.255.252", AF_INET);
check_int_equal (sctx->nreceivers, 1);
check_receiver (&sctx->receivers[0], "6.7.8.9", 1234, AF_INET, 1, DEFAULT_TTL);
check_receiver (&sctx->receivers[0], "6.7.8.9", 1234, AF_INET, 10, 237);
if (check_non_null (sctx = sctx->next))
{
check_source_address_mask (sctx, "2.3.4.5", "255.255.255.255", AF_INET);
Expand All @@ -141,7 +136,6 @@ main (int argc, char **argv)
}
}

#ifdef NOTYET
check_int_equal (parse_cf_string ("1.2.3.4/30: 6.7.8.9/1234\n2.3.4.5: 7.8.9.0/4321", &ctx), 0);
check_int_equal (ctx.fork, 0);
if (check_non_null (sctx = ctx.sources))
Expand All @@ -158,6 +152,7 @@ main (int argc, char **argv)
}
}

#ifdef NOTYET
check_int_equal (parse_cf_string ("1.2.3.4/30: localhost/1234", &ctx), 0);
check_int_equal (ctx.fork, 0);
if (check_non_null (sctx = ctx.sources))
Expand All @@ -166,6 +161,7 @@ main (int argc, char **argv)
check_int_equal (sctx->nreceivers, 1);
check_receiver (&sctx->receivers[0], "127.0.0.1", 1234, AF_INET, 1, DEFAULT_TTL);
}
#endif

check_int_equal (parse_cf_string ("1.2.3.4/30: ip6-localhost/1234", &ctx), 0);
check_int_equal (ctx.fork, 0);
Expand Down Expand Up @@ -209,6 +205,7 @@ main (int argc, char **argv)
check_receiver (&sctx->receivers[0], "2001:db8:0::1", 2000, AF_INET6, 1, DEFAULT_TTL);
check_null (sctx->next);
}
#ifdef NOTYET
#endif
return 0;
}
Expand Down
10 changes: 8 additions & 2 deletions rawsend.c
Expand Up @@ -184,10 +184,16 @@ raw_send_from_to (s, msg, msglen, saddr_generic, daddr_generic, ttl, flags)
#undef daddr

extern int
make_raw_udp_socket (sockbuflen)
long sockbuflen;
make_raw_udp_socket (sockbuflen, af)
size_t sockbuflen;
int af;
{
int s;
if (af == AF_INET6)
{
fprintf (stderr, "Spoofing not supported for IPv6\n");
return -1;
}
if ((s = socket (PF_INET, SOCK_RAW, IPPROTO_RAW)) == -1)
return s;
if (sockbuflen != -1)
Expand Down
2 changes: 1 addition & 1 deletion rawsend.h
Expand Up @@ -9,7 +9,7 @@

#define RAWSEND_COMPUTE_UDP_CHECKSUM 0x0001

extern int make_raw_udp_socket (long);
extern int make_raw_udp_socket (size_t, int);
extern int raw_send_from_to (int,
const void *, size_t,
struct sockaddr *,
Expand Down
2 changes: 1 addition & 1 deletion rawtest.c
Expand Up @@ -24,7 +24,7 @@ main (int argc, char **argv)
{
int s;

if ((s = make_raw_udp_socket (0)) == -1)
if ((s = make_raw_udp_socket (0, AF_INET)) == -1)
{
fprintf (stderr, "socket: %s\n",
strerror (errno));
Expand Down

0 comments on commit 294f34b

Please sign in to comment.