l i n u x - u s e r s - g r o u p - o f - d a v i s
Next Meeting:
July 7: Social gathering
Next Installfest:
Latest News:
Jun. 14: June LUGOD meeting cancelled
Page last updated:
2003 Apr 16 08:35

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
Re: [vox-tech] getting IP address in C
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [vox-tech] getting IP address in C

My machine has two IPs I guess. and
I want to be able to detect the

Here is what I ended up doing to solve the problem

        /*detecting hostname and ip*/
        printf("Getting hostname....\n");
        gethostname(hostname, 256);
        printf("Found %s... sound good to you?\n", hostname);

        printf("Getting IP Address now...\n");
        h_entry = gethostbyname(hostname);
        if(h_entry == 0) crash("gethostbyname()");

        printf("Aha! found %s\n", inet_ntoa(*((struct in_addr
        inet_aton(h_entry->h_addr, &adr_server.sin_addr);

        len_inet = sizeof(adr_server);


----- Original Message -----
From: "Rod Roark" <rod@sunsetsystems.com>
To: <vox-tech@lists.lugod.org>
Sent: Wednesday, April 16, 2003 4:54 AM
Subject: Re: [vox-tech] getting IP address in C

> On Wednesday 16 April 2003 02:41 am, Ryan wrote:
> > Is there a quick and easy way in C to get the IP address of the current
> > machine the program is running on?
> Depends on what you want to do.  The problem with your
> question is that a machine can have multiple IP addresses.
> Using will usually work if you want to open a
> connection to something running on the local machine.
> Otherwise you can try gethostname() and resolve it to an IP
> with gethostbyname().
> --
> Rod Roark, Sunset Systems     http://www.sunsetsystems.com/
> Offering preconfigured Linux computers, custom software and
> remote system administration services.
> Public Key: http://www.sunsetsystems.com/rodspublickey.asc
> _______________________________________________
> vox-tech mailing list
> vox-tech@lists.lugod.org
> http://lists.lugod.org/mailman/listinfo/vox-tech

vox-tech mailing list

LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
O'Reilly and Associates
For numerous book donations.