Skip to content

Instantly share code, notes, and snippets.

@arduent
Created August 11, 2020 18:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arduent/a33756d7e3ddfcf51a0eaca908612a16 to your computer and use it in GitHub Desktop.
Save arduent/a33756d7e3ddfcf51a0eaca908612a16 to your computer and use it in GitHub Desktop.
#include <netinet/in.h>
#include <resolv.h>
#include <string.h>
typedef union {
HEADER qb1;
u_char qb2[65536];
} querybuf;
int main(int argc, char **argv)
{
int len;
struct __res_state statp;
querybuf resbuf;
memset(&statp, 0, sizeof(statp));
if (res_ninit(&statp) < 0) {
fprintf(stderr, "Can't initialize statp.\n");
return (1);
}
statp.options |= RES_DEBUG;
len = res_nsearch(&statp, "google.com", C_IN, T_ANY,
resbuf.qb2, 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);
}
res_ndestroy(&statp);
return (0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment