title: Passing char uninitialiezed pointer address and allocation and extraction of member variables
body: <p>I am passing <code>char *</code> pointer from main to a function <code>abc</code> which is uninitialized pointer. And I am composing a network packet so like what allocated in the function I want it to be the representation of a packet. So This is my passing of uninitialized pointer in function call inside <code>main</code></p>
  <pre><code>            char *pay;
              abc(&amp;pay);
  </code></pre>
  <p>in the function I have as signature of a function like following</p>
  <pre><code>            void abc(char **c)
  </code></pre>
  <p>this is the full function</p>
  <pre><code>        void abc(char **c)
          {
              *c=(char *) malloc(sizeof(struct ethhdr)+sizeof(struct iphdr)+sizeof(struct tcphdr)+1000/*1000=payload*/);
              struct ethhdr *eth=(struct ethhdr *)&amp;*c;
              struct iphdr *ip=(struct iphdr *)(&amp;*eth+sizeof(struct ethhdr));
              struct tcphdr *tcp=(struct tcphdr *)(&amp;*ip+sizeof(struct iphdr));
              //populate eth
              //...
              //populate ip
              //...
              //populate tcp
              tcp-&gt;source=80;
              printf(&quot;%d\n&quot;,tcp-&gt;source);
              int *x=(int *)*c;
              //x=10;
  
          }
  </code></pre>
  <p>I like to know how can I cast second line in <code>abc</code> function
  I am doing like this</p>
  <pre><code>        struct ethhdr *eth=(struct ethhdr *)&amp;*c;
  </code></pre>
  <blockquote>
  <p>second line inside <code>abc</code> function.</p>
  </blockquote>
  <p>But at line containing this instruction <code>tcp-&gt;source=80;</code> its causing segFault.</p>
  <p>So my question is how can I cast the <code>c</code> double pointer in function and to assign it to<code>struct ethhdr *</code>,<code>struct iphd *</code> and <code>struct tcphdr *</code> pointers</p>
  <p>And how to assign the values to members of <code>struct ethhdr</code> , <code>struct iphdr</code> and <code>struct tcphdr</code></p>
  <p>I tried like</p>
  <blockquote>
  <p>tcp-&gt;source=80;</p>
  </blockquote>
  <p>But causing segFault</p>