title: Want my client program to connect to over IPv4 or IPv6
body: <p>Currently, the following program only connects using an IPv4 address.
  I want it to be modified to connect to a server(compatible of accepting IPv4 and IPv6 clients) using any of IPv6 or IPv4 address of the server.</p>
  
  <pre><code>            #include &lt;stdio.h&gt;
              #include &lt;stdlib.h&gt;
              #include &lt;string.h&gt;
              #include &lt;sys/types.h&gt;
              #include &lt;sys/socket.h&gt;
              #include &lt;netinet/in.h&gt;
              #include &lt;arpa/inet.h&gt;
  
              #include "common.h"
              #include "client.h"
  
  
  
              int
              CreateClientTCP(const char *svrHost,   
                              unsigned short svrPort,
                              char *svrName, 
                              int svrNameLen)
              {
                  int sock;
                  struct sockaddr_in svrAddr;
  
                  sock = socket(AF_INET, SOCK_STREAM, 0);
                  if (sock &lt; 0) {
                      perror("Failed to allocate the client socket");
                      exit(EXIT_FAILURE);
                  }
  
                  memset(&amp;svrAddr, 0, sizeof(svrAddr));
                  svrAddr.sin_family = AF_INET;
                  svrAddr.sin_port   = htons(svrPort);
  
                  if (inet_pton(AF_INET, svrHost, &amp;svrAddr.sin_addr.s_addr) &lt;= 0) {
                      perror("Failed to convert IP address\n");
                      exit(EXIT_FAILURE);
                  }
  
                  SocketAddrToString(&amp;svrAddr, svrName, svrNameLen);
                  Log("Attempting %s\n", svrName);
  
                  if (connect(sock, (struct sockaddr *)&amp;svrAddr, sizeof(svrAddr)) &lt; 0) {
                      perror("Failed to connect to the server");
                      exit(EXIT_FAILURE);
                  }
  
                  return sock;
              }
  
  
  
              int
              main(int argc, char *argv[])
              {
                  int sock;
                  ClientArgs cliArgs;
                  char svrName[INET_ADDRSTRLEN + PORT_STRLEN];
  
                  ParseArgs(argc, argv, &amp;cliArgs);
  
                  sock = CreateClientTCP(cliArgs.svrHost, cliArgs.svrPort,
                                         svrName, sizeof svrName);
  
                  Log("Connected to server at %s\n", svrName);
  
                  Client(sock, &amp;cliArgs);
  
                  close(sock);
                  Log("\nDisconnected from server at %s\n", svrName);
                  return 0;
              }
  </code></pre>