How to get IP in uint32_t format while parsing dns A records

146 Views Asked by At

I am trying to parse a records:

l = res_query(argv[1], ns_c_any, ns_t_a, nsbuf, sizeof(nsbuf));
    if (l < 0)
    {
      perror(argv[1]);
    }
    ns_initparse(nsbuf, l, &msg);
    l = ns_msg_count(msg, ns_s_an);
    for (i = 0; i < l; i++)
    {
      ns_parserr(&msg, ns_s_an, 0, &rr);
      ns_sprintrr(&msg, &rr, NULL, NULL, dispbuf, sizeof(dispbuf));
      printf("\t%s \n", dispbuf);
      inet_ntop(AF_INET, ns_rr_rdata(rr), debuf, sizeof(debuf));
      printf("\t%s \n", debuf);
    }

and currently inet_ntop gives me the ip in 1.1.1.1 format however I want it as a 32 bit integer, any thoughts?

0

There are 0 best solutions below