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 7656087
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:40:43+00:00 2026-05-31T12:40:43+00:00

I have struct that store info about ARP packet and I need to save

  • 0

I have struct that store info about ARP packet and I need to save the ARP request and reply packet together. I would like to use std::map for this, the key and mapped value is that ARP struct, and I would be using the find operator to math the reply with request.

My question is how can I say map::find to compare only some members from struct.

Example of what I’m trying to describe

struct arp_packet : public packet_info
{
    u_short type;   // 0x0001 request
                    // 0x0002 reply

    struct ipv4_address ip_sender;
    struct ipv4_address ip_target;
};

I would save all request in map like this

std::map<arp_packet*, arp_packet*>

First the mapped value is NULL but whet the reply packet comes I will use the find method to match it to request.

So how should I accomplist that the map would take as key the arp_packet *, and in find it would take the another arp_packet * and match it using ip_sender and ip_target?

  • 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-31T12:40:45+00:00Added an answer on May 31, 2026 at 12:40 pm

    A std::map accepts up to 4 template parameters (the last 2 have default values).

    You would be using the 3rd parameter here: a functor meant to compare two keys.

    struct ArpComparator {
      bool operator()(arp_packet* const left, arp_packet* const right) {
        // compare the fields you need here
      }
    };
    
    typedef std::map<arp_packet*, arp_packet*, ArpComparator> ArpMap;
    

    Be careful about implementing a proper operator() semantics, it should match the mathematical properties of <, notably antisymmetry and transitivity.

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

Sidebar

Related Questions

I have a struct to store info about persons and multi_index_contaider to store such
I have a function that takes a struct, and I'm trying to store its
I have a struct that looks something like this: [StructLayout(LayoutKind.Sequential)] public struct in_addr {
I have a struct that I initialize like this: typedef struct { word w;
I have an unmanaged struct I'd like to marshal to c sharp that looks
I have a code that looks something like: struct Data { int value; };
Let's say I have a struct that contains local environments: public struct Environments {
I have a 3rd party struct that is comprised of the following: [StructLayout(LayoutKind.Sequential, Size=1)]
In my C# application, I have a large struct (176 bytes) that is passed
I have a class that has an inner struct/class (I have decided which yet,

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.