Skip to content

Instantly share code, notes, and snippets.

uint32_t get_lower_32_bits(uint64_t i)
{
return (uint32_t) i;
}
uint32_t get_higher_32_bits(uint64_t i)
{
return (uint32_t) (i >> 32);
}
@pmichna
pmichna / broadcast.c
Last active December 18, 2015 10:39
How to do broadcast with UDP in UNIX.
struct sockaddr_in s;
int fd_socket = socket(PF_INET, SOCK_DGRAM, 0);
int bcastEnable = 1;
int32_t data = 1;
if (fd_socket < 0)
perror("socket");
if(setsockopt(fd_socket, SOL_SOCKET, SO_BROADCAST, &bcastEnable, sizeof(bcastEnable)))
perror("setsockopt");
memset(&s, 0, sizeof(struct sockaddr_in));