The following code snippet adds an IP alias:
void addAlias(const char *pName, const char *pAddr, const char *pMask) { struct ifaliasreq aliasreq; struct sockaddr_in *in; /* initialize alias request */ memset(&aliasreq, 0, sizeof(aliasreq)); sprintf(aliasreq.ifra_name, pName); /* initialize alias address */ in = (struct sockaddr_in *)&aliasreq.ifra_addr; in->sin_family = AF_INET; in->sin_len = sizeof(aliasreq.ifra_addr); in->sin_addr.s_addr = inet_addr(pAddr); /* initialize alias mask */ in = (struct sockaddr_in *)&aliasreq.ifra_mask; in->sin_family = AF_INET; in->sin_len = sizeof(aliasreq.ifra_mask); in->sin_addr.s_addr = inet_addr(pMask); /* call to setup the alias */ rtems_bsdnet_ifconfig(pName, SIOCAIFADDR, &aliasreq); }
Thanks to Mike Seirs for this example code.
Copyright © 1988-2008 OAR Corporation