What are addresses like in_addr_t inet_ntoa, etc.

Ok, before posting this question, I checked the topics here in_addr_t for the string

my question is different.

I understand that the inet_ntoa function has the following type

char * inet_ntoa (struct in_addr in); 

I want to know what in_addr_t

what will the representation be when it is used in the socket program.

I checked the structure definition in <netinet/in.h>

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

has type above. I do not want to print in_addr_t in char *, as inet_ntoa does. I want to see what in_addr_t.So is, how it can be done or what exactly in_addr_t is and why it is used again and again in socket programming. If I am not mistaken, it is defined as

typedef uint32_t in_addr_t;

So if in_addr_t is an unsigned 32 bit int, I want to see what it is, not a char * that prints 192.168.1.1 output to stdout.

+7
source share
1 answer

As we all know (we are doing this, right?), An IPv4 address is represented using unsigned 32-bit integers. We are not good people are not so good with large numbers (or small), so we use decimal decimal notation. (Do you know that you are in 1076000524 right now?).

However, since you broke through netinet and found out what is clearly stated by the standard

The header <netinet/in.h> should define the in_addr structure, which should include at least the following member:

in_addr_t s_addr

What

in_addr_t Equivalent to uint32_t , as described in <inttypes.h>

you can print it.

 printf("My unreadable addres is %u\n", in.s_addr); 

Quickly, what is 134744072 worth?

+13
source

All Articles