2
votes

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 ?

1

1 Answers

1
votes

The error message is misleading, the function is simply missing from earlier versions of the NDK. The compiler produces an incompatible type error because when functions are undefined it assumes the return type is int.

The relevant file is (NDK folder)/platforms/android-xx/arch-yyy/usr/include/arpa/inet.h

You can solve your problem by updating to the latest version of the NDK. inet_makeaddr is defined in inet.h as of android-21

If you still get a compile error after that then try

#include <arpa/inet.h>