Not sure what you are trying to achieve. But you shouldn’t add any AF_INET vs AF_INET6 logic. Do as explained in Userlevel IPv6 Programming Introduction and let getaddrinfo() decide.
That should get you pointed in the right direction.
(I’m being intentionally cryptic as this /sounds/ like it might be a
homework assignment - if it is, then you need to do the homework yourself
rather than have someone spoon-feed you the answer)
gcc testIP.c -o testIP
username@host:~/testIP> ./testIP
socket created 1
IPV4
a) If I understand it right the ifdef are “flags”, that flag can not have a value like 0,1,2 but just to be set or unset
b) Then I tried to see how one can automate that process, or in other words is there any way to ask the system to check that there is support for IPv6 and if yes how?
I thus tried the autoconf which generated the file b
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.68])
AC_INIT([FULL-PACKAGE-NAME], [VERSION], [BUG-REPORT-ADDRESS])
AM_INIT_AUTOMAKE
AC_CONFIG_SRCDIR([testIP.c])
AC_CONFIG_HEADERS([config.h])
# Checks for programs.
AC_PROG_CC
# Checks for libraries.
# Checks for header files.
AC_CHECK_HEADERS([arpa/inet.h netdb.h netinet/in.h stdlib.h string.h sys/socket.h unistd.h])
# Checks for typedefs, structures, and compiler characteristics.
# Checks for library functions.
AC_CHECK_FUNCS([socket])
AC_OUTPUT
which seems that is trying to find out if the function socket is implemented in the system… I will try to think a bit more about that.