Initial commit of files
This commit is contained in:
40
src/libnet/udp_broadcast.c
Normal file
40
src/libnet/udp_broadcast.c
Normal file
@ -0,0 +1,40 @@
|
||||
//
|
||||
// Neal Probert
|
||||
//
|
||||
|
||||
#include "netlib.h"
|
||||
|
||||
int udp_broadcast( const char *host, const char *service, struct sockaddr_storage *sa, socklen_t *len )
|
||||
{
|
||||
/* socket stuff */
|
||||
int sock, family; /* tcp socket */
|
||||
|
||||
if ( !host )
|
||||
host = "255.255.255.255";
|
||||
|
||||
// host
|
||||
family = ip_host2addr( host, service, sa, len );
|
||||
|
||||
if ( family != AF_INET )
|
||||
{
|
||||
log_error(host);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* plug me into a socket */
|
||||
if ( (sock = socket( family, SOCK_DGRAM, 0)) < 0 )
|
||||
{
|
||||
log_error("dgram_socket");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// ipv4 uses classic broadcast
|
||||
u_int i = 1;
|
||||
if ( setsockopt(sock, SOL_SOCKET, SO_BROADCAST, &i, sizeof(i)) != 0 )
|
||||
{
|
||||
log_error("so_broadcast");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return sock;
|
||||
}
|
||||
Reference in New Issue
Block a user