diff options
author | Emanuel Haupt <ehaupt@FreeBSD.org> | 2016-04-10 23:10:49 +0000 |
---|---|---|
committer | Emanuel Haupt <ehaupt@FreeBSD.org> | 2016-04-10 23:10:49 +0000 |
commit | 0c700487931dd8998a7556df48803d20a206f1f5 (patch) | |
tree | 94d541cfbfff95bf49e5dec9b66a45c5406b39da /net | |
parent | 31c19da0b36a022574718ab3af90716bfdf031d4 (diff) | |
download | ports-0c700487931dd8998a7556df48803d20a206f1f5.tar.gz ports-0c700487931dd8998a7556df48803d20a206f1f5.zip |
Fix interface binding & error messages.
PR: 208652
Submitted by: johan
Notes
Notes:
svn path=/head/; revision=412989
Diffstat (limited to 'net')
-rw-r--r-- | net/mdns-repeater/Makefile | 2 | ||||
-rw-r--r-- | net/mdns-repeater/files/patch-mdns-repeater.c | 145 |
2 files changed, 146 insertions, 1 deletions
diff --git a/net/mdns-repeater/Makefile b/net/mdns-repeater/Makefile index 04ae05bf6e4b..b4d06ffc9206 100644 --- a/net/mdns-repeater/Makefile +++ b/net/mdns-repeater/Makefile @@ -3,7 +3,7 @@ PORTNAME= mdns-repeater PORTVERSION= 1.10 -PORTREVISION= 1 +PORTREVISION= 2 CATEGORIES= net dns MASTER_SITES= LOCAL/ehaupt diff --git a/net/mdns-repeater/files/patch-mdns-repeater.c b/net/mdns-repeater/files/patch-mdns-repeater.c new file mode 100644 index 000000000000..5a3d77235296 --- /dev/null +++ b/net/mdns-repeater/files/patch-mdns-repeater.c @@ -0,0 +1,145 @@ +--- mdns-repeater.c.orig 2015-04-03 07:03:21 UTC ++++ mdns-repeater.c +@@ -32,6 +32,7 @@ + #include <netinet/in.h> + #include <arpa/inet.h> + #include <net/if.h> ++#include <errno.h> + + #define PACKAGE "mdns-repeater" + #define MDNS_ADDR "224.0.0.251" +@@ -79,7 +80,7 @@ void log_message(int loglevel, char *fmt + static int create_recv_sock() { + int sd = socket(AF_INET, SOCK_DGRAM, 0); + if (sd < 0) { +- log_message(LOG_ERR, "recv socket(): %m"); ++ log_message(LOG_ERR, "recv socket(): %s", strerror(errno)); + return sd; + } + +@@ -87,7 +88,7 @@ static int create_recv_sock() { + + int on = 1; + if ((r = setsockopt(sd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on))) < 0) { +- log_message(LOG_ERR, "recv setsockopt(SO_REUSEADDR): %m"); ++ log_message(LOG_ERR, "recv setsockopt(SO_REUSEADDR): %s", strerror(errno)); + return r; + } + +@@ -98,18 +99,18 @@ static int create_recv_sock() { + serveraddr.sin_port = htons(MDNS_PORT); + serveraddr.sin_addr.s_addr = htonl(INADDR_ANY); /* receive multicast */ + if ((r = bind(sd, (struct sockaddr *)&serveraddr, sizeof(serveraddr))) < 0) { +- log_message(LOG_ERR, "recv bind(): %m"); ++ log_message(LOG_ERR, "recv bind(): %s", strerror(errno)); + } + + // enable loopback in case someone else needs the data + if ((r = setsockopt(sd, IPPROTO_IP, IP_MULTICAST_LOOP, &on, sizeof(on))) < 0) { +- log_message(LOG_ERR, "recv setsockopt(IP_MULTICAST_LOOP): %m"); ++ log_message(LOG_ERR, "recv setsockopt(IP_MULTICAST_LOOP): %s", strerror(errno)); + return r; + } + + #ifdef IP_PKTINFO + if ((r = setsockopt(sd, SOL_IP, IP_PKTINFO, &on, sizeof(on))) < 0) { +- log_message(LOG_ERR, "recv setsockopt(IP_PKTINFO): %m"); ++ log_message(LOG_ERR, "recv setsockopt(IP_PKTINFO): %s", strerror(errno)); + return r; + } + #endif +@@ -120,7 +121,7 @@ static int create_recv_sock() { + static int create_send_sock(int recv_sockfd, const char *ifname, struct if_sock *sockdata) { + int sd = socket(AF_INET, SOCK_DGRAM, 0); + if (sd < 0) { +- log_message(LOG_ERR, "send socket(): %m"); ++ log_message(LOG_ERR, "send socket(): %s", strerror(errno)); + return sd; + } + +@@ -136,7 +137,7 @@ static int create_send_sock(int recv_soc + + #ifdef SO_BINDTODEVICE + if ((r = setsockopt(sd, SOL_SOCKET, SO_BINDTODEVICE, &ifr, sizeof(struct ifreq))) < 0) { +- log_message(LOG_ERR, "send setsockopt(SO_BINDTODEVICE): %m"); ++ log_message(LOG_ERR, "send setsockopt(SO_BINDTODEVICE): %s", strerror(errno)); + return r; + } + #endif +@@ -156,7 +157,7 @@ static int create_send_sock(int recv_soc + + int on = 1; + if ((r = setsockopt(sd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on))) < 0) { +- log_message(LOG_ERR, "send setsockopt(SO_REUSEADDR): %m"); ++ log_message(LOG_ERR, "send setsockopt(SO_REUSEADDR): %s", strerror(errno)); + return r; + } + +@@ -167,22 +168,28 @@ static int create_send_sock(int recv_soc + serveraddr.sin_port = htons(MDNS_PORT); + serveraddr.sin_addr.s_addr = if_addr->s_addr; + if ((r = bind(sd, (struct sockaddr *)&serveraddr, sizeof(serveraddr))) < 0) { +- log_message(LOG_ERR, "send bind(): %m"); ++ log_message(LOG_ERR, "send bind(): %s", strerror(errno)); + } + ++#if __FreeBSD__ ++ if((r = setsockopt(sd, IPPROTO_IP, IP_MULTICAST_IF, &serveraddr.sin_addr, sizeof(serveraddr.sin_addr))) < 0) { ++ log_message(LOG_ERR, "send ip_multicast_if(): errno %d: %s", errno, strerror(errno)); ++ } ++#endif ++ + // add membership to receiving socket + struct ip_mreq mreq; + memset(&mreq, 0, sizeof(struct ip_mreq)); + mreq.imr_interface.s_addr = if_addr->s_addr; + mreq.imr_multiaddr.s_addr = inet_addr(MDNS_ADDR); + if ((r = setsockopt(recv_sockfd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq))) < 0) { +- log_message(LOG_ERR, "recv setsockopt(IP_ADD_MEMBERSHIP): %m"); ++ log_message(LOG_ERR, "recv setsockopt(IP_ADD_MEMBERSHIP): %s", strerror(errno)); + return r; + } + + // enable loopback in case someone else needs the data + if ((r = setsockopt(sd, IPPROTO_IP, IP_MULTICAST_LOOP, &on, sizeof(on))) < 0) { +- log_message(LOG_ERR, "send setsockopt(IP_MULTICAST_LOOP): %m"); ++ log_message(LOG_ERR, "send setsockopt(IP_MULTICAST_LOOP): %s", strerror(errno)); + return r; + } + +@@ -249,7 +256,7 @@ static void daemonize() { + pid_t running_pid; + pid_t pid = fork(); + if (pid < 0) { +- log_message(LOG_ERR, "fork(): %m"); ++ log_message(LOG_ERR, "fork(): %s", strerror(errno)); + exit(1); + } + +@@ -385,7 +392,7 @@ int main(int argc, char *argv[]) { + + pkt_data = malloc(PACKET_SIZE); + if (pkt_data == NULL) { +- log_message(LOG_ERR, "cannot malloc() packet buffer: %m"); ++ log_message(LOG_ERR, "cannot malloc() packet buffer: %s", strerror(errno)); + r = 1; + goto end_main; + } +@@ -409,7 +416,7 @@ int main(int argc, char *argv[]) { + ssize_t recvsize = recvfrom(server_sockfd, pkt_data, PACKET_SIZE, 0, + (struct sockaddr *) &fromaddr, &sockaddr_size); + if (recvsize < 0) { +- log_message(LOG_ERR, "recv(): %m"); ++ log_message(LOG_ERR, "recv(): %s", strerror(errno)); + } + + int j; +@@ -440,7 +447,7 @@ int main(int argc, char *argv[]) { + ssize_t sentsize = send_packet(socks[j].sockfd, pkt_data, (size_t) recvsize); + if (sentsize != recvsize) { + if (sentsize < 0) +- log_message(LOG_ERR, "send()"); ++ log_message(LOG_ERR, "send(): %s", strerror(errno)); + else + log_message(LOG_ERR, "send_packet size differs: sent=%ld actual=%ld", + recvsize, sentsize); |