开发者

IN_ADDR struct strangely defined in android

开发者 https://www.devze.com 2023-02-12 08:40 出处:网络
I am trying to compile networking code on android and seeing compilation errors. the struct I am using is is ip_mreq_source which should be defined in header like so:

I am trying to compile networking code on android and seeing compilation errors. the struct I am using is is ip_mreq_source which should be defined in header like so:

struct ip_mreq_source {
  struct in_addr imr_multiaddr;
  struct in_addr imr_sourceaddr;
  struct in_addr imr_interface;
};

Where in_addr should be defined as:

typedef uint32_t in_addr_t;
struct in_addr
  {
    in_addr_t s_addr;
  };

My detailed error coming out of g++ (GCC 4.4.3) from the Android based compiler:

    arm-linux-androideabi-g++ -MMD -MP -MF groupsock/GroupsockHelper.o.d.org -fpic
 -ffunction-sections -funwind-tables -fstack-protector -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ 
-D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__  -Wno-psabi -march=armv5te -mtune=xscale -msoft-float 
-fno-exceptions -fno-rtti -mthumb -Os -fomit-frame-pointer -fno-strict-aliasing -finline-
limit=64 -Igroupsock/include -Igroupsock/../UsageEnvironment/include -Iandroid-
ndk-r5b/sources/cxx-stl/system/include -Igroupsock -DANDROID  -Wa,--noexecstack 
-DANDROID_NDK -Wall -fexceptions  -O2 -DNDEBUG -g   -Iandroid-8/arch-arm/usr/include -c  
groupsock/GroupsockHelper.cpp -o groupsock/GroupsockHelper.o && rm -f 
groupsock/GroupsockHelper.o.d && mv groupsock/GroupsockHelper.o.d.org 
groupsock/GroupsockHelper.o.d
groupsock/GroupsockHelper.cpp: In function 'Boolean socketJoinGroupSSM(UsageEnvironment&, int, netAddressBits, netAddressBits)':
groupsock/GroupsockHelper.cpp:427: error: request fo开发者_开发知识库r member 's_addr' in 'imr.ip_mreq_source::imr_multiaddr', which is of non-class type '__u32'
groupsock/GroupsockHelper.cpp:428: error: request for member 's_addr' in 'imr.ip_mreq_source::imr_sourceaddr', which is of non-class type '__u32'
groupsock/GroupsockHelper.cpp:429: error: request for member 's_addr' in 'imr.ip_mreq_source::imr_interface', which is of non-class type '__u32'

I am not sure what is causing the error. Any pointers would be great - no pun intended. Thanks


Thanks for everyone's help. Was able to track down the error to different struct definitions in the versions of the include files for the android g++ compiler I was using.

Turns out the Android platform g++ include files are quite restricted. The definitions of structs in these headers were of the form:

struct in_addr
  {
    __u32 s_addr;
  };

And:

struct ip_mreq_source {
  __u32 imr_multiaddr;
  __u32 in_addr imr_sourceaddr;
  int some_other_var
};

So my struct2, struct3 and struct4 were actually __u32 (unsigned ints as defined in asm/types.h) and not even structs in this old version. To solve the issue, I changed my usage to:

struct struct1 st1;
st1.struct2 = Value

instead of:

struct struct1 st1;
st1.struct2.s = Value;

Thanks for leading me the right way though.

;


The following works without a problem, what's your problem?

#include <stdint.h>

typedef uint32_t in_addr_t;

struct x {
  in_addr_t s;
};

struct foo {
  x a;
  x b;
  x c;
};

int main() {
  uint32_t v = 5;
  foo f;

  f.a.s = v;

  return 0;
}


There is nothing wrong with the code sample you provided. The only sensible explanation that comes to mind is that there's a #define somewhere that conflicts with the name of 'x' and substitutes it to '__u32' (unsigned int?).

You should try to preprocess the offending source file (-E flag for g++) to perform macro expansion and check the definition of 'struct1' in the output.

0

精彩评论

暂无评论...
验证码 换一张
取 消