char * src_addr;
char * dst_addr;
src_addr = inet_ntoa(ip->ip_src);
printf("src: %s\n", src_addr);
dst_addr = inet_ntoa(ip->ip_dst);
printf("dst: %s\n", dst_addr);
printf("src: %s\n", src_addr);
This will output the dst_addr in the third printf statement. Am I doing something wrong?
From the documentation: inet_ntoa() returns the dots-and-numbers string in a static buffer that is overwritten with each call to the function.
So, in your case the second call to inet_ntoa gives you a new string but in the same buffer, so dst_addr points to the same as src_addr, which now both point to the new destination string.