#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <stdio.h>
#include <stdlib.h>
|
int | main (int argc, char *argv[]) |
|
int main |
( |
int |
argc, |
|
|
char * |
argv[] |
|
) |
| |
47 sd = socket(AF_INET, SOCK_DGRAM, 0);
50 perror(
"Opening datagram socket error");
54 printf(
"Opening datagram socket....OK.\n");
60 if(setsockopt(
sd, SOL_SOCKET, SO_REUSEADDR, (
char *)&reuse,
sizeof(reuse)) < 0)
62 perror(
"Setting SO_REUSEADDR error");
67 printf(
"Setting SO_REUSEADDR...OK.\n");
78 perror(
"Binding datagram socket error");
83 printf(
"Binding datagram socket...OK.\n");
89 group.imr_multiaddr.s_addr = inet_addr(
"225.1.1.1");
90 group.imr_interface.s_addr = inet_addr(
"127.0.0.1");
91 if(setsockopt(
sd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (
char *)&
group,
sizeof(
group)) < 0)
93 perror(
"Adding multicast group error");
98 printf(
"Adding multicast group...OK.\n");
105 perror(
"Reading datagram message error");
111 printf(
"Reading datagram message...OK.\n");
112 printf(
"The message from multicast server is: \"%s\"\n",
databuf);
116 }
int datalen
Definition: mcastclient.c:41
struct sockaddr_in localSock
Definition: mcastclient.c:38
char databuf[1024]
Definition: mcastclient.c:42
int sd
Definition: mcastclient.c:40
struct ip_mreq group
Definition: mcastclient.c:39
struct sockaddr_in localSock |