1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
|
/*****************************************************************************/
/*
* ifconftest.c -- Test SIOCGIFCONF ioctl.
*
* Copyright (C) 2000
* Thomas Sailer (sailer@ife.ee.ethz.ch)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* Please note that the GPL allows you to use the driver, NOT the radio.
* In order to use the radio, you need a license from the communications
* authority of your country.
*
* History:
* 0.1 19.09.2000 Created
*
*/
/*****************************************************************************/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#define _REENTRANT
#include "trx.h"
#include <sys/time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <sys/poll.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <stdarg.h>
#include <stdio.h>
#include <signal.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <signal.h>
#include <string.h>
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#else
#include "getopt.h"
#endif
#ifdef HAVE_SYSLOG_H
#include <syslog.h>
#endif
//#ifdef HAVE_NET_IF_H
//#include <net/if.h>
//#endif
#ifdef HAVE_LINUX_IF_H
#include <linux/if.h>
#endif
#ifdef HAVE_LINUX_AX25_H
#include <linux/ax25.h>
#endif
#ifdef HAVE_LINUX_SOCKIOS_H
#include <linux/sockios.h>
#endif
#ifdef HAVE_LINUX_IF_ETHER_H
#include <linux/if_ether.h>
#endif
#if defined(HAVE_ARPA_INET_H) && !defined(WIN32)
#include <arpa/inet.h>
#endif
/* --------------------------------------------------------------------- */
int main(int argc, char *argv[])
{
unsigned char buf[8192];
struct ifconf ifconf;
struct ifreq *ifr, *cur, *end, ifr2;
int fd;
if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
perror("socket");
exit(1);
}
ifconf.ifc_len = sizeof(buf);
ifconf.ifc_buf = buf;
if (ioctl(fd, SIOCGIFCONF, &ifconf) == -1) {
perror("ioctl SIOCGIFCONF");
exit(1);
}
ifr = (struct ifreq *)ifconf.ifc_buf;
end = (struct ifreq *)(((char *)ifconf.ifc_buf) + ifconf.ifc_len);
while (ifr < end) {
cur = ifr;
ifr = (struct ifreq *)(((char *)ifr) + sizeof(struct ifreq));
memcpy(&ifr2, cur, sizeof(ifr2));
if (ioctl(fd, SIOCGIFHWADDR, &ifr2)) {
perror("ioctl SIOCGIFHWADDR");
exit(1);
}
printf("IF Family: %u Name: %s Hwaddr Family: %d\n", cur->ifr_addr.sa_family, cur->ifr_name, ifr2.ifr_addr.sa_family);
}
exit(0);
}
|