C.14. Joining the Multicast Group

 /********************************************************* NAME : open_sock *********************************************************/ static int open_sock( vrrp_rt *vsrv ) { struct ip_mreq req; int ret; /* open the socket */ vsrv->sockfd = socket( AF_INET, SOCK_RAW, IPPROTO_VRRP ); if( vsrv->sockfd < 0 ){ int err = errno; VRRP_LOG(("cant open raw socket. errno=%d. (try to run it as root)\n" , err)); return -1; } /* join the multicast group */ memset( &req, 0, sizeof (req)); req.imr_multiaddr.s_addr = htonl(INADDR_VRRP_GROUP); req.imr_interface.s_addr = htonl(vsrv->vif.ipaddr); ret = setsockopt (vsrv->sockfd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *) &req, sizeof (struct ip_mreq)); if( ret < 0 ){ int err = errno; ...

Get VRRP: Increasing Reliability and Failover with the Virtual Router Redundance Protocol now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.