Skip to content

Commit

Permalink
Make the Ethernet address configurable.
Browse files Browse the repository at this point in the history
  • Loading branch information
dag-erling committed Nov 21, 2018
1 parent f804eae commit fcd6acd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
5 changes: 4 additions & 1 deletion sbin/flytrap/flytrap.8.in
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd November 14, 2018
.Dd November 21, 2018
.Dt FLYTRAP 8
.Os
.Sh NAME
Expand All @@ -35,6 +35,7 @@
.Sh SYNOPSIS
.Nm
.Op Fl dfnov
.Op Fl e Ar addr
.Op Fl I Ar addr Ns | Ns Ar range Ns | Ns Ar subnet
.Op Fl i Ar addr Ns | Ns Ar range Ns | Ns Ar subnet
.Op Fl p Ar pidfile
Expand All @@ -55,6 +56,8 @@ The following options are available:
.Bl -tag -width Fl
.It Fl d
Enable log messages at debug level or higher.
.It Fl e Ar addr
Use the specified Ethernet address instead of the hardcoded default.
.It Fl f
Foreground mode: do not daemonize and do not create a pidfile.
.It Fl I Ar a.b.c.d Ns | Ns Ar a.b.c.d-e.f.g.h Ns | Ns Ar a.b.c.d/p
Expand Down
22 changes: 20 additions & 2 deletions sbin/flytrap/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,20 @@ exclude_range(ip4s_node **set, const char *range)
return (0);
}

static int
set_ether_addr(const char *addr)
{
ether_addr ea;
const char *e;

if ((e = ether_parse(addr, &ea)) == NULL || *e != '\0')
return (-1);
ft_verbose("ethernet address %02x:%02x:%02x:%02x:%02x:%02x",
ea.o[0], ea.o[1], ea.o[2], ea.o[3], ea.o[4], ea.o[5]);
flytrap_ether_addr = ea;
return (0);
}

static void
daemonize(void)
{
Expand All @@ -117,7 +131,7 @@ usage(void)
{

fprintf(stderr, "usage: "
"flytrap [-dfnov] [-p pidfile] [-t csvfile] "
"flytrap [-dfnov] [-p pidfile] [-t csvfile] [-e addr] "
"[-Ii addr|range|subnet] [-Xx addr|range|subnet] "
"iface\n");
exit(1);
Expand All @@ -132,7 +146,7 @@ main(int argc, char *argv[])
ifname = NULL;
ft_log_level = FT_LOG_LEVEL_NOTICE;
ft_log_init("flytrap", NULL);
while ((opt = getopt(argc, argv, "dfhI:i:nop:t:vX:x:")) != -1) {
while ((opt = getopt(argc, argv, "de:fhI:i:nop:t:vX:x:")) != -1) {
switch (opt) {
case 'd':
if (ft_log_level > FT_LOG_LEVEL_DEBUG)
Expand All @@ -145,6 +159,10 @@ main(int argc, char *argv[])
if (include_range(&src_set, optarg) != 0)
usage();
break;
case 'e':
if (set_ether_addr(optarg) != 0)
usage();
break;
case 'i':
if (include_range(&dst_set, optarg) != 0)
usage();
Expand Down

0 comments on commit fcd6acd

Please sign in to comment.