DNS check
来源:互联网 发布:国际象棋测试软件下载 编辑:程序博客网 时间:2024/05/14 22:55
1. compile
cc ns.c -lresolv -lsocket -lnsl
2. run
It will print out local node name and its full dsn name. (uname -n)
It DSN work failed, a error string will be printed out, and full dsn name will be same as nodename.
#include <string.h>
#include <sys/types.h>
#include <sys/utsname.h>
#include <netinet/in.h>
#include <arpa/nameser.h>
#include <resolv.h>
#include <netdb.h>
/**
* Compile how to:
* cc ns.c -lresolv -lsocket -lnsl
*/
void main(int argc, char * argv[])
{
static struct utsname n;
typedef union
{
HEADER hdr;
unsigned char buf[1024];
} querybuf;
querybuf answer;
unsigned char *cp;
long l;
char name[255];
char *ret_ptr;
if (uname(&n) == -1)
{
printf("Cannot run uname(...)/n");
return;
}
ret_ptr = n.nodename;
/*
* On certain machines (Solaris, for instance), n.nodename is not in FQDN
* format. On Linux it is. So, let's ensure that what we have is a
* FQDN
*/
l = res_init();
if (l == -1) {
printf("Cannot run res_init(...)/n");
goto done;
}
l = res_search(ret_ptr, C_IN, T_ANY, (u_char *)&answer, sizeof(answer));
if (l == -1 || (unsigned long)l < sizeof(HEADER)) {
printf("Cannot run res_search(...)/n");
goto done;
}
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("Cannot run dn_expand(...)/n");
goto done;
}
ret_ptr = name;
done:
if (l == -1)
printf("node name=[%s], fullname=[%s]/n",n.nodename,ret_ptr);
else
printf("node name=[%s], fullname=[%s]/n",n.nodename,ret_ptr);
ret_ptr = 0;
}
- DNS check
- check
- CHECK
- DNS
- dns
- dns
- DNS
- DNS
- DNS
- DNS
- DNS
- DNS
- DNS
- DNS
- DNS
- DNS
- DNS
- DNS
- VC++ 编程荟萃(21-40)
- javascript正则表达式的常用方法总结
- 操练听力技巧
- JNDI 在 J2EE 中的角色
- 重写struts控制器导致在apache+weblogic环境下无法访问的问题
- DNS check
- 桌面老出现Default和NativeImage文件夹的解决办法
- 鲁迅美术学院2009年本科生招生发放文化考试通知单各专业分数线
- java 中如何实现定时器
- IT业未来做什么最赚钱?
- 快速排序
- 华为H3C拨号软件编译过程
- php中update的书写
- MyEclipse6.0+FlexBuilder3插件