Consider the program:
#include <iostream> using namespace std; #include <stdio.h> #include <sys/socket.h> #include <arpa/inet.h> #include <netinet/in.h> #include <errno.h> #include <string.h> #include <stdlib.h> //function to set IPv6 and Gateway void setIPv6(char * ip,unsigned int prefix,char * gateway) { char cmd[128]={0}; char nwkInf[5]="eth0"; sprintf(cmd,"ip addr flush dev %s",nwkInf); system(cmd); memset(cmd,0x00,128); sprintf(cmd,"ip link set %s down",nwkInf); system(cmd); memset(cmd,0x00,128); sprintf(cmd,"/sbin/ip -6 addr add %s/%d dev %s",ip,prefix,nwkInf); system(cmd); memset(cmd,0x00,128); sprintf(cmd,"/sbin/route -A inet6 add default gw %s",gateway); system(cmd); memset(cmd,0x00,128); sprintf(cmd,"ip link set %s up",nwkInf); system(cmd); } //main program int main() { //passing IPv6,prefix and Gateway setIPv6("fd18:6dc5:3dbc:ce24::5",64,"fd18:6dc5:3dbc:ce24::1"); return 0; }
Here, "fd18:6dc5:3dbc:ce24::5" is IP Address, 64 is prefix value and "fd18:6dc5:3dbc:ce24::1" Gateway.
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Consider the program:
Here, "fd18:6dc5:3dbc:ce24::5" is IP Address, 64 is prefix value and "fd18:6dc5:3dbc:ce24::1" Gateway.
need an explanation for this answer? contact us directly to get an explanation for this answer