日期:2014-05-16  浏览次数:20754 次

linux内核中关于dns数据结构的定义在哪里??
linux内核中关于dns数据结构的定义在哪里??

谢谢回答!!!

------解决方案--------------------
楼主是说这个么?这个是获取不到dns的,只能得到,ip、广播、网关、硬件地址、mtu等
inline int
__nmn_stat_rtr_get_nic_addr(void *addr, const u32 x, const u32 addrtype)
{
struct ifreq ifr;
struct sockaddr_in sin;
int sock = socket(AF_INET, SOCK_DGRAM, 0);
if(-1 == sock){
return ERROR;
}
snprintf(ifr.ifr_name, IFNAMSIZ, "eth%u", x);
ifr.ifr_name[IFNAMSIZ-1] = 0;
if(-1 == ioctl(sock, addrtype, &ifr)){
return ERROR;
}
switch(addrtype)
{
case SIOCGIFADDR:
case SIOCGIFNETMASK:
// case SIOCGIFDSTADDR:
case SIOCGIFBRDADDR:
memcpy(&sin, &(ifr.ifr_dstaddr), sizeof(sin));
memcpy(addr, &sin.sin_addr.s_addr, sizeof(sin.sin_addr.s_addr));
break;
case SIOCGIFHWADDR:
memcpy(addr, &(ifr.ifr_hwaddr.sa_data), 6);
break;
case SIOCGIFMTU:
memcpy(addr, &(ifr.ifr_mtu), sizeof(addr));
break;
default:
return ERROR;
}
return NOERR;
}
------解决方案--------------------
C/C++ code

inline int
__nmn_stat_rtr_get_nic_addr(void *addr, const u32 x, const u32 addrtype)
{
    struct ifreq ifr;
    struct sockaddr_in sin;
    int sock = socket(AF_INET, SOCK_DGRAM, 0);
    if(-1 == sock){
        return ERROR;
    }
    snprintf(ifr.ifr_name, IFNAMSIZ, "eth%u", x);
    ifr.ifr_name[IFNAMSIZ-1] = 0;
    if(-1 == ioctl(sock, addrtype, &ifr)){
        return ERROR;
    }
    switch(addrtype)
    {
    case SIOCGIFADDR:
    case SIOCGIFNETMASK:
//    case SIOCGIFDSTADDR:
    case SIOCGIFBRDADDR:
        memcpy(&sin, &(ifr.ifr_dstaddr), sizeof(sin));
        memcpy(addr, &sin.sin_addr.s_addr, sizeof(sin.sin_addr.s_addr));
        break;
    case SIOCGIFHWADDR:
        memcpy(addr, &(ifr.ifr_hwaddr.sa_data), 6);
        break;
    case SIOCGIFMTU:
        memcpy(addr, &(ifr.ifr_mtu), sizeof(addr));
        break;
    default:
        return ERROR;
    }
    return NOERR;
}