I am debugging a networking code and want to print ip addresses which are declared as int32
.
when i print it using gdb print command, i get some values which is not much meaningful.
How can i possibly print them in meaningful format?
Just use inet_ntoa(3)
as so:
(gdb) p (char*)inet_ntoa(0x01234567) # Replace with your IP address
$1 = 0xa000b660 "103.69.35.1"
If you are debugging a core file and can't use inet_ntoa() then you can also do something like:
(gdb) set $int_ip = 0x01234567 (gdb) printf "%d.%d.%d.%d\n", ($int_ip & 0xff), ($int_ip >> 8) & 0xff, ($int_ip >> 16) & 0xff, ($int_ip >> 24) 103.69.35.1 (gdb)
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