|
Re: How do I find my own IP address?: msg#00227lang.erlang.general
Joe Armstrong wrote: I need to know my own IP address if you are interested i have written a c program to do some of the things above (this is what i suppose the inet module is/does). if you run it, what kind of information does it print? bengt #include <stdio.h> #include <string.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <netdb.h> main(int argc, const char* argv[]) { char name[80]; struct hostent *hp; char **p; if (0 != gethostname(name, sizeof (name))) { (void) printf("gethostname failed\n"); exit (1); } hp = gethostbyname(name); if (hp == NULL) { (void) printf("host information for %s not found\n", name); exit (3); } for (p = hp->h_addr_list; *p != 0; p++) { struct in_addr in; char **q; (void) memcpy(&in.s_addr, *p, sizeof (in.s_addr)); (void)printf("%s\t%s", inet_ntoa(in), hp->h_name); for (q = hp->h_aliases; *q != 0; q++) { (void) printf(" %s", *q); } (void) putchar('\n'); } exit (0); } |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | listbox item color: 00227, Balogh Robert |
|---|---|
| Next by Date: | RE: How do I find my own IP address?: 00227, Chappell, Simon P |
| Previous by Thread: | Re: How do I find my own IP address?i: 00227, Shawn Pearce |
| Next by Thread: | Re: How do I find my own IP address?: 00227, Joachim Durchholz |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |