![]() |
| | #1 |
| Registered User Join Date: Aug 2009
Posts: 5
| how to get hostname and IP address of a machine I want to get the hostname and the ip address of the machine in C on both windows and linux environments. Are there any functions in C which will give me this information? Thanks, Chandana. Last edited by Chandana; 08-17-2009 at 07:54 AM. |
| Chandana is offline | |
| | #2 |
| subminimalist Join Date: Jul 2008 Location: NYC
Posts: 3,944
| gethostname(), gethostbyaddr(), gethostbyname().
__________________ Accuracy and integrity mean nothing if you don't make it past the censors...PYTHAGORAS |
| MK27 is offline | |
| | #3 |
| Registered User Join Date: Aug 2009
Posts: 5
| Thanks for the reply. Can you give me some sample code which uses this gethostname(). I am trying to call gethostname() from the main function, but I am getting "segmentation fault" error. |
| Chandana is offline | |
| | #4 |
| Registered User Join Date: Sep 2004 Location: California
Posts: 2,845
| Post your code that is giving you the seg fault.
__________________ bit∙hub [bit-huhb] n. A source and destination for information. |
| bithub is offline | |
| | #5 |
| Registered User Join Date: Oct 2008 Location: TX
Posts: 1,262
| As a first guess I'd say that you don't have a big enough buffer for the hostname which is stored in the first argument of gethostname(). |
| itCbitC is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| obtain hostname or IP | afisher | Networking/Device Communication | 3 | 12-01-2004 07:46 AM |
| Retrieving current PC IP Address? Please help... | SyntaxBubble | Networking/Device Communication | 4 | 09-02-2003 06:12 PM |
| Outputting your IP and hostname | Nakeerb | C++ Programming | 4 | 10-21-2002 08:24 PM |
| ip or hostname | jchanwh | C Programming | 2 | 04-08-2002 08:41 PM |