
In all cases, I plan on also implementing option 6, however.
I recommend option 3, 4, or 5, but I prefer 3 the most, and 4 after that. See more on this below.Īny of those options work.
Use the better POSIX inet_pton() "internet presentation (textual) to network (binary) format" function (see here and here) instead of the non-POSIX inet_aton() "internet ascii string to network" function (see here). Add #define _DEFAULT_SOURCE to the top of your main source file before including any headers, so that it is defined before your headers get included, thereby allowing in inet_aton() from where you include. Gcc -Wall -Wextra -Werror -O3 -std=c17 -D_DEFAULT_SOURCE \ Use the less-restrictive -std=gnu17 instead of -std=c17 ( thanks, Add -D_DEFAULT_SOURCE to your build command to define the macro _DEFAULT_SOURCE for your entire program, so that gcc will allow in inet_aton() from for you (more on this below). Remove -std=c17 so that you get the extra features provided by gcc instead of being limited to the C standard. Remove -Werror from the build command so that it compiles with that error as a warning instead of as an error. So, using -std=c17 causes the declaration of inet_aton() to get excluded from, even though it would otherwise be included. WithOUT -std=c17, the gcc compiler includes many more features which are not part of the C standard, including POSIX features, gcc extensions, and special Linux system features. It turns out that putting -std=c17 is more-restrictive than just leaving that part off. (If you are stumbling upon this question, first ensure you have #include at the top of your file, as already stated in the question.) I am including arpa/inet.h, which contains the declaration for inet_aton(), at the top of my source file, so I know that is not the problem: #include Īfter a bunch of study, I figured it out! The part I want to fix is: implicit declaration of function ‘inet_aton’ did you mean ‘inet_pton’? Retcode = inet_aton("127.0.0.1", &addr_server.sin_addr) Ĭc1: all warnings being treated as errors Socket_geeksforgeeks_udp_server_GS_edit_GREAT.c:159:15: error: implicit declaration of function ‘inet_aton’ did you mean ‘inet_pton’? Socket_geeksforgeeks_udp_server_GS_edit_GREAT.c: In function ‘main’: Here is my command and error output: eRCaGuy_hello_world/c$ gcc -Wall -Wextra -Werror -O3 -std=c17 socket_geeksforgeeks_udp_server_GS_edit_GREAT.c -o bin/server -lm & bin/server Socket_geeksforgeeks_udp_server_GS_edit_GREAT.c -o bin/server \ Here is my build command: gcc -Wall -Wextra -Werror -O3 -std=c17 \ I'm working in this file: socket_geeksforgeeks_udp_server_GS_edit_GREAT.c #Implicit declaration of function code#
I am unable to use inet_aton() to convert an ASCII IP address such as "192.168.0.1" to a struct in_addr address in network byte order because I cannot get my code to compile.