convert actual address"www" to IP

How can i convert a simple address like www.in.gr to IP address x.x.x.x format?
A little tut through the needed functions like inet_ntoa would be cool, because i can't figure this out by myself.
Thanx.
skiritis13Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gugarioCommented:
Here you go, I ran into that problem recently.. what you want to use is gethostbyname().. some of these includes might be overkill, but that's all I used in my program.

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <sys/time.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/types.h>
#include <netdb.h>

struct in_addr* resolve_addr(char *host)
{
        struct hostent *h;
        static struct in_addr addr;
        //if host name empty, return null
        if (host == NULL || strlen(host) == 0)
                return NULL;

        //check to see if value entered was an IP
        addr.s_addr = inet_addr(host);
        if (addr.s_addr != -1)
                return &addr;

        //check to see if value entered was a host name
        h = gethostbyname(host);
        if (h!= NULL)
                return (struct in_addr *) *h->h_addr_list;

        //if neither worked, return NULL
        return NULL;
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
skiritis13Author Commented:
What i was really looking for is this in "for windows" format because currently i can't run linux.
Anyway i made it win-ed my self( the code is the same, i just changed the headers ) but gethostbyname keeps returning null.I run into the msdn and it was very clear to use getaddrinfo in the place of gethostbyname. Any point on how to use getaddrinfo and the struct addrinfo or should i stick with the above code block?
Again: in the above gethostbyname keeps returning NULL.
0
skiritis13Author Commented:
Anyway i just made it work.Thanx for the code!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.