参考:http://blog.csdn.net/zahuopuboss/article/details/9259283
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <linux/if.h>
#include <linux/if_tun.h>
#include <sys/types.h>
#include <errno.h>
#include <net/route.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
/**
* ¼¤»î½Ó¿Ú
*/
int interface_up(char *interface_name)
{
int s;
if ((s = socket(PF_INET, SOCK_STREAM, 0)) < 0) {
printf("Error create socket :%d\n", errno);
return -1;
}
struct ifreq ifr;
strcpy(ifr.ifr_name, interface_name);
short flag;
flag = IFF_UP;
if (ioctl(s, SIOCGIFFLAGS, &ifr) < 0) {
printf("Error up %s :%d\n", interface_name, err