title: Address family not supported by protocol UDP - C
body: <p>I'm trying to create an UDP interaction client/server.
  I'm having some issues trying to send messages with this code.
  During the execution I've got this error:</p>
  
  <blockquote>
    <p>"Address family not supported by protocol" after the sendto function.
    Thanks in advance!</p>
  </blockquote>
  
  <pre><code>int prepare_udp_socket(char *pong_addr, char *pong_port)
  {
      struct addrinfo gai_hints, *pong_addrinfo = NULL;
      int ping_socket;
      int gai_rv;
      int np;
  
              /*** Specify the UDP sockets' options ***/
              memset(&amp;gai_hints, 0, sizeof gai_hints);
              gai_hints.ai_family=AF_INET;
              gai_hints.ai_socktype=SOCK_DGRAM;
              gai_hints.ai_flags=0;
              gai_hints.ai_protocol = IPPROTO_UDP;
  
              if ((ping_socket = socket(gai_hints.ai_family, gai_hints.ai_socktype, gai_hints.ai_protocol)) == -1)
                  fail_errno("UDP Ping could not get socket");
              /*** change socket behavior to NONBLOCKING ***/
              if(fcntl(ping_socket,F_SETFL, O_NONBLOCK)==-1)
                  fail_errno("set NONBLOCKING socket fail");
  
              //call getaddrinfo() in order to get Pong Server address in binary form 
              gai_rv=getaddrinfo(pong_addr, pong_port, &amp;gai_hints, &amp;pong_addrinfo);
  
              if(gai_rv!=0){
                  printf("Getaddrinfo failed\n");
                  exit(1);
              }   
              /*** connect the ping_socket UDP socket with the server ***/    
          if(connect(ping_socket, pong_addrinfo-&gt;ai_addr, pong_addrinfo-&gt;ai_addrlen)!=0){
                fail_errno("Can't connect");
              }     
              freeaddrinfo(pong_addrinfo);
              return ping_socket;
          }
  
      double do_ping(int msg_size, int msg_no, char message[msg_size], int ping_socket, double timeout)
      {
          int lost_count = 0;
          char answer_buffer[msg_size];
          ssize_t recv_bytes, sent_bytes;
          int offset;
          struct sockaddr_storage pong_addr;
          size_t pong_addr_len = sizeof(struct sockaddr_storage);
          struct timespec send_time, recv_time;
          double roundtrip_time_ms;
          int re_try = 0;
          /*** write msg_no at the beginning of the message buffer ***/
      if(sprintf(message,"%d\n",msg_no)&lt;0){
              fail("sprintf(...) failed");
          }
          do {
              debug(" ... sending message %d\n", msg_no);
          /*** Store the current time in send_time ***/
          if(clock_gettime(CLOCK_MONOTONIC,&amp;send_time)!=0){
            fail_errno("clock_gettime failed with sendTime");
          }
          /*** Send the message through the socket ***/
          **if((sent_bytes = sendto(ping_socket, &amp;message, msg_size,0,(struct sockaddr*)&amp;pong_addr,pong_addr_len)) == -1){
              fail_errno("Cannot send bytes throught the socket");**
          }
  </code></pre>