当前位置: 技术问答>linux和unix
用何函数可以得到本机ip和DNS?急!!!!!!!
来源: 互联网 发布时间:2015-04-25
本文导语: 多谢!! | /*获得本机IP*/ #include #include #include #include #include #include #include #include #include #include #include #include #include struct in_addr myself,mymask; int fd_arp; struct ifreq ifr; void main(int arg...
多谢!!
|
/*获得本机IP*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
struct in_addr myself,mymask;
int fd_arp;
struct ifreq ifr;
void main(int argc,char *argv[])
{
char device[32];
struct sockaddr_in from,to;
int fromlen;
struct sockaddr_in *sin_ptr;
u_char *ptr;
int n;
strcpy(device,"eth0");
if((fd_arp=socket(AF_INET,SOCK_PACKET,htons(0x0806))),0)
{
perror("arp socket err");
exit(-1);
}
strcpy(ifr.ifr_name,device);
if(ioctl(fd_arp,SIOCGIFADDR,&ifr)sin_addr;
if(ioctl(fd_arp,SIOCGIFNETMASK,&ifr)sin_addr;
if(ioctl(fd_arp,SIOCGIFHWADDR,&ifr)
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
struct in_addr myself,mymask;
int fd_arp;
struct ifreq ifr;
void main(int argc,char *argv[])
{
char device[32];
struct sockaddr_in from,to;
int fromlen;
struct sockaddr_in *sin_ptr;
u_char *ptr;
int n;
strcpy(device,"eth0");
if((fd_arp=socket(AF_INET,SOCK_PACKET,htons(0x0806))),0)
{
perror("arp socket err");
exit(-1);
}
strcpy(ifr.ifr_name,device);
if(ioctl(fd_arp,SIOCGIFADDR,&ifr)sin_addr;
if(ioctl(fd_arp,SIOCGIFNETMASK,&ifr)sin_addr;
if(ioctl(fd_arp,SIOCGIFHWADDR,&ifr)