unix DSN lookup

1. get node name
    uname -n

2. get FQDN through DSN Server, by passing node name

3. if node name is configured as a FQDN, and DSN Server is down.
    the node name will be returned too.


4. nslookup can be used to check DSN Server result.

5. DSN server configure file is /etc/resolv.conf


#include <sys/utsname.h>
#include <resolv.h>

//     char sysname[]        /* name of this implementation of the operating */
//     char nodename[]     /* name of this node within an implementation- */
                                           /* defined communications network */
//     char release[]           /* current release level of this implementation */
//     char version[]            /* current version level of this release */
//     char machine[]         /* name of the hardware type on which the system is */
                                           /* running */

typedef union
{
        HEADER hdr;
        unsigned char buf[1024];
} querybuf;

main()
{

static struct utsname n;

          querybuf answer;
          unsigned char     *cp;
          long l;
          char      name[255];
          char     *ret_ptr;



if (uname(&n) == -1)
{
        printf("failed to uname/n");
}


 printf("nodename=%s/n",n.nodename);

        ret_ptr = n.nodename;

          res_init();
          l =  res_search(ret_ptr, C_IN, T_ANY, (u_char *)&answer, sizeof(answer));
          if ((unsigned long)l < sizeof(HEADER))
            printf("failure on res_search()/n");
         
          cp = (unsigned char *)&answer + sizeof(HEADER);
         
          memset(name, 0, sizeof(name));
          l = dn_expand((unsigned char *)&answer, (unsigned char *)&answer+512, cp,
                        name, 255);
          if (l == -1)
            printf("failure on dn_expand()/n");
          ret_ptr = name;

            printf("name=%s/n",ret_ptr);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值