Re: C program for getting IP address of standlone box - with no sockets
- From: floyd@xxxxxxxxxx (Floyd L. Davidson)
- Date: Sat, 10 Dec 2005 16:36:58 -0900
agarwalpiyush@xxxxxxxxx wrote:
>Hello,
>Any inputs to get the IP address of the current machine within a C
>program with the following constraints:
>
>(i) There may be no socket based connections established on the
>interface I am interested in. [Rules out accessing the socket structure
>for saddr/daddr].
That is an unusual restriction. Perhaps if you explain why you have
that restriction you'll discover either a better way, or learn that
you don't really need such a restriction.
The significance is that no matter how you slice it, to obtain
the interface configuration _some_ program is necessarily going
to use a socket based connection to access the kernel's
information. Whether your program does it directly or calls
another program, such as /ifconfig/ to do it, probably doesn't
make any difference.
>(ii) The string should be returned to me in a buffer in the program,
>not stdout. I prefer not to pipe it out to a file and then re-read that
>file into a buffer in my program.
>
>system ("ifconfig eth0 | grep \"inet_addr\" .... >
>store_ip_in_file.txt");
>read (store_ip_in_file.txt, buffer, 15);
>
>.. is NOT preferrred!!
That makes sense.
>(iii) I have root access to the system, but unwilling to make system
>calls or anything "unsafe".
That does not make sense. There kernel provides services to
user processes... that is what an operating system *does*. You
*cannot* do much of anything without asking the kernel to
provide required services. Those services, of course, are
provided via system calls. (If you meant to say that you are
unwilling to use the system(3) function, that is *not* a "system
call", and would in fact be a reasonable statement.)
>(iv) The interface might not have a "name" .. therfore solutions based
>on gethostname and then DNS lookup of that would be not preferred
>again!
That makes sense too.
--
Floyd L. Davidson <http://www.apaflo.com/floyd_davidson>
Ukpeagvik (Barrow, Alaska) floyd@xxxxxxxxxx
.
- References:
- C program for getting IP address of standlone box - with no sockets
- From: agarwalpiyush
- C program for getting IP address of standlone box - with no sockets
- Prev by Date: Re: C program for getting IP address of standlone box - with no sockets
- Next by Date: Re: Getting output of grep into a variable in C program?
- Previous by thread: Re: C program for getting IP address of standlone box - with no sockets
- Next by thread: Re: C program for getting IP address of standlone box - with no sockets
- Index(es):
Relevant Pages
|