Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added equality operators between IPAddress types and in_addr types. #1387

Merged
merged 16 commits into from
May 14, 2024

Conversation

Dimi1010
Copy link
Collaborator

@Dimi1010 Dimi1010 commented May 6, 2024

Centralized code for comparing IP address equality between IPAddress derived types and in_addr structures.

@Dimi1010 Dimi1010 requested a review from seladb as a code owner May 6, 2024 14:29
Copy link
Collaborator

@tigercosmos tigercosmos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks a lot, much cleaner!

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reason not to include those methods as part of the IPv4Address and IPv6Address classes? 🤔

Copy link
Collaborator Author

@Dimi1010 Dimi1010 May 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wasn't sure if we would want the pure IPAddress.h header to have forward declarations of in_addr and in6_addr structs, or was kept clean for some reason as it mostly included only standard headers. It would be easier to be all in one place if that is not an issue.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seladb I thought the same thing in the beginning, I guess @Dimi1010 wants to put the two following methods together:

inline bool operator==(const IPv4Address& lhs, const in_addr& rhs) 
inline bool operator==(const in_addr& lhs, const IPv4Address& rhs)

if we put the == method in the class, e.g.

bool IPv4Address::operator==(const in_addr& other) ;

then we still need to declare the following function somewhere else:

bool operator==(const in_addr& lhs, const IPv4Address& rhs)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can put bool IPv4Address::operator==(const in_addr& other) inside the class, and bool operator==(const in_addr& lhs, const IPv4Address& rhs) further down in the file? 🤔

I guess that a forward declaration of in_addr and in6_addr is not an issue, do you think otherwise?

Copy link
Collaborator Author

@Dimi1010 Dimi1010 May 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can put bool IPv4Address::operator==(const in_addr& other) inside the class, and bool operator==(const in_addr& lhs, const IPv4Address& rhs) further down in the file? 🤔

Should not be an issue.

I guess that a forward declaration of in_addr and in6_addr is not an issue, do you think otherwise?

Not really, outside of a little global namespace pollution in IPAddress.h by the 2 structs.

It is mostly as I initially just included the entire IPUtils.h header in the IPAddressUtils.h to get the in_addr structs and did not want to include the entire header in IPAddress.h. It was only changed to a forward declaration later, and at that point it was already separate files. ¯\_(ツ)_/¯

If all that is ok, I can have it done when I get some free time.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have second thoughts on this... 🤔

I don't think we have in_addr and in6_addr anywhere in our API, I'm not sure we want to include it...

Copy link
Collaborator Author

@Dimi1010 Dimi1010 May 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have second thoughts on this... 🤔

I don't think we have in_addr and in6_addr anywhere in our API, I'm not sure we want to include it...

As is, the IPAddressUtils.h can be included separately in the translation units that directly operate with in_addr and in6_addr already and need the comparison operators, so it will not pollute the API unless included.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, let's keep it as is. Can you add tests?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where do the tests of Common++ go?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider adding tests in Tests/Pcap++Test/Tests/IpMacTests.cpp

@Dimi1010 Dimi1010 requested review from tigercosmos and seladb May 12, 2024 09:30
Copy link
Collaborator

@tigercosmos tigercosmos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, I cannot find any thing wrong.

@seladb seladb merged commit 3a77e45 into seladb:dev May 14, 2024
39 checks passed
@Dimi1010 Dimi1010 deleted the feature/ip-addr-equality-ops branch May 14, 2024 08:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants