X-Git-Url: http://git.maemo.org/git/?p=mardrone;a=blobdiff_plain;f=mardrone%2FARDrone_SDK_Version_1_8_20110726%2FControlEngine%2FiPhone%2FClasses%2Fwifi.c;fp=mardrone%2FARDrone_SDK_Version_1_8_20110726%2FControlEngine%2FiPhone%2FClasses%2Fwifi.c;h=c7d25d09c2e1e242b00b3e0449cc1887ca2a1048;hp=0000000000000000000000000000000000000000;hb=9ec9bc13b75d30bc45535c54a652934debfcea92;hpb=ae0a3c2dc0898400aca0dd6b439c5db8044db7b2 diff --git a/mardrone/ARDrone_SDK_Version_1_8_20110726/ControlEngine/iPhone/Classes/wifi.c b/mardrone/ARDrone_SDK_Version_1_8_20110726/ControlEngine/iPhone/Classes/wifi.c new file mode 100644 index 0000000..c7d25d0 --- /dev/null +++ b/mardrone/ARDrone_SDK_Version_1_8_20110726/ControlEngine/iPhone/Classes/wifi.c @@ -0,0 +1,77 @@ +/* + * wifi.c + * ARDroneEngine + * + * Created by f.dhaeyer on 30/03/11. + * Copyright 2011 Parrot SA. All rights reserved. + * + */ +#include "wifi.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define max(a,b) ((a > b) ? a : b) + +#define BUFFERSIZE 4000 + +char iphone_mac_address[] = "00:00:00:00:00:00"; + +void get_iphone_mac_address(const char *itfName) +{ + if(itfName) + { + struct ifconf ifc; + struct ifreq *ifr; + int sockfd; + char buffer[BUFFERSIZE], *cp, *cplim; + char temp[80]; + + sockfd = socket(AF_INET, SOCK_DGRAM, 0); + if (sockfd >= 0) + { + ifc.ifc_len = BUFFERSIZE; + ifc.ifc_buf = buffer; + + if (ioctl(sockfd, SIOCGIFCONF, (char *)&ifc) >= 0) + { + ifr = ifc.ifc_req; + + cplim = buffer + ifc.ifc_len; + for (cp = buffer ; cp < cplim ; ) + { + ifr = (struct ifreq *)cp; + if (ifr->ifr_addr.sa_family == AF_LINK) + { + struct sockaddr_dl *sdl = (struct sockaddr_dl *)&ifr->ifr_addr; + int a,b,c,d,e,f; + + strcpy(temp, (char *)ether_ntoa((const struct ether_addr *)LLADDR(sdl))); + sscanf(temp, "%x:%x:%x:%x:%x:%x", &a, &b, &c, &d, &e, &f); + sprintf(temp, "%02X:%02X:%02X:%02X:%02X:%02X",a,b,c,d,e,f); + if(strcmp(ifr->ifr_name, itfName) == 0) + { + strcpy(iphone_mac_address, temp); + break; + } + } + cp += sizeof(ifr->ifr_name) + max(sizeof(ifr->ifr_addr), ifr->ifr_addr.sa_len); + } + } + + close(sockfd); + } + } +}