title: converting host to ip by sockaddr_in gethostname etc
body: <p>i need help converting hostname to ip and inserting to sockaddr_in->sin_addr to be able assign to char.
  For example i input: localhost and it gives me 127.0.0.1</p>
  
  <p>I found code, but i dont know why it gives me wrong numbers</p>
  
  <pre><code>//---
  #include &lt;sys/types.h&gt;
  #include &lt;netinet/in.h&gt;
  #include &lt;string.h&gt;
  #include &lt;sys/socket.h&gt;
  #include &lt;arpa/inet.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;string.h&gt;
  #include &lt;errno.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;time.h&gt;
  #include &lt;sys/fcntl.h&gt;
  #include &lt;netdb.h&gt;
  //---
  
  ///CZY WPISANO HOST
  
          struct in_addr inaddr;
          inaddr.s_addr = inet_addr(argv[1]);
          if( inaddr.s_addr == INADDR_NONE) //if sHost is name and not IP
          {
              struct hostent* phostent = gethostbyname( argv[1]);
              if( phostent == 0)
                  bail("gethostbyname()");
  
              if( sizeof(inaddr) != phostent-&gt;h_length)
                  bail("problem z inaddr"); // error something wrong,
  
              puts(argv[1]);
              inaddr.s_addr = *((unsigned long*) phostent-&gt;h_addr);
  
              //strdup( inet_ntoa(inaddr));
              srvr_addr = inet_ntoa(adr_srvr.sin_addr);
              puts(srvr_addr);
          }
  </code></pre>
  
  <p>I also wrote own code but i dont know how transfer from sockaddr to sockaddr_in data:</p>
  
  <pre><code>///CZY WPISANO HOST
      if(argv[1][0]&gt;=(char)'a' &amp;&amp; argv[1][0]&lt;=(char)'Z')
      {
          struct hostent *hent;
          hent = gethostbyname(argv[1]);
          adr_srvr.sin_addr =  (struct in_addr*)hent-&gt;h_addr_list;
  
      }
  </code></pre>
  
  <p>adr_srvr is a char* type</p>
  
  <p>I really need help, thanks!</p>