net-mgmt/mac-telnet: Update to 0.6.3

* Add support for /etc/ethers lookup
* Prevent socket conflicts with other MNDP listeners
* Move mactelnetd man page to section 8
This commit is contained in:
Joe Marcus Clarke
2025-09-22 09:56:53 -04:00
parent 3089b9d626
commit eb3bddcd99
9 changed files with 5 additions and 243 deletions
+1 -2
View File
@@ -1,6 +1,5 @@
PORTNAME= mac-telnet
PORTVERSION= 0.6.1
PORTREVISION= 2
PORTVERSION= 0.6.3
PORTEPOCH= 1
CATEGORIES= net-mgmt net
+3 -3
View File
@@ -1,3 +1,3 @@
TIMESTAMP = 1723560182
SHA256 (haakonnessjoen-MAC-Telnet-0.6.1-v0.6.1_GH0.tar.gz) = c6e2760d62bba643e9ac93b6e5664d109e42666cf8a1de7a9518eec191cfbb34
SIZE (haakonnessjoen-MAC-Telnet-0.6.1-v0.6.1_GH0.tar.gz) = 80328
TIMESTAMP = 1758544583
SHA256 (haakonnessjoen-MAC-Telnet-0.6.3-v0.6.3_GH0.tar.gz) = 1b685568bddfe8d41cf70242a8db98968154334647b2c98c389596604e3fc38a
SIZE (haakonnessjoen-MAC-Telnet-0.6.3-v0.6.3_GH0.tar.gz) = 81507
@@ -1,40 +0,0 @@
--- src/interfaces.c.orig 2024-08-15 15:58:48 UTC
+++ src/interfaces.c
@@ -150,6 +150,9 @@ int net_get_interfaces(struct net_interface **interfac
static const struct ifaddrs *ifaddrsp;
const struct sockaddr_in *dl_addr;
int found = 0;
+#if !defined(__FreeBSD__)
+ long allones_bcast = htonl(INADDR_BROADCAST);
+#endif
if (getifaddrs(&int_addrs) < 0) {
perror("getifaddrs");
@@ -173,8 +176,14 @@ int net_get_interfaces(struct net_interface **interfac
if (ifaddrsp->ifa_addr->sa_family == AF_INET) {
memcpy(interface->ipv4_addr, &dl_addr->sin_addr, IPV4_ALEN);
+#if defined(__FreeBSD__)
+ memcpy(interface->bcast_addr, &((const struct sockaddr_in *)ifaddrsp->ifa_broadaddr)->sin_addr, IPV4_ALEN);
+#else
+ memcpy(interface->bcast_addr, &allones_bcast, IPV4_ALEN);
+#endif
} else {
memset(interface->ipv4_addr, 0, IPV4_ALEN);
+ memset(interface->bcast_addr, 0, IPV4_ALEN);
}
}
#ifdef __linux__
@@ -208,9 +217,12 @@ int net_get_interfaces(struct net_interface **interfac
DL_FOREACH(*interfaces, interface) {
struct in_addr *addr =
(struct in_addr *)interface->ipv4_addr;
+ struct in_addr *bcast =
+ (struct in_addr *)interface->bcast_addr;
printf("Interface %s:\n", interface->name);
printf("\tIP: %s\n", inet_ntoa(*addr));
+ printf("\tBCAST: %s\n", inet_ntoa(*bcast));
printf("\tMAC: %s\n",
ether_ntoa((struct ether_addr *)interface->mac_addr));
#ifdef __linux__
@@ -1,17 +0,0 @@
--- src/interfaces.h.orig 2024-08-15 16:06:02 UTC
+++ src/interfaces.h
@@ -25,6 +25,7 @@ struct net_interface {
char name[256];
unsigned char ipv4_addr[IPV4_ALEN];
unsigned char mac_addr[ETH_ALEN];
+ unsigned char bcast_addr[IPV4_ALEN];
/* used by mactelnetd */
int socketfd;
@@ -57,4 +58,4 @@ extern int net_send_udp(const int socket, struct net_i
const unsigned char *destmac, const struct in_addr *sourceip, const int sourceport,
const struct in_addr *destip, const int destport, const unsigned char *data, const int datalen);
extern unsigned short in_cksum(unsigned short *addr, int len);
-#endif
\ No newline at end of file
+#endif
@@ -1,46 +0,0 @@
--- src/mactelnet.c.orig 2024-08-12 21:08:19 UTC
+++ src/mactelnet.c
@@ -37,6 +37,7 @@
#endif
#if defined(__FreeBSD__) || defined(__APPLE__)
#include <sys/types.h>
+#include <sys/mman.h>
#include <net/ethernet.h>
#else
#include <netinet/ether.h>
@@ -126,6 +127,8 @@ static unsigned int send_socket;
static unsigned int send_socket;
+static unsigned char *bcast_addr;
+
static int handle_packet(unsigned char *data, int data_len);
static void print_version() {
@@ -168,7 +171,7 @@ static int send_udp(struct mt_packet *packet, int retr
struct sockaddr_in socket_address;
socket_address.sin_family = AF_INET;
socket_address.sin_port = htons(MT_MACTELNET_PORT);
- socket_address.sin_addr.s_addr = htonl(INADDR_BROADCAST);
+ memcpy(&(socket_address.sin_addr), bcast_addr, IPV4_ALEN);
sent_bytes = sendto(send_socket, packet->data, packet->size, 0, (struct sockaddr *)&socket_address,
sizeof(socket_address));
@@ -470,6 +473,9 @@ static int find_interface() {
continue;
}
+#if defined(__FreeBSD__)
+ setsockopt(testsocket, IPPROTO_IP, IP_ONESBCAST, &optval, sizeof(optval));
+#endif
setsockopt(testsocket, SOL_SOCKET, SO_BROADCAST, &optval, sizeof(optval));
setsockopt(testsocket, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval));
@@ -488,6 +494,7 @@ static int find_interface() {
send_socket = testsocket;
memcpy(srcmac, interface->mac_addr, ETH_ALEN);
active_interface = interface;
+ bcast_addr = interface->bcast_addr;
/* Send a SESSIONSTART message with the current device */
init_packet(&data, MT_PTYPE_SESSIONSTART, srcmac, dstmac, sessionkey, 0);
@@ -1,33 +0,0 @@
--- src/mactelnetd.c.orig 2024-08-15 17:08:22 UTC
+++ src/mactelnetd.c
@@ -254,6 +254,12 @@ static void setup_sockets() {
perror("SO_BROADCAST");
continue;
}
+#if defined(__FreeBSD__)
+ if (setsockopt(interface->socketfd, IPPROTO_IP, IP_ONESBCAST, &optval, sizeof(optval)) == -1) {
+ perror("IP_ONESBCAST");
+ continue;
+ }
+#endif
setsockopt(interface->socketfd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval));
@@ -290,7 +296,7 @@ static int send_udp(const struct mt_connection *conn,
struct sockaddr_in socket_address;
socket_address.sin_family = AF_INET;
socket_address.sin_port = htons(conn->srcport);
- socket_address.sin_addr.s_addr = htonl(INADDR_BROADCAST);
+ memcpy(&(socket_address.sin_addr), &conn->interface->bcast_addr, IPV4_ALEN);
return sendto(conn->interface->socketfd, packet->data, packet->size, 0, (struct sockaddr *)&socket_address,
sizeof(socket_address));
@@ -315,7 +321,7 @@ static int send_special_udp(struct net_interface *inte
struct sockaddr_in socket_address;
socket_address.sin_family = AF_INET;
socket_address.sin_port = htons(port);
- socket_address.sin_addr.s_addr = htonl(INADDR_BROADCAST);
+ memcpy(&(socket_address.sin_addr), &interface->bcast_addr, IPV4_ALEN);
return sendto(interface->socketfd, packet->data, packet->size, 0, (struct sockaddr *)&socket_address,
sizeof(socket_address));
@@ -1,11 +0,0 @@
--- src/mtwei.c.orig 2024-09-24 12:56:03 UTC
+++ src/mtwei.c
@@ -36,7 +36,7 @@
#include <stdio.h>
#include <string.h>
#include <libintl.h>
-#if defined(__linux__)
+#if defined(HAVE_SYS_RANDOM_H)
#include <sys/random.h>
#endif
@@ -1,90 +0,0 @@
--- src/users.c.orig 2024-08-15 14:34:02 UTC
+++ src/users.c
@@ -211,6 +211,24 @@ struct mt_credentials *find_user(char *username) {
return NULL;
}
+#if OPENSSL_VERSION_NUMBER < 0x030000000 // less than 3.0.0
+/*
+ * Filter out colons from the decoded string.
+ * By default, the OPENSSL_buf2hexstr function in OpenSSL 1.1
+ * uses colons as a byte separator, and this cannot be overridden.
+ */
+static void remove_colons(char *s) {
+ const char *p = s;
+ char *q = s;
+ while (*p != '\0') {
+ *q = *p++;
+ q += (*q != ':');
+ }
+
+ *q = '\0';
+}
+#endif
+
int add_user(const char *username, const char *password) {
FILE *rfile;
FILE *wfile;
@@ -289,12 +307,27 @@ int add_user(const char *username, const char *passwor
continue;
}
fprintf(wfile, "%s:", username);
+#if OPENSSL_VERSION_NUMBER < 0x030000000 // less than 3.0.0
+ char *output;
+ output = OPENSSL_buf2hexstr(newhash, MT_CRED_HASHLEN);
+ remove_colons(output);
+#else
char output[MT_CRED_HASHLEN * 2 + 1];
OPENSSL_buf2hexstr_ex(output, sizeof(output), NULL, newhash, MT_CRED_HASHLEN, '\0');
+#endif
fputs(output, wfile);
fputs(":", wfile);
+#if OPENSSL_VERSION_NUMBER < 0x030000000 // less than 3.0.0
+ OPENSSL_free(output);
+ output = OPENSSL_buf2hexstr(newsalt, MT_CRED_SALTLEN);
+ remove_colons(output);
+#else
OPENSSL_buf2hexstr_ex(output, sizeof(output), NULL, newsalt, MT_CRED_SALTLEN, '\0');
+#endif
fputs(output, wfile);
+#if OPENSSL_VERSION_NUMBER < 0x030000000 // less than 3.0.0
+ OPENSSL_free(output);
+#endif
fputs("\n", wfile);
found = 1;
} else {
@@ -306,12 +339,27 @@ int add_user(const char *username, const char *passwor
if (!found && password != NULL) {
// Write username, salt, and hashed password to the file
fprintf(wfile, "%s:", username);
+#if OPENSSL_VERSION_NUMBER < 0x030000000 // less than 3.0.0
+ char *output;
+ output = OPENSSL_buf2hexstr(newhash, MT_CRED_HASHLEN);
+ remove_colons(output);
+#else
char output[MT_CRED_HASHLEN * 2 + 1];
OPENSSL_buf2hexstr_ex(output, sizeof(output), NULL, newhash, MT_CRED_HASHLEN, '\0');
+#endif
fputs(output, wfile);
fputs(":", wfile);
+#if OPENSSL_VERSION_NUMBER < 0x030000000 // less than 3.0.0
+ OPENSSL_free(output);
+ output = OPENSSL_buf2hexstr(newsalt, MT_CRED_SALTLEN);
+ remove_colons(output);
+#else
OPENSSL_buf2hexstr_ex(output, sizeof(output), NULL, newsalt, MT_CRED_SALTLEN, '\0');
+#endif
fputs(output, wfile);
+#if OPENSSL_VERSION_NUMBER < 0x030000000 // less than 3.0.0
+ OPENSSL_free(output);
+#endif
fputs("\n", wfile);
}
@@ -327,4 +375,4 @@ int add_user(const char *username, const char *passwor
}
return found ? 2 : 1;
-}
\ No newline at end of file
+}
+1 -1
View File
@@ -7,5 +7,5 @@ share/locale/bg/LC_MESSAGES/mactelnet.mo
share/locale/nb/LC_MESSAGES/mactelnet.mo
share/man/man1/macping.1.gz
share/man/man1/mactelnet.1.gz
share/man/man1/mactelnetd.1.gz
share/man/man1/mndp.1.gz
share/man/man8/mactelnetd.8.gz