[lib-client] Disable use_iface() if glibc not used
setsockopt(... SO_BINDTODEVICE ...) does not work on OpenBSD. The only way to force an interface seems to specify its IP address and to use setsockopt(... IPPROTO_IP, IP_MULTICAST_IF ...). See the code of ping (-I option). libowlps-client now builds on OpenBSD!
This commit is contained in:
parent
95b9ea30bf
commit
b3cfa2ea08
|
@ -5,6 +5,8 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <sys/param.h>
|
||||||
|
|
||||||
#define DEBUG
|
#define DEBUG
|
||||||
|
|
||||||
|
|
||||||
|
@ -44,6 +46,7 @@ int owlclient_create_trx_socket(const char *const dest_ip,
|
||||||
/* Selects 'iface' as sending interface for the socket 'sockfd'. */
|
/* Selects 'iface' as sending interface for the socket 'sockfd'. */
|
||||||
void owlclient_use_iface(const int sockfd, const char *const iface)
|
void owlclient_use_iface(const int sockfd, const char *const iface)
|
||||||
{
|
{
|
||||||
|
#ifdef __GLIBC__
|
||||||
if (setsockopt(sockfd, SOL_SOCKET, SO_BINDTODEVICE, iface,
|
if (setsockopt(sockfd, SOL_SOCKET, SO_BINDTODEVICE, iface,
|
||||||
strlen(iface) + 1) == -1)
|
strlen(iface) + 1) == -1)
|
||||||
{
|
{
|
||||||
|
@ -52,6 +55,11 @@ void owlclient_use_iface(const int sockfd, const char *const iface)
|
||||||
perror("") ;
|
perror("") ;
|
||||||
fprintf(stderr, "Sending through the default interface.\n") ;
|
fprintf(stderr, "Sending through the default interface.\n") ;
|
||||||
}
|
}
|
||||||
|
#else // __GLIBC__
|
||||||
|
fprintf(stderr, "Cannot select interface %s to send the packet:"
|
||||||
|
" this option is currently GNU libc-specific.\n"
|
||||||
|
"Sending through the default interface.\n", iface) ;
|
||||||
|
#endif // __GLIBC__
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue