1 /* -*- c-basic-offset: 8; -*-
3 * Copyright (c) 1993 W. Richard Stevens. All rights reserved.
4 * Permission to use or modify this software and its documentation only for
5 * educational purposes and without fee is hereby granted, provided that
6 * the above copyright notice appear in all copies. The author makes no
7 * representations about the suitability of this software for any purpose.
8 * It is provided "as is" without express or implied warranty.
14 join_mcast(int fd
, struct sockaddr_in
*sin
)
16 #ifdef IP_ADD_MEMBERSHIP /* only include if host supports mcasting */
20 inaddr
= sin
->sin_addr
.s_addr
;
21 if (IN_MULTICAST(inaddr
) == 0)
22 return; /* not a multicast address */
24 mreq
.imr_multiaddr
.s_addr
= inaddr
;
25 mreq
.imr_interface
.s_addr
= htonl(INADDR_ANY
); /* need way to change */
26 if (setsockopt(fd
, IPPROTO_IP
, IP_ADD_MEMBERSHIP
, &mreq
,
28 err_sys("IP_ADD_MEMBERSHIP error");
31 fprintf(stderr
, "multicast group joined\n");
32 #endif /* IP_ADD_MEMBERSHIP */