C.8. Configuring a List of IP Addresses for a Virtual Router

/*********************************************************
 NAME : cfg_add_ipaddr
*********************************************************/
static void cfg_add_ipaddr( vrrp_rt *vsrv, uint32_t ipaddr )
{
   vsrv->naddr++;
   /* alloc the room */
   if( vsrv->vaddr ){
         vsrv->vaddr = realloc( vsrv->vaddr
                             , vsrv->naddr*sizeof(*vsrv-
                               >vaddr) );
   } else {
          vsrv->vaddr = malloc( sizeof(*vsrv->vaddr) );
   }
   assert( vsrv->vaddr );
   /* store the data */
   vsrv->vaddr[vsrv->naddr-1].addr        = ipaddr;
   vsrv->vaddr[vsrv->naddr-1].deletable   = 0;
}

The function cfg_add_ipaddr is called with a specific virtual router structure and one IP address to be added to the list of IP addresses for this virtual router.

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.