2

I want to printf the values of ipv6 address whose type is struct in6_addr and ipv4 address whose type is u_int32_t to console.

I have tried type casting but it yields error

error: aggregate value used where an integer was expected
printf("---------------- ipv4= %zu ipv6 = %zu ",(size_t)ipv4, (size_t)ipv6);

I have also tried %s ,%lu and many other ways after going through the old question in stack overflow and other places .

If anyone has a solution to it I shall be greatly thankful .

Jayesh Bhoi
  • 24,694
  • 15
  • 58
  • 73
Altanai
  • 1,323
  • 1
  • 19
  • 33

1 Answers1

6

in6_addr is a struct which contains a union, you can't just cast it to size_t and hope it will work. You should use inet_ntop to convert it to human-readable form. See http://www.beej.us/guide/bgnet/output/html/multipage/inet_ntopman.html for more info.

Shimon Rachlenko
  • 5,469
  • 40
  • 51
  • right from the moment i heard about inet_ntop I have been tryin to pass my ipv6 address into this function and obtain a string that can be used to process furthur. However I can find a suitable implementation . Do you have c code that achieves this ? – Altanai Apr 15 '14 at 06:03