M
Mantorok Redgormor
I have a member of a struct which is:
int32_t ut_addr_v6[4];
And int32_t is typedef int int32_t; mentioning that for clarity.
Now when I attempt the following:
printf("%u.%u.%u.%u\n", ut_addr_v6[0],
ut_addr_v6[1], ut_addr_v6[2],
ut_addr_v6[3]);
I get: 2912244697.0.0.0
Why is it that I get this result from the above?
However, if I use the following:
void *ptr;
unsigned char *ptr1;
ptr = ut_addr_info;
ptr1 = ptr;
printf("%u.%u.%u.%u\n", ptr1[0], ptr1[1], ptr1[2], ptr1[3]);
It displays how I wish it to display. So why is it that it works for a
pointer to unsigned char but doesn't work when I attempt to display
each element of the array of ints? And why is it that the array of its
is 4 ints and not just one, when all it seems to occupy is one int? Is
this for compensation of support for ipv6? If that is the case, then I
must be accessing the individual bytes of the first element of the
array with unsigned char *.
Also, what is a good method/algorithm for converting network byte
order to host byte order where host byte order is little endian? I can
extract the individual bytes in reverse order and stoe them in an
array but I was aiming more for storing them in an object of the same
type I am manipulating.
And lastly, when I was using the "ptr" of type void * above, I did the
following:
printf("%u.%u.%u.%u\n", (unsigned char)ptr[0],
(unsigned char)ptr[1], (unsigned char)ptr[2],
(unsigned char)ptr[3]);
dereferencing of void *.
Is this because the cast has no affect when ptr[0] is firstly
converted to *(ptr+0) ? What is a way around this while still using a
pointer to void?
- nethlek
int32_t ut_addr_v6[4];
And int32_t is typedef int int32_t; mentioning that for clarity.
Now when I attempt the following:
printf("%u.%u.%u.%u\n", ut_addr_v6[0],
ut_addr_v6[1], ut_addr_v6[2],
ut_addr_v6[3]);
I get: 2912244697.0.0.0
Why is it that I get this result from the above?
However, if I use the following:
void *ptr;
unsigned char *ptr1;
ptr = ut_addr_info;
ptr1 = ptr;
printf("%u.%u.%u.%u\n", ptr1[0], ptr1[1], ptr1[2], ptr1[3]);
It displays how I wish it to display. So why is it that it works for a
pointer to unsigned char but doesn't work when I attempt to display
each element of the array of ints? And why is it that the array of its
is 4 ints and not just one, when all it seems to occupy is one int? Is
this for compensation of support for ipv6? If that is the case, then I
must be accessing the individual bytes of the first element of the
array with unsigned char *.
Also, what is a good method/algorithm for converting network byte
order to host byte order where host byte order is little endian? I can
extract the individual bytes in reverse order and stoe them in an
array but I was aiming more for storing them in an object of the same
type I am manipulating.
And lastly, when I was using the "ptr" of type void * above, I did the
following:
printf("%u.%u.%u.%u\n", (unsigned char)ptr[0],
(unsigned char)ptr[1], (unsigned char)ptr[2],
(unsigned char)ptr[3]);
dereferencing of void *.
Is this because the cast has no affect when ptr[0] is firstly
converted to *(ptr+0) ? What is a way around this while still using a
pointer to void?
- nethlek