title: Why does a cast from sockaddr_in to sockaddr work
body: <p>In the C language a typical way to <code>bind</code> a Socket would be the following way:</p>
  
  <pre><code>int server_socket_fd = socket(AF_INET, SOCK_STREAM, 0);
  struct sockaddr_in addr;
  int port_number = 55555;
  
  addr.sin_family = AF_INET;
  addr.sin_addr.s_addr = htonl(INADDR_ANY);
  addr.sin_port = htons(port_number);
  
  int result = bind(server_socket_fd,(struct sockaddr *)&amp;addr , sizeof(addr));
  if(bind_result &gt; 0)
  {
      // Stuff
  }
  </code></pre>
  
  <p>I am wondering why the cast from <code>sockaddr_in</code> to <code>sockaddr</code> works since I cant find any documentation why it works.
  It just seems like everyone just does it.</p>
  
  <p>Why does the typecast work here?</p>
  
  <p>I am not asking why we cast it, this has been answered <a href="https://stackoverflow.com/questions/21099041/why-do-we-cast-sockaddr-in-to-sockaddr-when-calling-bind">here</a>. I am asking why it works.</p>