Wednesday, September 24, 2014

C - Implicit Declaration of Function 'inet_addr'

The inet_addr() function converts the internet host address cp from IPV4 numbers-and-dots notation into binary data in network byte order. If the input is invalid, INADDR_NONE(-1) is returned. But use of this function sometimes can be problematic because -1 represents You should avoid its use in favor of inet_aton(), inet_pton() or getaddrinfo()

But to fix the error:
implicit declaration of function 'inet_addr' is invalid in C99 [-Wimplicit-function-declaration]
    serv.sin_addr.s_addr = inet_addr(argv[1]);

You should add “#include <arpa/inet.h>” to the main.h file or any header file included.

No comments: