public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: IP ADDRESS OF MACHINE
@ 2002-02-28  3:25 snodx
  2002-02-28  3:55 ` Edmund Green
  0 siblings, 1 reply; 23+ messages in thread
From: snodx @ 2002-02-28  3:25 UTC (permalink / raw)
  To: gcc-help

OK After reading Mr Rupert Wood's post I decided that enough is enough
and decided to test whether a NetWork Card is installed on my system or
not.

So I connected an Internet Router to my Linux computer. If there is a
NetWork Card installed on my computer then I should be able to access
the Internet.

And voila, there is a NetWork Card installed on my system.

I had already set the Computer's TCP/IP Address to 192.168.0.2. The
Internet router's address was set to 151.137.54.204

So by accessing the internet I was able to confirm that there is indeed a
NetWork Card on my computer.

But I decided to explore a bit further. I came across a command /bin/netstat

I ran this command /bin/netstat --route

This was the output that I got:

Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
192.168.0.2     *               255.255.255.255 UH        0 0          0 eth0
192.168.0.0     *               255.255.255.0   U         0 0          0 eth0
127.0.0.0       *               255.0.0.0       U         0 0          0 lo
default         151.137.54.204   0.0.0.0         UG        0 0          0 eth0

I am now slowly able to understand some of the Jargon that Mr Rupert wood was using.
He talked about interfaces and I understand now that there is a EtherNet Interface
eth0 installed on my system.

So now this is the final-most-precise-version of my question:

I have a EtherNet Interface eth0 installed on my system. The TCP/IP Address of
my computer has been set to 192.168.0.2.

I wish to develop a C/C++ program that can retrieve the local computer's TCP/IP Address.

I DONT WANT THE PROGRAM TO SEARCH IN THE /etc/hosts FILE WHICH IS I BELIEVE USED FOR
A DIFFERENT PURPOSE.

In short I am looking for a program like /bin/netstat --route only this program is to be
much much much simpler. It just needs to retrieve the TCP/IP Address 192.168.0.2 and display
it.

Thanx for everybody's inputs here.

Awaiting a final reply.
SNODX

^ permalink raw reply	[flat|nested] 23+ messages in thread
[parent not found: <616BE6A276E3714788D2AC35C40CD18D53345D@whale.softwire.co.uk>]
[parent not found: <616BE6A276E3714788D2AC35C40CD18D47C245@whale.softwire.co.uk>]
* Re: IP ADDRESS OF MACHINE
@ 2002-02-28  4:04 snodx
  2002-02-28  4:30 ` Michal Lipták
  0 siblings, 1 reply; 23+ messages in thread
From: snodx @ 2002-02-28  4:04 UTC (permalink / raw)
  To: gcc-help

Alright Mr Green, that was a nice point. Your post has made me
refine my question a bit more.

Maybe there are several interfaces installed on a system. BUT the interface
through which an internet browser like Netscape Navigator or Lynx interacts with
the Internet HAS to be after all one. I am talking about THIS IP Address that the
system is using to talk to the internet. How does the internet browser access the
Internet? I want a C/C++ program to detect THIS interface and display IT'S IP Address.

That leads to the second part of your question is there a better place where this
question can be posted. I think the best place would be where network issues are
discussed. I shall indeed do so. I posted this question here because 

So now how do I obtain the TCP/IP Address of that interface through which an internet
browser interacts?

Thanks for the input anyway.

SNODX

^ permalink raw reply	[flat|nested] 23+ messages in thread
* Re: IP ADDRESS OF MACHINE
@ 2002-02-28  3:56 snodx
  0 siblings, 0 replies; 23+ messages in thread
From: snodx @ 2002-02-28  3:56 UTC (permalink / raw)
  To: gcc-help

Alright Mr Green, that was a nice point. Your post has made me
refine my question a bit more.

Maybe there are several interfaces installed on a system. BUT the interface
through which an internet browser like Netscape Navigator or Lynx interacts with
the Internet HAS to be after all one. I am talking about THIS IP Address that the
system is using to talk to the internet. How does the internet browser access the
Internet? I want a C/C++ program to detect THIS interface and display IT'S IP Address.

That leads to the second part of your question is there a better place where this
question can be posted. I think the best place would be where network issues are
discussed. I shall indeed do so. I posted this question here because 

So now how do I obtain the TCP/IP Address of that interface through which an internet
browser interacts?

Thanks for the input anyway.

SNODX

^ permalink raw reply	[flat|nested] 23+ messages in thread
[parent not found: <616BE6A276E3714788D2AC35C40CD18D47C203@whale.softwire.co.uk>]
* Re: IP ADDRESS OF MACHINE
@ 2002-02-28  1:38 snodx
  0 siblings, 0 replies; 23+ messages in thread
From: snodx @ 2002-02-28  1:38 UTC (permalink / raw)
  To: gcc-help

Thanks Andrea 'Fyre Wyzard' Bocci for your response.

I ran the code that you gave. It DID give me the IP Address of the machine which was: 127.0.0.1

This means that my system has been set to localhost address.

This localhost address will be used by those application servers which will be installed and configured on my system
such as the Apache server.

But 127.0.0.1 is set BY DEFAULT. Using the /bin/netconf application I set my standalone computer's proper TCP/IP
address which was 192.168.0.2.

Using a C/C++ program I wanted to obtain THIS address (192.168.0.2) not 127.0.0.1

I understand that the confusion has arisen because I posted the wrong question.

I am rephrasing the question here:

I have a standalone computer and I dont know whether there is a NetWork Card installed and configured on this computer.

Using /bin/netconf I set the local TCP/IP address of this computer which is 192.168.0.2

Now using a C/C++ program I wish to obtain the TCP/IP address of the machine. How do I go about this.

SNODX

^ permalink raw reply	[flat|nested] 23+ messages in thread
* Re: IP ADDRESS OF MACHINE
@ 2002-02-27  9:17 snodx
  2002-02-27 19:32 ` Andrea 'Fyre Wyzard' Bocci
  0 siblings, 1 reply; 23+ messages in thread
From: snodx @ 2002-02-27  9:17 UTC (permalink / raw)
  To: gcc-help

Greetings,
           Thanks to Stephano Mariani and Robert Lopez for their inputs.

            Robert Lopez wrote:
             >The GNU C Library Reference Manual might be useful to you. See the
sections on Host Addresses and  Host Names in the Sockets section.

            Where can I get the GNU C Library Reference Manual?

            Stephano Mariani wrote:

            >See `man gethostbyname`

            I gather that you suggested that I use this function which exists in the netdb.h header file

            I wrote the following C program:

            #include<unistd.h>
            #include<netdb.h>

            main()
            {
              int snodsize=12;
              char snodarr[100],arrsnod[100],*sndptr,*snodptr,**snodptrptr;
              struct hostent *hstptr;

              sndptr=snodarr;
              snodptr=arrsnod;
              snodptrptr=&snodptr;

                gethostname(sndptr,(size_t)snodsize);

              hstptr=gethostbyname(sndptr);
              snodptrptr=hstptr->h_addr_list;

                printf("%s",*snodptrptr);
            }
___________________________________________________________________________________________________

        The program is simple to understand:

        It declares a pointer to a character ARRAY called sndptr

        It declares another pointer to another character array snodptr

        It declares a pointer to a character pointer called snodptrptr

        It retrieves the hostname of the current system using gethostname of unistd.h

        It retrieves a pointer to a hostent structure using gethostbyname of netdb.h

        Next I equate the pointer-to-character-pointer variable snodptrptr
        to the h_addr_list field of the hostent structure. This is because
        h_addr_list is the most likely field where the IP Address might be
        stored and it is a pointer-to-pointer which cannot be accessed directly.
        Hence snodptrptr

        I display snodptrptr.

        But I am not getting the IP Address as I wanted it.
__________________________________________________________________________________________________

         What am I doing wrong? Are there any modifications in the code?
         SNODX

^ permalink raw reply	[flat|nested] 23+ messages in thread
* Re: IP ADDRESS OF MACHINE
@ 2002-02-27  5:13 snodx
  0 siblings, 0 replies; 23+ messages in thread
From: snodx @ 2002-02-27  5:13 UTC (permalink / raw)
  To: gcc-help

Greetings,
           Thanks to Stephano Mariani and Robert Lopez for their inputs.

            Robert Lopez wrote:
             >The GNU C Library Reference Manual might be useful to you. See the
sections on Host Addresses and  Host Names in the Sockets section.

            Where can I get the GNU C Library Reference Manual?

            Stephano Mariani wrote:

            >See `man gethostbyname`

            I gather that you suggested that I use this function which exists in the netdb.h header file

            I wrote the following C program:

            #include<unistd.h>
            #include<netdb.h>

            main()
            {
              int snodsize=12;
              char snodarr[100],arrsnod[100],*sndptr,*snodptr,**snodptrptr;
              struct hostent *hstptr;

              sndptr=snodarr;
              snodptr=arrsnod;
              snodptrptr=&snodptr;

                gethostname(sndptr,(size_t)snodsize);

              hstptr=gethostbyname(sndptr);
              snodptrptr=hstptr->h_addr_list;

                printf("%s",*snodptrptr);
            }
___________________________________________________________________________________________________

        The program is simple to understand:

        It declares a pointer to a character ARRAY called sndptr

        It declares another pointer to another character array snodptr

        It declares a pointer to a character pointer called snodptrptr

        It retrieves the hostname of the current system using gethostname of unistd.h

        It retrieves a pointer to a hostent structure using gethostbyname of netdb.h

        Next I equate the pointer-to-character-pointer variable snodptrptr
        to the h_addr_list field of the hostent structure. This is because
        h_addr_list is the most likely field where the IP Address might be
        stored and it is a pointer-to-pointer which cannot be accessed directly.
        Hence snodptrptr

        I display snodptrptr.

        But I am not getting the IP Address as I wanted it.
__________________________________________________________________________________________________

         What am I doing wrong? Are there any modifications in the code?
         SNODX

^ permalink raw reply	[flat|nested] 23+ messages in thread
* Re: IP ADDRESS OF MACHINE
@ 2002-02-26 18:29 Robert Lopez
  0 siblings, 0 replies; 23+ messages in thread
From: Robert Lopez @ 2002-02-26 18:29 UTC (permalink / raw)
  To: snodx, gcc-help


> So I wish to obtain my standalone computer's IP Address through a
> C/C++ program. What function should I use for this?

The GNU C Library Reference Manual might be useful to you. See the
sections on Host Addresses and  Host Names in the Sockets section.

Robert.Lopez@Philips.com

^ permalink raw reply	[flat|nested] 23+ messages in thread
* Re: IP ADDRESS OF MACHINE
@ 2002-02-26  4:18 snodx
  2002-02-26  5:46 ` Stephano Mariani
  2002-02-28 14:02 ` Florian Weimer
  0 siblings, 2 replies; 23+ messages in thread
From: snodx @ 2002-02-26  4:18 UTC (permalink / raw)
  To: gcc-help

I am working on a standalone computer. This is why I said that I dont
know whether there is a NetWork card installed and configured. I just set
the IP Address using the /bin/netconf utility

So I wish to obtain my standalone computer's IP Address through a
C/C++ program. What function should I use for this?

SNODX

^ permalink raw reply	[flat|nested] 23+ messages in thread
* IP ADDRESS OF MACHINE
@ 2002-02-26  0:35 snodx
  2002-02-26  1:29 ` Frank Schafer
  0 siblings, 1 reply; 23+ messages in thread
From: snodx @ 2002-02-26  0:35 UTC (permalink / raw)
  To: gcc-help

Gretings,
         I was exploring the header files that come alongwith the GNU Gcc package when I came across the function gethostname in unistd.h

         When I called the function I got the hostname of the machine on which I was running the program.

         Is there a similar function which can return the IP Address of the machine? I tried gethostid but it is returning a number in long int format.

         I may mention that I have RedHat Linux 6.0 with gcc version 2.91 installed. I dont know if I have a network card installed but I set the IP Address using the /bin/netconf utility.

         SNODX

^ permalink raw reply	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2002-03-05  9:18 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-02-28  3:25 IP ADDRESS OF MACHINE snodx
2002-02-28  3:55 ` Edmund Green
     [not found] <616BE6A276E3714788D2AC35C40CD18D53345D@whale.softwire.co.uk>
2002-03-05  1:18 ` Rupert Wood
     [not found] <616BE6A276E3714788D2AC35C40CD18D47C245@whale.softwire.co.uk>
2002-02-28  5:39 ` Rupert Wood
  -- strict thread matches above, loose matches on Subject: below --
2002-02-28  4:04 snodx
2002-02-28  4:30 ` Michal Lipták
2002-02-28  3:56 snodx
     [not found] <616BE6A276E3714788D2AC35C40CD18D47C203@whale.softwire.co.uk>
2002-02-28  2:43 ` Rupert Wood
2002-02-28  1:38 snodx
2002-02-27  9:17 snodx
2002-02-27 19:32 ` Andrea 'Fyre Wyzard' Bocci
2002-02-28  6:03   ` Nelson Guedes Paulo Junior
2002-02-28  6:49     ` John Love-Jensen
2002-02-28 10:15       ` Nelson Guedes Paulo Junior
2002-03-01  6:34         ` John Love-Jensen
2002-03-05  1:07     ` Bharathi S
2002-02-27  5:13 snodx
2002-02-26 18:29 Robert Lopez
2002-02-26  4:18 snodx
2002-02-26  5:46 ` Stephano Mariani
2002-02-28 14:02 ` Florian Weimer
2002-02-26  0:35 snodx
2002-02-26  1:29 ` Frank Schafer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).