Ok before posting this question I have checked threads here in_addr_t to string
my question is different.
I understand that inet_ntoa function is of following type
char * inet_ntoa (struct in_addr in);
What I want to know is what is in_addr_t
what will be the representation when it is used in a 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;
};
is of above type. I do not want to print in_addr_t to char * as inet_ntoa does. I want to see what is in_addr_t.So how can it be done or what exactly is in_addr_t and why is it 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 unsigned 32 bit
int I want to see what is that and not the char *
which prints 192.168.1.1 kind of output on stdout.
As we all know (we do, right?) an IPv4
address is represented using an unsigned 32 bits integer. Us puny humans aren't so good with large numbers (or small ones) so we use dot decimal notation. (Did you know you're at 1076000524
right now ? Neither did I).
However, since you dug through netinet
and found out what is clearly specified by the standard
The
<netinet/in.h>
header shall define thein_addr
structure, which shall include at least the following member:
in_addr_t s_addr
Which is
in_addr_t
Equivalent to the typeuint32_t
as described in<inttypes.h>
you can print it.
printf("My unreadable addres is %u\n", in.s_addr);
Quick, what does 134744072
stand for ?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With