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

Attachments 3.png 4.44 KB 2.png 3.72 KB 3.png 4.44 KB
1 Year
Discussion Span
Last Post by dbfud1988

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) );

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

Attachments 2.jpg 52.69 KB

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.

Edited by Moschops

This article has been dead for over six months. Start a new discussion instead.
Be sure to adhere to our posting rules.