New port: net/macchanger

GNU MAC Changer is an utility that makes the maniputation of MAC addresses of
network interfaces easier.

WWW: http://www.gnu.org/software/macchanger

PR:		187363
Submitted by:	clutton@zoho.com
This commit is contained in:
Kurt Jaeger 2014-10-22 05:34:34 +00:00
parent 0075956658
commit 353cd6a22a
Notes: svn2git 2021-03-31 03:12:20 +00:00
svn path=/head/; revision=371342
6 changed files with 371 additions and 0 deletions

26
net/macchanger/Makefile Normal file
View file

@ -0,0 +1,26 @@
# $FreeBSD$
PORTNAME= macchanger
PORTVERSION= 1.7.0
CATEGORIES= net
MAINTAINER= clutton@zoho.com
COMMENT= GNU MAC Changer
LICENSE= GPLv3
USE_GITHUB= true
GH_ACCOUNT= alobbs
GH_COMMIT= f4f66e1
GNU_CONFIGURE= yes
USE_AUTOTOOLS= aclocal autoconf automake autoheader
AUTOMAKE_ARGS= --add-missing
INFO= macchanger
PLIST_FILES= bin/${PORTNAME} man/man1/${PORTNAME}.1.gz \
%%DATADIR%%/OUI.list %%DATADIR%%/wireless.list
PLIST_DIRS= %%DATADIR%%
.include <bsd.port.mk>

2
net/macchanger/distinfo Normal file
View file

@ -0,0 +1,2 @@
SHA256 (macchanger-1.7.0.tar.gz) = ec916fa592c445c4c48d420ae0ad5adb942b0a6009d96394d0555fcb967965aa
SIZE (macchanger-1.7.0.tar.gz) = 306369

View file

@ -0,0 +1,49 @@
--- configure.ac 2014-01-01 18:57:39.000000000 +0200
+++ configure.ac 2014-03-19 02:43:40.440612214 +0200
@@ -9,6 +9,46 @@
AC_PROG_INSTALL
AC_PROG_CC
+AC_CANONICAL_HOST
+
+case "$host" in
+*-*-linux*)
+ AC_DEFINE([LLADDR(s)], [s->sll_addr], [the link level address])
+;;
+*-*-freebsd*)
+ AC_DEFINE([sockaddr_ll], [sockaddr_dl], [the socket link structures])
+ AC_DEFINE([sll_family], [sdl_family], [the socket family member])
+ AC_DEFINE([AF_PACKET], [AF_LINK], [the domain name])
+ AC_DEFINE([ifr_hwaddr], [ifr_addr], [the address member])
+ AC_DEFINE([SIOCSIFHWADDR], [SIOCSIFLLADDR], [the ioctl call])
+;;
+esac
+
+AC_MSG_CHECKING([if sockaddr has the sa_len member])
+AC_LINK_IFELSE(
+ [AC_LANG_PROGRAM(
+ [[ #include <sys/socket.h> ]],
+ [[ struct sockaddr sock; return (sock.sa_len); ]])],
+ [AC_DEFINE([HAVE_SOCKADDR_SA_LEN], [1],
+ [socket address structures have length fields])
+])
+
+AC_CHECK_HEADER([ifaddrs.h], ,[AC_MSG_ERROR(
+ [*** ifaddrs.h missing - please install first or check config.log ***])])
+
+AC_CHECK_HEADERS([linux/if_packet.h net/if_dl.h])
+
+if test "x$ac_cv_header_linux_if_packet_h" = "xyes" ; then
+ AC_DEFINE([HAVE_IF_PACKET], [1],
+ [The Linux if_packet.h header found])
+elif test "x$ac_cv_header_net_if_dl_h" = "xyes" ; then
+ AC_DEFINE([HAVE_IF_DL], [1],
+ [The BSD if_dl.h header found])
+else
+ AC_MSG_ERROR([*** sockaddr_* missing - please install first or check config.log ***])
+fi
+
+AC_CHECK_HEADER(linux/ethtool.h, AC_DEFINE([HAVE_ETHTOOL], [1], [Linux ethernet headers found]), )
AC_OUTPUT([
Makefile

View file

@ -0,0 +1,166 @@
--- src/main.c 2014-01-01 11:23:39.000000000 +0200
+++ src/main.c 2014-10-17 12:15:02.254848839 +0300
@@ -40,9 +40,6 @@
#include "maclist.h"
#include "netinfo.h"
-#define EXIT_OK 0
-#define EXIT_ERROR 1
-
static void
print_help (void)
{
@@ -54,7 +51,9 @@
" -e, --ending Don't change the vendor bytes\n"
" -a, --another Set random vendor MAC of the same kind\n"
" -A Set random vendor MAC of any kind\n"
+#if defined(HAVE_ETHTOOL)
" -p, --permanent Reset to original, permanent hardware MAC\n"
+#endif
" -r, --random Set fully random MAC\n"
" -l, --list[=keyword] Print known vendors\n"
" -b, --bia Pretend to be a burned-in-address\n"
@@ -116,7 +115,9 @@
char ending = 0;
char another_any = 0;
char another_same = 0;
+#if defined(HAVE_ETHTOOL)
char permanent = 0;
+#endif
char print_list = 0;
char show = 0;
char set_bia = 0;
@@ -131,7 +132,9 @@
{"ending", no_argument, NULL, 'e'},
{"endding", no_argument, NULL, 'e'}, /* kept for backwards compatibility */
{"another", no_argument, NULL, 'a'},
+#if defined(HAVE_ETHTOOL)
{"permanent", no_argument, NULL, 'p'},
+#endif
{"show", no_argument, NULL, 's'},
{"another_any", no_argument, NULL, 'A'},
{"bia", no_argument, NULL, 'b'},
@@ -142,7 +145,9 @@
net_info_t *net;
mac_t *mac;
+#if defined(HAVE_ETHTOOL)
mac_t *mac_permanent;
+#endif
mac_t *mac_faked;
char *device_name;
int val;
@@ -158,7 +163,7 @@
"This is free software; see the source for copying conditions. There is NO\n"
"warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n",
VERSION);
- exit (EXIT_OK);
+ exit (EXIT_SUCCESS);
break;
case 'l':
print_list = 1;
@@ -182,9 +187,11 @@
case 'A':
another_any = 1;
break;
+#if defined(HAVE_ETHTOOL)
case 'p':
permanent = 1;
break;
+#endif
case 'm':
set_mac = optarg;
break;
@@ -192,26 +199,26 @@
case '?':
default:
print_help();
- exit (EXIT_OK);
+ exit (EXIT_SUCCESS);
break;
}
}
/* Read the MAC lists */
if (mc_maclist_init() < 0) {
- exit (EXIT_ERROR);
+ exit (EXIT_FAILURE);
}
/* Print list? */
if (print_list) {
mc_maclist_print(search_word);
- exit (EXIT_OK);
+ exit (EXIT_SUCCESS);
}
/* Get device name argument */
if (optind >= argc) {
print_usage();
- exit (EXIT_OK);
+ exit (EXIT_SUCCESS);
}
device_name = argv[optind];
@@ -220,10 +227,12 @@
/* Read the MAC */
if ((net = mc_net_info_new(device_name)) == NULL) {
- exit (EXIT_ERROR);
+ exit (EXIT_FAILURE);
}
mac = mc_net_info_get_mac(net);
+#if defined(HAVE_ETHTOOL)
mac_permanent = mc_net_info_get_permanent_mac(net);
+#endif
/* --bia can only be used with --random */
if (set_bia && !random) {
@@ -232,16 +241,18 @@
/* Print the current MAC info */
print_mac ("Current MAC: ", mac);
+#if defined(HAVE_ETHTOOL)
print_mac ("Permanent MAC: ", mac_permanent);
+#endif
/* Change the MAC */
mac_faked = mc_mac_dup (mac);
if (show) {
- exit (EXIT_OK);
+ exit (EXIT_SUCCESS);
} else if (set_mac) {
if (mc_mac_read_string (mac_faked, set_mac) < 0) {
- exit (EXIT_ERROR);
+ exit (EXIT_FAILURE);
}
} else if (random) {
mc_mac_random (mac_faked, 6, set_bia);
@@ -254,10 +265,12 @@
} else if (another_any) {
mc_maclist_set_random_vendor(mac_faked, mac_is_anykind);
mc_mac_random (mac_faked, 3, 1);
+#if defined(HAVE_ETHTOOL)
} else if (permanent) {
mac_faked = mc_mac_dup (mac_permanent);
+#endif
} else {
- exit (EXIT_OK); /* default to show */
+ exit (EXIT_SUCCESS); /* default to show */
}
/* Set the new MAC */
@@ -279,9 +292,11 @@
/* Memory free */
mc_mac_free (mac);
mc_mac_free (mac_faked);
+#if defined(HAVE_ETHTOOL)
mc_mac_free (mac_permanent);
+#endif
mc_net_info_free (net);
mc_maclist_free();
- return (ret == 0) ? EXIT_OK : EXIT_ERROR;
+ return (ret == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
}

View file

@ -0,0 +1,124 @@
--- src/netinfo.c 2014-01-01 19:10:25.000000000 +0200
+++ src/netinfo.c 2014-10-22 05:49:50.129320393 +0300
@@ -23,14 +23,31 @@
* USA
*/
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <sys/socket.h>
#include <sys/ioctl.h>
-#include <linux/ethtool.h>
-#include <linux/sockios.h>
+#include <net/if.h>
+#include <ifaddrs.h>
+#include <net/ethernet.h>
+
+#if defined(HAVE_IF_PACKET)
+# include <linux/if_packet.h>
+#elif defined(HAVE_IF_DL)
+# include <net/if_dl.h>
+#endif
+
+#if defined(HAVE_ETHTOOL)
+# include <linux/ethtool.h>
+# include <linux/sockios.h>
+#endif
#include "netinfo.h"
@@ -49,7 +66,7 @@
strncpy (new->dev.ifr_name, device, sizeof(new->dev.ifr_name));
new->dev.ifr_name[sizeof(new->dev.ifr_name)-1] = '\0';
- if (ioctl(new->sock, SIOCGIFHWADDR, &new->dev) < 0) {
+ if (if_nametoindex(device) == 0) {
perror ("[ERROR] Set device name");
free(new);
return NULL;
@@ -66,29 +83,55 @@
free(net);
}
-
mac_t *
mc_net_info_get_mac (const net_info_t *net)
{
- int i;
- mac_t *new = (mac_t *) malloc (sizeof(mac_t));
+ int i;
+ mac_t *mac = (mac_t *) malloc (sizeof(mac_t));
+ u_char *lladr;
- for (i=0; i<6; i++) {
- new->byte[i] = net->dev.ifr_hwaddr.sa_data[i] & 0xFF;
- }
+ struct ifaddrs *ifap, *ifa;
+ struct sockaddr_ll *sdl;
- return new;
-}
+ if (getifaddrs(&ifap) == 0) {
+ for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
+
+ sdl = (struct sockaddr_ll *) ifa->ifa_addr;
+
+ if (strcmp(ifa->ifa_name, net->dev.ifr_name) != 0)
+ continue;
+ if (!sdl && sdl->sll_family != AF_PACKET)
+ continue;
+
+ lladr = (u_char *) LLADDR(sdl);
+ for (i=0; i<6; i++)
+ mac->byte[i] = lladr[i] & 0xFF;
+ break;
+ }
+ freeifaddrs(ifap);
+ } else
+ perror("getifaddrs");
+
+ return mac;
+}
int
mc_net_info_set_mac (net_info_t *net, const mac_t *mac)
{
int i;
+#if defined(HAVE_ETHTOOL)
+ if (ioctl(net->sock, SIOCGIFHWADDR, &net->dev) < 0) {
+ perror ("[ERROR] Set ifreq structure");
+ return -1;
+ }
+#elif defined(HAVE_SOCKADDR_SA_LEN)
+ net->dev.ifr_addr.sa_family = AF_PACKET;
+ net->dev.ifr_addr.sa_len = ETHER_ADDR_LEN;
+#endif
- for (i=0; i<6; i++) {
+ for (i=0; i<6; i++)
net->dev.ifr_hwaddr.sa_data[i] = mac->byte[i];
- }
if (ioctl(net->sock, SIOCSIFHWADDR, &net->dev) < 0) {
perror ("[ERROR] Could not change MAC: interface up or insufficient permissions");
@@ -98,6 +141,7 @@
return 0;
}
+#if defined(HAVE_ETHTOOL)
mac_t *
mc_net_info_get_permanent_mac (const net_info_t *net)
{
@@ -126,3 +170,4 @@
free(epa);
return newmac;
}
+#endif

4
net/macchanger/pkg-descr Normal file
View file

@ -0,0 +1,4 @@
GNU MAC Changer is an utility that makes the maniputation of MAC addresses of
network interfaces easier.
WWW: http://www.gnu.org/software/macchanger