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

add "missing" (bit) operator for hw_address, ip_address, ipv6_address #275

Merged
merged 5 commits into from
Mar 29, 2018
Merged

add "missing" (bit) operator for hw_address, ip_address, ipv6_address #275

merged 5 commits into from
Mar 29, 2018

Conversation

stubbfel
Copy link
Contributor

Hi,
last i play a bit with ipv6 and address caclulation and so i added some operator functions the address classes.

  • add or-operator and a simlple unit test for hw_address, ip_address, ipv6_address
  • add not-operator and a simlple unit test for hw_address, ip_address, ipv6_address
  • add greater-then-operator and a simlple unit test for ipv6_address
  • add new constructor and a simlple unit test for network_interface, which use a ipv6_address to find the nic
  • add override the function gateway_from_ip for ipv6_address parameter (untested)

… ipv6_address

* add not-operator and a simlple unit test for hw_address, ip_address, ipv6_address
* add greater-then-operator and a simlple unit test for ipv6_address
* add new constructor and a simlple unit test for network_interface, which use a ipv6_address to find the nic
* add override the function gateway_from_ip for ipv6_address parameter (untested)
@stubbfel
Copy link
Contributor Author

hmm looks like that some ipv6 adresses more invalid on windows then on linux.

@mfontanini
Copy link
Owner

Sorry it took me a few days to reply. This looks good! I'll have a deeper look later today or tomorrow and I'll probably merge it.

@mfontanini
Copy link
Owner

Ugh sorry it took me so long to get back at this. I initially implemented operator< so we could store these addresses inside std::map/set and operator==/operator!= so you could... well, check for equality or inequality which is a thing you often do. In this case if we're adding operator>, I think it makes sense to implement operator<= and operator>= so address types are fully comparable. These should just be implemented in terms of the other operators (e.g. operator<= is implemented in terms of operator>).

Can you add those ones? It should be a one liner for all of them.

* add  <=, >, >= operator for IPv4Address with tests
* add  <=,>= operator for IPv6Address with tests
@stubbfel
Copy link
Contributor Author

ok, add these operators fo hw, ip and ip6 address

@mfontanini
Copy link
Owner

I'm curious why some operators are implemented as friends while the same operator in a different class is just a regular operator?

@stubbfel
Copy link
Contributor Author

??? sry im not sure what you mean with implemented as friends? if i see correctly all operators, which i added are public and did not use the friend "visiblity". may you can give an example please?

@mfontanini
Copy link
Owner

Sure, for example IPv6Address::operator~ is a free funcion. It's defined inside IPv6Address but since it's defined with friend visibility it's actually a free function (defined here).

Then the same member but for HWAddress::operator~ that's actually a member function. Is there any reason why they're not both defined in the same way?

@stubbfel
Copy link
Contributor Author

stubbfel commented Mar 19, 2018

dam yes, i think i just copied & paste the friend signature from " TINS_API friend std::ostream& operator<<(std::ostream& os, const IPv6Address& addr);" and forget to remove the friend keyword
🤦‍♂️ . ill fix it later

@stubbfel
Copy link
Contributor Author

was the refactoring of the operator so ok?

@mfontanini mfontanini merged commit 342e2c7 into mfontanini:develop Mar 29, 2018
@mfontanini
Copy link
Owner

Yep, looks good! Thanks for the PR!

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.

2 participants