2
votes

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:

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

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

2
Use inet_aton to convert dotted decimal into struct in_addr datatype. Look at the man page of inet_aton to get a full list of available functions.rakib_

2 Answers

2
votes

in_addr is a struct with a single unsigned long member:

struct in_addr ip_dest;
ip_dest.s_addr = 0xffffffffL;
1
votes

I think in 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)

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