/*
 * Simple broadcaster
 * (c)2013 JBY
 */
#include <stdio.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <strings.h>
#include <unistd.h>
#include <stdlib.h>

int main(int argc,char *argv[]) {
  int s, r;
  struct sockaddr_in sin;
  char *msg="Quoi de neuf ?";

  s = socket(AF_INET,SOCK_DGRAM,0);
  if (s==-1) {
    perror("socket");
    exit(EXIT_FAILURE);
  }
  bzero(&sin,sizeof(sin));
  sin.sin_family = PF_INET;
  sin.sin_port = htons(60123);
  sin.sin_addr.s_addr = inet_addr("255.255.255.255");//INADDR_BROADCAST
  int e = 1;
  r = setsockopt(s,SOL_SOCKET,SO_BROADCAST,&e,sizeof(e));
  if (r==-1) {
    perror("setsockopt");
    close(s);
    exit(EXIT_FAILURE);
  }
  r = sendto(s,msg,strlen(msg),0,(struct sockaddr *)&sin,sizeof(sin));
  if (r==-1) {
    perror("sendto");
  }
  close(s);
  exit(r==-1?EXIT_FAILURE:EXIT_SUCCESS);
}