title: Bind failed: : Address family not supported by protocol family - C
body: <p>I've declared a <code>struct sockaddr_in server</code> in my main function. </p>
  
  <p>I pass it into this function to return a socket file descriptor</p>
  
  <pre><code>int openSocket(char* ip_addr, int port, struct sockaddr_in* server){
  
      int sockfd, len;
  
      sockfd = socket(AF_INET, SOCK_DGRAM, 0);
  
      if(sockfd &lt; 0){
          perror("Failed to open socket: ");
          exit(-1);
      }
  
      len = sizeof(server);
      bzero(server, len);
      server-&gt;sin_family= AF_INET;
      inet_pton(AF_INET, ip_addr, &amp;server-&gt;sin_addr);
      server-&gt;sin_port= htons(port);
  
      if((bind(sockfd, (struct sockaddr*)&amp;server, len)) &lt; 0){
          perror("Bind failed: ");
          exit(-1);
      }
      return sockfd;
  
  }
  </code></pre>
  
  <p>The struct is passed into the function using this call</p>
  
  <pre><code>sockfd = openSocket(vector-&gt;ip_addr, vector-&gt;port, &amp;server);
  </code></pre>
  
  <p>However I get the following error.</p>
  
  <pre><code> Bind failed: : Address family not supported by protocol family
  </code></pre>