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

Update SubnetCalculator.php #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

xdsta
Copy link

@xdsta xdsta commented Mar 30, 2020

min-host for /31 and /32 was wrong.
max-host for /31 and /32 was wrong.

added private function "addIps".

Attention, min-host and max-host only fixed in decimal-version.

min-host for /31 and /32 was wrong.
max-host for /31 and /32 was wrong.

added private function "addIps".

Attention, min-host and max-host only fixed in dezimal-version.
@markrogoyski
Copy link
Owner

Hi @xdsta,

Thanks for your interest in SubnetCalculator.

Can you provide some information to help me understand what you perceive the issue to be. Please tell me:

  • What input you used
  • What the expected output was
  • What the actual output was
  • Why you think the actual output is wrong and the expected output is correct.

Thanks,
Mark

@xdsta
Copy link
Author

xdsta commented Apr 3, 2020

Hey @markrogoyski,

sure - we can use 192.168.0.1/31 and 192.168.0.1/32 for the test as input:

192.168.0.1/32 < this network only has one ip-address, but the min-/max-host-methods return 192.168.0.2 and 192.168.0.1. So max-host is ok, but min-host is wrong because it does not belong to this network

192.168.0.1/31 < this is a special one - it has 2 ip-addresses, but strictly seen no usable hosts. But we can use this for P2P-Connections, so we use the network-address for host 1 and the broadcast for host 2. The min-/max-hostmethods return 192.168.0.1 and 192.168.0.0 - so the output is reversed.

The mistake is to return $this->ip_address; in case of an /31 and /32 as it is not sure, that this is the networkaddress. So I changed min-host to return the network-portion instead and max-host to return network-portion + 1 for /31 as a special case.

Greetings
xdsta

@xdsta
Copy link
Author

xdsta commented Apr 3, 2020

If you are not fine with the "+1"-workaround, you can use the broadcast-calculation instead for the max-host-calculation :) This is more comprehensible for all.

} elseif ($this->network_size == 31) { return $this->getBroadcastAddress(); }

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