Date: Mon, 9 Jun 1997 11:28:41 +0800 (GMT) From: Orlando Andico To: Michael Åström cc: djgpp AT delorie DOT com Subject: Re: TCP/IP, what is my IP address? In-Reply-To: <33954849.2EAA@erm.ericsson.se> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Content-Transfer-Encoding: 8bit Precedence: bulk On Wed, 4 Jun 1997, Michael Åström wrote: > Sorry, but I think you missunderstod me. The programs task is to figure > out its own IP-address. And therefor I need a C scource that does so. > Please, post me one. Uhm. If you're using UNIX, you can do something like this: --- #include struct hostent entry, *tmpentry; tmpentry = gethostbyname ("localhost"); if (tmpentry == NULL) { fprintf (stderr, "couldn't resolve hostname: localhost\n"); exit (1); } else memcpy (&entry, tmpentry, sizeof (struct hostent)); --- At which point entry.h_addr_list contains the list of IP addresses (char **h_addr_list) terminated with a null (i.e. first IP address is h_addr_list[0] and so on). These are 4-bytes long for IPv4, network-byte order (not yet dotted-decimal). You can use the inet_network() function to retrieve the dotten-decimal address. If you're using Winsock/Windows.. I haven't got a clue :) ----------------------------------------------------------------------- Orlando Alcantara Andico WWW: http://www2.mozcom.com/~orly/ Email: orly AT mozcom DOT com ICBM: 14 deg. 30' N, 120 deg. 59' E POTS: (+632) 932-2385