Doing simple domain name search Just enter sometimes Segmentation fault I really do not know how to solve this problem But some can be found ip i not idea Read what information can solve this problem I'm sorry my English is very poor

You're trying to read or write memory that isn't yours.

If you want nay more information, we'll need the code.

struct hostent *ghbn;

    ghbn = gethostbyname(argc[1]);

    if(ghbn != NULL){
        printf("Host Name->%s\n", ghbn->h_name);
        printf("IP ADDRESS->%s\n",inet_ntoa(*(struct in_addr *)ghbn->h_name) );
    }else{
        printf("error\n");
    }

I do not know gethostbyname function uses Assuming that this function scans the target router How do I get real ip

gethostbyname , inet_ntop I do not know These functions are detailed usage first ip list is Real next ip I do not know what

The function inet_ntoa expects you to pass in an in_addr structure. You can see that here:

https://msdn.microsoft.com/en-us/library/windows/desktop/ms738564%28v=vs.85%29.aspx where it says "An in_addr structure that represents an Internet host address" (under parameters).

So what are you passing to the function inet_ntoa? You are taking a hostent's h_name member, which we can see here https://msdn.microsoft.com/en-us/library/windows/desktop/ms738552(v=vs.85).aspx is a char FAR* object, and you are then insisting that your compiler treat it as if it were a pointer to a struct in_addr.

Ordering your compiler to pretend that a char pointer is actually pointing to a struct in_addr does not make it true.

Basically, you're passing nonsense to the function inet_ntoa

There are much, much easier libraries to use to do what you're tryig to do.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.