I have a Raspberry Pi which has name resolution issues with Python's getaddrinfo. I traced the source code, perhaps wrongly, to the C function gethostbyaddr. So now I am trying to create a simple test to see what this function returns. Sockets programming, and C, is way over my head, but my attempt is:
#include <sys/socket.h>
#include <string.h>
#include <stdio.h>
static struct gai_afd {
int a_af;
int a_addrlen;
int a_socklen;
int a_off;
const char *a_addrany;
const char *a_loopback;
};
int main()
{
struct hostent *hp;
struct gai_afd *gai_afd;
hp = gethostbyaddr("google.com", gai_afd->a_addrlen, AF_INET);
}
Compiling using gcc gives two warnings:
warning: useless storage class specifier in empty declaration [enabled by default]
In function ‘main’: warning: assignment makes pointer from integer without a cast [enabled by default]
Running a.out gives Segmentation fault.
What must I change to make the above work?
My objective is to find out why getaddrinfo is unable to resolve google.com when ping works fine on this very same machine. The trouble I am facing is here.