lly,
вобщем эта, я тут тестик для асинхронного резолва наваял, по идее на текущей прошивке не должен работать. Если не сложно запусти пожалуйста со своим ядром.
собирать так cc async_resolv.c -o ifenum -levent
Code:
#include <arpa/inet.h>
#include <net/if.h>
#include <netinet/ether.h>
#include <netinet/in.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <event.h>
#include <evdns.h>
//#include <evutil.h>
#include <stdio.h>
struct lookup_info
{
int start_index;
int current_index;
struct event ev;
};
int num;
void evdns_cb(int result, char type, int count, int ttl, void *addresses, void *arg) {
struct in_addr *addrs = addresses;
int i;
if (result != 0) {
printf("Error looking up address.\n");
exit(1);
} else {
for (i = 0; i < count; i++) {
printf("callback recolve test: %s\n", inet_ntoa(addrs[i]));
num = 7;
}
exit(0);
}
}
int main(int argc, char *argv[]) {
char buf[1024];
struct ifconf ifc;
struct ifreq *ifr;
int sck;
int nInterfaces;
int i;
/* Get a socket handle. */
sck = socket(AF_INET6, SOCK_DGRAM, 0);
if(sck < 0) {
perror("socket");
return 1;
}
/* Query available interfaces. */
ifc.ifc_len = sizeof(buf);
ifc.ifc_buf = buf;
if(ioctl(sck, SIOCGIFCONF, &ifc) < 0) {
perror("ioctl(SIOCGIFCONF)");
return 1;
}
/* Iterate through the list of interfaces. */
ifr = ifc.ifc_req;
nInterfaces = ifc.ifc_len / sizeof(struct ifreq);
for(i = 0; i < nInterfaces; i++) {
struct ifreq *item = &ifr[i];
/* Show the device name and IP address */
printf("%s: IP %s", item->ifr_name, inet_ntoa(((struct sockaddr_in *)&item->ifr_addr)->sin_addr));
/* Get the MAC address */
if(ioctl(sck, SIOCGIFHWADDR, item) < 0) {
perror("ioctl(SIOCGIFHWADDR)");
return 1;
}
printf(", MAC %s\n", ether_ntoa((struct ether_addr *)item->ifr_hwaddr.sa_data));
}
/* Lookup host name. */
num = 1;
char *host;
if (argc == 2) {
host = argv[1];
}
struct lookup_info *info;
/* Initialize the event library */
event_init();
evdns_init();
/* need two priorities */
event_priority_init(2);
printf("Async resolving [%s]\n", host);
int rc = evdns_resolve_ipv4(host, 0, evdns_cb, info);
if(rc != DNS_ERR_NONE) {
printf("Failed to lookup '%s': %s", host, evdns_err_to_string(rc));
}
printf("result [%d]\n", rc);
event_dispatch();
printf("num [%d]\n", num);
return 0;
}