Created
August 11, 2020 18:10
-
-
Save arduent/a33756d7e3ddfcf51a0eaca908612a16 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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