: This is a multi-part message in MIME format.
: --------------3A9D1D027FECBF4F7DAB0838
: Content-Type: text/plain; charset=us-ascii
: Content-Transfer-Encoding: 7bit
: I'm working on a GUI FTP client application in Java. In order to
: implement the PORT command I need the IP address of the client machine
: i.e. an IP address that the FTP host can use to connect to a port on the
: client machine. The Java method "getLocal Host()" just returns
: 127.0.0.1". I'm looking for some way to get this, hopefully a UNIX
: command that would return the IP number.
: Thanks Clu
in C the following program will obtain all of the IP addresses
available for the machine:
/* on Solaris build using: cc -o getip getip.c -lxnet */
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <stdio.h>
#include <string.h>
int
main(int argc, char *argv[])
{
struct hostent *he;
char hn[256];
int i = 0;
struct in_addr *addr;
/* get our hostname */
if(gethostname(hn, 256) != 0)
{
perror("gethostname");
return 1;
}
printf("host: %s\n", hn);
/* enumerate addresses available on this host */
he = gethostbyname(hn);
if(he)
{
while(he->h_addr_list[i])
{
addr = (struct in_addr *) he->h_addr_list[i];
printf(" %s\n", inet_ntoa(*addr));
i++;
}
}
else
perror("gethostbyname");
return 0;
Quote:}
--
Senior Software Engineer http://www.wwa.com/~gwiley/glen
3Com - Carrier Systems R&D
"UNIX _IS_ user friendly, its just picky about who its friends are."