root and hwaddr checking

Releases and bugs in here...
Sedulus
Forum Moderator
Posts: 687
Joined: 2003-01-04 14:32

root and hwaddr checking

Post by Sedulus » 2003-02-10 21:13

you don't need to be root if you use the following ioctl's
(I googled for this)

Code: Select all

#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <linux/if.h>

int main()
{
    struct ifreq ifr;
    struct ifreq *IFR;
    struct ifconf ifc;

    char buf[1024];
    int s, i;

    if((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
      return -1;

    ifc.ifc_len = sizeof(buf);
    ifc.ifc_buf = buf;
    ioctl(s, SIOCGIFCONF, &ifc);


    IFR = ifc.ifc_req;
    for (i = ifc.ifc_len / sizeof(struct ifreq); --i >= 0; IFR++) {

        strcpy(ifr.ifr_name, IFR->ifr_name);
        if (ioctl(s, SIOCGIFFLAGS, &ifr) == 0) {
            if (! (ifr.ifr_flags & IFF_LOOPBACK)) {
                if (ioctl(s, SIOCGIFHWADDR, &ifr) == 0) {
                    int j;
                    for (j=0; j<5; ++j)
                      printf("%02x:", ((unsigned char*)ifr.ifr_hwaddr.sa_data)[j]);
                    printf("%02x\n", ((unsigned char*)ifr.ifr_hwaddr.sa_data)[j]);
                }
            }
        }
    }

    close(s);
    return 0;
}
http://dc.selwerd.nl/hublist.xml.bz2
http://www.b.ali.btinternet.co.uk/DCPlusPlus/index.html (TheParanoidOne's DC++ Guide)
http://www.dslreports.com/faq/dc (BSOD2600's Direct Connect FAQ)

Who is online

Users browsing this forum: Google [Bot] and 0 guests