![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to delete the files from local host to remote host | krishna176 | SUN Solaris | 3 | 03-24-2007 12:48 PM |
| Host ID vs MAC Address | TheBlueSky | SUN Solaris | 4 | 02-03-2007 06:10 AM |
| How to get the host ip address in HP-UX in ksh? | nir_s | Shell Programming and Scripting | 12 | 08-07-2005 05:01 PM |
| Host IP address for a telnet session | shauche | UNIX for Advanced & Expert Users | 1 | 05-14-2003 04:33 AM |
| Server name + IP address removed from host table after rebooting | FIRE | UNIX for Advanced & Expert Users | 3 | 07-25-2002 12:42 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
host name to IP address
There's a piece in a C program I'm writing (Linux) that simply needs to take a host name and return an IP address (e.g., take 'mail.gnu.org' and return 199.232.76.166). I've gotten a successful status from getaddrinfo, but don't see any of the fields in the result structure that has what I'm looking for, and similar for the structure returned by gethostbyname. I'm wondering if I need to use a function like 'inet_addr' on one of those values to get what I'm looking for. Thank you.
|
| Forum Sponsor | ||
|
|
|
|||
|
|||
|
I tried this:
struct in_addr host_addr . . . . host_addr.s_addr = inet_addr(cat_str); printf("IP address ==> %s\n", inet_ntoa(host_addr)); All I get is a series of 255.255.255.255 for each of the hosts I try ('cat_str' being something like 'mail.gnu.org'). Maybe I need to pass 'cat_str' into 'gethostbyname' and take the 'host_aliases' out of that and pass it into inet_addr. I guess I'm having a little trouble with the terminology being used by these man pages and making sure I know which form of the address they are referring to. |
|
|||
|
Did you try the example code at the other end of that link?
inet_addr wants an IP address as a string ("dotted decimal notation", in the parlance), not a host name. Also, you should check its return status, to figure out if something went wrong. |
|
|||
|
Quote:
|