当前位置: 技术问答>linux和unix
在程序中设置ip问题
来源: 互联网 发布时间:2016-01-27
本文导语: struct sockaddr_in sin; struct ifreq ifr; int fd; gchar *ptr; bzero(&ifr,sizeof(struct ifreq)); fd=socket(AF_INET,SOCK_DGRAM,0); strcpy(ifr.ifr_name,"etho"); memset(&sin,0,sizeof(sin)); sin.sin_family=AF_INET; ptr=gtk_entry_get_text(GTK_ENTRY(entry_ip)); /...
struct sockaddr_in sin;
struct ifreq ifr;
int fd;
gchar *ptr;
bzero(&ifr,sizeof(struct ifreq));
fd=socket(AF_INET,SOCK_DGRAM,0);
strcpy(ifr.ifr_name,"etho");
memset(&sin,0,sizeof(sin));
sin.sin_family=AF_INET;
ptr=gtk_entry_get_text(GTK_ENTRY(entry_ip)); //从文本框中得到用户输入的ip
sin.sin_addr.s_addr=inet_addr(ptr);
memcpy(&ifr.ifr_addr,&sin,sizeof(sin));
if(ioctl(fd,SIOCSIFADDR,&ifr)
struct ifreq ifr;
int fd;
gchar *ptr;
bzero(&ifr,sizeof(struct ifreq));
fd=socket(AF_INET,SOCK_DGRAM,0);
strcpy(ifr.ifr_name,"etho");
memset(&sin,0,sizeof(sin));
sin.sin_family=AF_INET;
ptr=gtk_entry_get_text(GTK_ENTRY(entry_ip)); //从文本框中得到用户输入的ip
sin.sin_addr.s_addr=inet_addr(ptr);
memcpy(&ifr.ifr_addr,&sin,sizeof(sin));
if(ioctl(fd,SIOCSIFADDR,&ifr)