title: Rebuilding a packet to inject via pcap
body: <p>Here is the situation: in my scenario I have, 3 computers, A, B and C. </p>
  
  <p>Computer A sends data to computer B. Computer B captures these packets with pcap, appends the headers, redoes the checksums, and injects it out another ethernet interface to computer C. So basically A sends to C, though through C's point of view, the data is coming from computer B.</p>
  
  <p>My problem is this: following TCPDUMP's tutorial on dissecting a captured packet, I've learned to calculate offsets and using typecasting to obtain ethernet, ip, and tcp header structures. The method of doing so is shown below:</p>
  
  <pre><code>ethernet = (struct sniff_ethernet*)(packet);
  ip = (struct sniff_ip*)(packet + SIZE_ETHERNET);
  size_ip = IP_HL(ip)*4;
  if (size_ip &lt; 20) {
      printf("   * Invalid IP header length: %u bytes\n", size_ip);
      return;
  }
  tcp = (struct sniff_tcp*)(packet + SIZE_ETHERNET + size_ip);
  size_tcp = TH_OFF(tcp)*4;
  if (size_tcp &lt; 20) {
      printf("   * Invalid TCP header length: %u bytes\n", size_tcp);
      return;
  }
  payload = (u_char *)(packet + SIZE_ETHERNET + size_ip + size_tcp);
  </code></pre>
  
  <p>Because I want to inject the captured packet to send it from computer B to computer C, I must modify some of the source/destination information and recalculate the checksum when I'm done. However, my issue is, since this data is now separated into structures of ethernet header, IP header, and TCP headers, how do I put it back together into a <code>u_char</code> that <code>pcap_inject</code> can use?</p>
  
  <p>Is it possible to do some sort of concatenation here?</p>