将' struct in_addr '从'unsigned int'类型分配给' struct in_addr '时的不兼容类型

时间:2022-03-10 04:16:06

I am using Linux for compiling. In the struct ip (for IPv4), when I tried to give the value as ip1.ip_dst = 0xffffffff;, it got the following error:

我正在使用Linux进行编译。在struct ip(针对IPv4)中,当我试图将值设为ip1时。ip_dst = 0xffffffff;

error: incompatible types when assigning to type ‘struct in_addr’ from type 'unsigned int' ip.ip_dst = 0xffffffff;`

错误:从类型“unsigned int”ip分配给类型为“struct in_addr”的不兼容类型。ip_dst = 0 xffffffff;”

What value should I give to a variable with struct in_addr datatype? And how can I solve this error?

对于具有struct in_addr数据类型的变量,我应该给它什么值?如何解决这个误差呢?

2 个解决方案

#1


2  

in_addr is a struct with a single unsigned long member:

in_addr是一个具有单个无符号长成员的结构体:

struct in_addr ip_dest;
ip_dest.s_addr = 0xffffffffL;

#2


1  

I think in Linux,

我想在Linux中,

typedef uint32_t in_addr_t;

struct in_addr {
    in_addr_t s_addr;
};

you may want to cast your value to (uint32_t)

您可能希望将您的值转换为(uint32_t)

Read more on this: http://linux.die.net/man/3/inet

更多阅读:http://linux.die.net/man/3/inet

#1


2  

in_addr is a struct with a single unsigned long member:

in_addr是一个具有单个无符号长成员的结构体:

struct in_addr ip_dest;
ip_dest.s_addr = 0xffffffffL;

#2


1  

I think in Linux,

我想在Linux中,

typedef uint32_t in_addr_t;

struct in_addr {
    in_addr_t s_addr;
};

you may want to cast your value to (uint32_t)

您可能希望将您的值转换为(uint32_t)

Read more on this: http://linux.die.net/man/3/inet

更多阅读:http://linux.die.net/man/3/inet