分类: LINUX
2013-12-25 17:35:55
原文地址: Linux 通过 socket 设置IPv6地址 作者:gaocheng
close(sockfd6);
/***************************
*deleteIP
****************************/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
//#include
#include
#include
#include
#include
#include
#include
struct in6_ifreq
{
struct in6_addr ifr6_addr;
unsigned int ifr6_prefixlen;
unsigned int ifr6_ifindex;
};
int main(int argc, char* argv[] )
{
int sockfd6;
struct ifreq ifr;
struct in6_ifreq ifreq6;
int ret;
sockfd6 = socket(AF_INET6, SOCK_DGRAM, 0);
//
strcpy(ifr.ifr_name, "eth1");//:)
ret = ioctl(sockfd6, SIOCGIFINDEX, &ifr);
if(ret <0)
{
printf("%d\n",__LINE__);
}
//
inet_pton(AF_INET6, argv[1], &ifreq6.ifr6_addr);
ifreq6.ifr6_prefixlen = 64;//:)
ifreq6.ifr6_ifindex = ifr.ifr_ifindex;
ret = ioctl(sockfd6,SIOCDIFADDR, &ifreq6);
if(ret <0)
{
perror("deletip: ");
printf("%d\n",__LINE__);
}
//
close(sockfd6);
}