Skip to content

Instantly share code, notes, and snippets.

@orleika
Created April 20, 2018 01:57
Show Gist options
  • Save orleika/ba479722a4e5441fdf388f0f7cdc8e79 to your computer and use it in GitHub Desktop.
Save orleika/ba479722a4e5441fdf388f0f7cdc8e79 to your computer and use it in GitHub Desktop.
some description
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct in_addr localInterface;
struct sockaddr_in groupSock;
int sd;
char buf[2048];
int main (int argc, char *argv[])
{
fgets(buf, sizeof(buf), stdin);
sd = socket(AF_INET, SOCK_DGRAM, 0);
if(sd < 0) {
exit(1);
}
memset((char *) &groupSock, 0, sizeof(groupSock));
groupSock.sin_family = AF_INET;
groupSock.sin_addr.s_addr = inet_addr("224.0.0.1");
groupSock.sin_port = htons(atoi(argv[1]));
localInterface.s_addr = inet_addr("127.0.0.1");
if(setsockopt(sd, IPPROTO_IP, IP_MULTICAST_IF, (char *)&localInterface, sizeof(localInterface)) < 0) {
exit(1);
}
if(sendto(sd, buf, sizeof(buf), 0, (struct sockaddr*)&groupSock, sizeof(groupSock)) < 0) {
exit(1);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment