title: Convert IP address from sockaddr to in_addr
body: <p>I need to convert socket address that is placed in structure <code>sockaddr</code> to structure <code>in_addr</code>. I was trying to understand how IP is stored in these structures:</p>
  <pre><code>struct sockaddr
  {
      u_short sa_family;      /* address family */
      char    sa_data[14];    /* up to 14 bytes of direct address */
  };
  
  
  struct in_addr 
  {
      union
      {
          struct { u_char s_b1,s_b2,s_b3,s_b4; } S_un_b;
          struct { u_short s_w1,s_w2; } S_un_w;
          u_long S_addr;
      }
      S_un;
  };
  </code></pre>
  <p>I got stuck with question how <code>127.0.0.1</code> is stored in 14 characters of <code>sa_data</code>.
  What is the best way to convert sockaddr to in_addr?</p>