i wrote the follow code in linux(ubuntu 12.04 linux kernel 3.12.17), and it compare success, but when i move the code in android with the eclipse, and compare with ndk,it shows error: incompatible types when assigning to type 'struct in_addr' from type 'int'.
addrs = inet_makeaddr(inet_netof(sin->sin_addr), INADDR_ANY);
the whole code is :
#include <jni.h>
#include <linux/if.h>
#include <linux/in.h>
#include <linux/sockios.h>
#include <stdint.h>
#include <sys/endian.h>
static struct in_addr *getbroadcastaddr(char *inter, int sock, char *buf){
struct ifconf ifc;
struct ifreq ifreq,*ifr;
static struct in_addr addrs;
struct sockaddr_in *sin;
bzero(&addrs,sizeof(addrs));
ifc.ifc_len = UDPMSGSIZE;
ifc.ifc_buf = buf;
if (ioctl(sock, SIOCGIFCONF, (char *)&ifc) < 0) {
perror("broadcast: ioctl (get interface configuration)");
return(&addrs);
}
ifr = ifc.ifc_req;
for (ifr=ifc.ifc_req;ifr->ifr_name[0];ifr++) {
if (strcmp(ifr->ifr_name,inter)) continue;
ifreq = *ifr;
if (ioctl(sock, SIOCGIFFLAGS, (char *)&ifreq) < 0) {
perror("broadcast: ioctl (get interface flags)");
continue;
}
if ((ifreq.ifr_flags & IFF_BROADCAST) &&
(ifreq.ifr_flags & IFF_UP) &&
(ifr->ifr_addr.sa_family == AF_INET)) {
sin = (struct sockaddr_in *)&ifr->ifr_addr;
if (ioctl(sock, SIOCGIFBRDADDR, (char *)&ifreq) < 0) {
addrs = inet_makeaddr(inet_netof(sin->sin_addr), INADDR_ANY);
} else {
addrs = ((struct sockaddr_in *)
(&ifreq.ifr_broadaddr))->sin_addr;
}
printf("Interface : %s\n",ifr->ifr_name);
return(&addrs);
}
}
return(NULL);
}
why? did the function 'inet_makeaddr' in android-ndk is different in the gun ?