Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6838305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:34:50+00:00 2026-05-26T23:34:50+00:00

Here is the situation: in my scenario I have, 3 computers, A, B and

  • 0

Here is the situation: in my scenario I have, 3 computers, A, B and C.

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.

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:

ethernet = (struct sniff_ethernet*)(packet);
ip = (struct sniff_ip*)(packet + SIZE_ETHERNET);
size_ip = IP_HL(ip)*4;
if (size_ip < 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 < 20) {
    printf("   * Invalid TCP header length: %u bytes\n", size_tcp);
    return;
}
payload = (u_char *)(packet + SIZE_ETHERNET + size_ip + size_tcp);

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 u_char that pcap_inject can use?

Is it possible to do some sort of concatenation here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T23:34:51+00:00Added an answer on May 26, 2026 at 11:34 pm

    From the code I see here, you’re not actually dissecting the memory that libpcap captured for you. Each of the casting operations simply tells the compiler how you intend to treat the bytes starting from a pointer — what size those objects are, what offsets to find which pieces of data and how long they are.

    If you modify this memory through those pointers, you’ve modified the one and only copy of it in the process memory — and can use some of the “more basic” pointers to hand the entire block of memory to sendmsg(2) or whatever without needing to reassemble the data — you never took it apart.

    Update

    To inject the packets back on the network you need to use the raw(7) socket type; the IPPROTO_RAW socket option is required to send TCP packets through a raw(7) socket — otherwise, all TCP packets would be directed to the raw(7) socket you open, making networking on the machine difficult to use.

    The raw(7) sockets will perform some re-calculation tasks for you:

       A protocol of IPPROTO_RAW implies enabled IP_HDRINCL and is
       able to send any IP protocol that is specified in the passed
       header.  Receiving of all IP protocols via IPPROTO_RAW is not
       possible using raw sockets.
    
              ┌───────────────────────────────────────────────────┐
              │IP Header fields modified on sending by IP_HDRINCL │
              ├──────────────────────┬────────────────────────────┤
              │IP Checksum           │Always filled in.           │
              ├──────────────────────┼────────────────────────────┤
              │Source Address        │Filled in when zero.        │
              ├──────────────────────┼────────────────────────────┤
              │Packet Id             │Filled in when zero.        │
              ├──────────────────────┼────────────────────────────┤
              │Total Length          │Always filled in.           │
              └──────────────────────+────────────────────────────┘
    
       If IP_HDRINCL is specified and the IP header has a nonzero
       destination address then the destination address of the
       socket is used to route the packet.  When MSG_DONTROUTE is
       specified, the destination address should refer to a local
       interface, otherwise a routing table lookup is done anyway
       but gatewayed routes are ignored.
    
       If IP_HDRINCL isn't set, then IP header options can be set on
       raw sockets with setsockopt(2); see ip(7) for more
       information.
    

    Let the kernel re-calculate whatever it is willing to do for you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have quite unique situation. Here is my scenario: 4 thumbnails linking to the
I have a situation here with post fix and prefix operator.Take a look at
I have a strange situation here. In my android app, I have a layout
I have a simple situation here. lets face html code first => <form name=geoKey
Here is my situation: I am using telerik with winform. I have a dataset
Here is my situation. I have an application (Mirth Connect) running on the same
Here's the situation. We have a 3rd party middleware (using SQLServer as a back-end)
I have kind of a such scenario: (source: microsoft.com ) Here i need to
Here's the scenario: Platform: VS2005 and language is VC++ Situation: There's just 1 assembly
I just encountered the following situation. I have an Android app with a scenario

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.