same error? in the following line did you changed fprintf(stdout, "%s\n", inet_ntoa(*addr); with fprintf(stdout, "%s\n", inet_ntoa(addr);?
What do you mean with automatically?
C or C++?