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);
}
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);
}