Allow for binding to a link-local IPv6 address

Requires to also give the interface like ipv6%interface
This commit is contained in:
Sven Geuer 2023-12-16 23:37:36 +01:00
parent 3c3b5b0858
commit c9503273a7
3 changed files with 33 additions and 2 deletions

View file

@ -29,6 +29,7 @@
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <net/if.h>
#include <netdb.h>
#include <signal.h>
#include <syslog.h>
@ -189,6 +190,15 @@ void do_daemon()
sa_serv.sin6_addr = in6addr_any;
sa_serv.sin6_port = htons( args_info.standalone_port );
/* In case a standalone interface was specified ... */
if ( args_info.standalone_iface_given ) {
/* ... try to get and set the interface's index */
if ( !(sa_serv.sin6_scope_id = if_nametoindex(args_info.standalone_iface)) ) {
my_perror("Setting server socket interface failed, possibly mis-spelled");
exit(1);
}
}
/* In case a standalone address was specified ... */
if ( args_info.standalone_addr_given ) {
/* ... try to set it as an IPv6 address ... */