Re: C program for getting IP address of standlone box - with no sockets



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
.



Relevant Pages

  • Re: [PATCH 0/7] dlm: overview
    ... > aren't just unique within a single cluster (think clusters of clusters, ... How the configuration gets from the config file to kernel is a mystery to me ... By a message over a socket, ... Let's have no magical filesystems in the core interface please. ...
    (Linux-Kernel)
  • Re: Java Sockets/bufferedIOstreams are full-duplex right?
    ... actual socket, I take it from your description that the expansion ... The kernel manages the network interfaces and builds TCP/IP ... With SSL, the record-building phase occurs in the user space (i.e. the ... the kernel buffer is at least half-full, ...
    (comp.lang.java.programmer)
  • Re: ntpd and network sockets
    ... it is unfortunate that both interface ... small" and then blythly ignore the socket entirely. ... that the stacks "socket buffer overflow" stat will increase I ... overflow in the ntpd itself. ...
    (comp.protocols.time.ntp)
  • Re: ntpd and network sockets
    ... it is unfortunate that both interface ... small" and then blythly ignore the socket entirely. ... that the stacks "socket buffer overflow" stat will increase I ... overflow in the ntpd itself. ...
    (comp.protocols.time.ntp)
  • Re: Multicast group memberships lost if eth0 brought down and up
    ... running in user-space, not in the kernel. ... What I have is an application program which opens an IPv6 socket, ... The problem occurs when the interface is brought down and then back ... I would have expected the kernel to save group memberships when it ...
    (Fedora)