1. watchA

Contents

    1. watchA
  1. example
https://docs.oracle.com/cd/E36784_01/html/E36873/libresolv-3lib.html

https://docs.oracle.com/cd/E36784_01/html/E36875/resolver-3resolv.html#REFMAN3Bresolver-3resolv

libresolv(3LIB)
Name
libresolv - resolver library
Synopsis

cc [ flag... ] file... –lresolv –lsocket –lnsl [ library... ]
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/nameser.h>
#include <resolv.h>
#include <netdb.h>

2. example

#include <resolv.h>
#include <string.h>

int main(int argc, char **argv)
{
    int len;
    struct __res_state statp;
    union msg {
        uchar_t buf[NS_MAXMSG];
        HEADER  h;
    } resbuf;

    /* Initialize resolver */
    memset(&statp, 0, sizeof(statp));
    if (res_ninit(&statp) < 0) {
        fprintf(stderr, "Can't initialize statp.\n");
        return (1);
    }

    /*
     * Turning on DEBUG mode keeps this example simple,
     * without need to output anything.
     */
    statp.options |= RES_DEBUG;

    /* Search for A type records */
    len = res_nsearch(&statp, "example.com", C_IN, T_A,
         resbuf.buf, NS_MAXMSG);
    if (len < 0) {
        fprintf(stderr, "Error occured during search.\n");
        return (1);
    }
    if (len > NS_MAXMSG) {
        fprintf(stderr, "The buffer is too small.\n");
        return (1);
    }

    /* ... Process the received answer ... */

    /* Cleanup */
    res_ndestroy(&statp);
    return (0);
}


CategoryDns CategoryWatch CategoryTemplate

MoinQ: libresolv (last edited 2021-05-15 05:27:50 by ToshinoriMaeno)