-
Notifications
You must be signed in to change notification settings - Fork 683
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
Conversation
There was a problem hiding this 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!
There was a problem hiding this comment.
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? 🤔
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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, andbool 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
andin6_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.
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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
andin6_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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
…able bloat." as it makes the total diff hard to read. This reverts commit aa2b280. # Conflicts: # Tests/Pcap++Test/Tests/IpMacTests.cpp
There was a problem hiding this 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.
Centralized code for comparing IP address equality between
IPAddress
derived types andin_addr
structures.