Reading NIC MAC's and IP addresses

Hi Group!

I've asked this before and didn't get anywhere and I just can not find any answers anywhere on the net so appologies if you've read this before.

I need some help in writing a suite of functions that will give me the interface index, MAC and IP address of every NIC on any Posix-compliant computer - a bit like what 'ifconfig' does.

I'm presuming that first I must write some kit to scan the PCI bus and look at each device class that it finds (but I'm guessing here) and follow that up with a class-specific function to interrogate the device.

What I'm after is something like the following:

extern int my_function (* struct_address);

Where the return value is the number of NIC's it found and the pointer to struct address is a dynamically created array of something like the following structure:

struct my_struct {
Unsigned char if_index;
unsigned char mac [6];
unsigned int ip4_address;
};

I don't need anyone to solve the thing for me but I'd appreciate a good starting point from which to begin like what is the library call I need to use to scan the bus?

If there is anyone who has written an ifconfig type solution before I'd welcome some feedback.

Thanks in advance.

Comments

  • : Hi Group!
    :
    : I've asked this before and didn't get anywhere and I just can not find any answers anywhere on the net so appologies if you've read this before.
    :
    : I need some help in writing a suite of functions that will give me the interface index, MAC and IP address of every NIC on any Posix-compliant computer - a bit like what 'ifconfig' does.
    :
    : I'm presuming that first I must write some kit to scan the PCI bus and look at each device class that it finds (but I'm guessing here) and follow that up with a class-specific function to interrogate the device.
    :
    : What I'm after is something like the following:
    :
    : extern int my_function (* struct_address);
    :
    : Where the return value is the number of NIC's it found and the pointer to struct address is a dynamically created array of something like the following structure:
    :
    : struct my_struct {
    : Unsigned char if_index;
    : unsigned char mac [6];
    : unsigned int ip4_address;
    : };
    :
    : I don't need anyone to solve the thing for me but I'd appreciate a good starting point from which to begin like what is the library call I need to use to scan the bus?
    :
    : If there is anyone who has written an ifconfig type solution before I'd welcome some feedback.
    :
    : Thanks in advance.
    :
    :


    If youre using windows :

    [code]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/winsock/windows_sockets_start_page_2.asp[/code]
  • : : Hi Group!
    : :
    : : I've asked this before and didn't get anywhere and I just can not find any answers anywhere on the net so appologies if you've read this before.
    : :
    : : I need some help in writing a suite of functions that will give me the interface index, MAC and IP address of every NIC on any Posix-compliant computer - a bit like what 'ifconfig' does.
    : :
    : : I'm presuming that first I must write some kit to scan the PCI bus and look at each device class that it finds (but I'm guessing here) and follow that up with a class-specific function to interrogate the device.
    : :
    : : What I'm after is something like the following:
    : :
    : : extern int my_function (* struct_address);
    : :
    : : Where the return value is the number of NIC's it found and the pointer to struct address is a dynamically created array of something like the following structure:
    : :
    : : struct my_struct {
    : : Unsigned char if_index;
    : : unsigned char mac [6];
    : : unsigned int ip4_address;
    : : };
    : :
    : : I don't need anyone to solve the thing for me but I'd appreciate a good starting point from which to begin like what is the library call I need to use to scan the bus?
    : :
    : : If there is anyone who has written an ifconfig type solution before I'd welcome some feedback.
    : :
    : : Thanks in advance.
    : :
    : :
    :
    :
    : If youre using windows :
    :
    : [code]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/winsock/windows_sockets_start_page_2.asp[/code]
    :

    Thanks for this. Actually I was using Linux but I've finally sorted it after a mega-struggle. Did it using pure ioctl. If you open an AF_INET socket there's a SIOC GET parameter that scans the bus for you and gives you a set of "struct ifreq"s with the interface names in.
    From there you can call ioctl again to get if-index mappings to devices, IP addresses, media access control data etc...

    Thanks again. Solved!
    Think it through first - then pester someone.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories