Skip to content

Instantly share code, notes, and snippets.

@nchaimov
Created March 15, 2017 00:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nchaimov/bbf7a665d18dd91753f812c3a65551a6 to your computer and use it in GitHub Desktop.
Save nchaimov/bbf7a665d18dd91753f812c3a65551a6 to your computer and use it in GitHub Desktop.
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <string.h>
#include <dlfcn.h>
int getaddrinfo(const char *node, const char *service,
const struct addrinfo *hints, struct addrinfo **res) {
struct addrinfo my_hints;
memcpy(&my_hints, hints, sizeof(struct addrinfo));
my_hints.ai_family = AF_UNSPEC;
int(*original_getaddrinfo)(const char *, const char *, const struct addrinfo *, struct addrinfo **);
original_getaddrinfo = (int (*)(const char *, const char *, const struct addrinfo *, struct addrinfo **))
dlsym(RTLD_NEXT, "getaddrinfo");
if(original_getaddrinfo == NULL) {
fprintf(stderr, "can't find getaddrinfo\n");
abort();
}
(*original_getaddrinfo)(node, service, &my_hints, res);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment