Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

printing ip addresses using gdb

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?

like image 816
sud03r Avatar asked Nov 29 '22 11:11

sud03r


2 Answers

Just use inet_ntoa(3) as so:

(gdb) p (char*)inet_ntoa(0x01234567)  # Replace with your IP address
$1 = 0xa000b660 "103.69.35.1"
like image 130
Adam Rosenfield Avatar answered Dec 10 '22 21:12

Adam Rosenfield


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) 
like image 20
Brad W Avatar answered Dec 10 '22 22:12

Brad W