Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what are addresses of type in_addr_t inet_ntoa etc

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.

like image 772
Registered User Avatar asked Jun 30 '11 06:06

Registered User


1 Answers

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 the in_addr structure, which shall include at least the following member:

in_addr_t s_addr

Which is

in_addr_t Equivalent to the type uint32_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 ?

like image 100
cnicutar Avatar answered Nov 15 '22 19:11

cnicutar