title: How to implement inet_pton() in C?
body: <p>I am doing an IP header parsing and changing source IP address... before I was doing some how using <code>NIPQUAD</code> macro but not working properly then I found <code>inet_pton()</code> which changes string IP address to network byte order. I didn't understood :</p>
  <ul>
  <li><strong>how uint_32 (unsigned int) is being used to hold IP address?</strong></li>
  <li><strong>how this fuction is converting from string IP to network byte order?</strong></li>
  <li><strong>how it is being used to show IP address?</strong></li>
  </ul>
  <p><code>NIPQUAD</code> macro:</p>
  <pre><code>// use printf(&quot;%d.%d.%d.%d&quot;,NIPQUAD(iphdr-&gt;saddr));
  #define NIPQUAD(addr) \
      ((unsigned char *)&amp;addr)[0], \
      ((unsigned char *)&amp;addr)[1], \
      ((unsigned char *)&amp;addr)[2], \
      ((unsigned char *)&amp;addr)[3]
  
  </code></pre>