2bae9358d7
FossilOrigin-Name: c53d95729c009f8f80a7d63847cef7668ff73f8af0523ab65f7734696f85399c
32 lines
565 B
C
32 lines
565 B
C
#include <string.h>
|
|
|
|
#include <sys/types.h>
|
|
#include <sys/socket.h>
|
|
#include <ifaddrs.h>
|
|
|
|
#include "sock.h"
|
|
|
|
|
|
|
|
int sock_getbroadcastaddr(const struct sockaddr * addr,struct sockaddr * broadcastaddr)
|
|
{
|
|
struct ifaddrs *ifap,*ifa;
|
|
|
|
if ( getifaddrs(&ifap)==-1)
|
|
return 0;
|
|
|
|
int rc=0;
|
|
for (ifa = ifap; ifa != NULL; ifa = ifa->ifa_next) {
|
|
|
|
if (sock_cmpaddr(addr,ifa->ifa_addr,0))
|
|
continue;
|
|
memcpy (broadcastaddr, ifa->ifa_broadaddr, sock_addrlen(ifa->ifa_broadaddr));
|
|
rc=1;
|
|
break;
|
|
}
|
|
freeifaddrs(ifap);
|
|
return rc;
|
|
}
|
|
|
|
|