> Incrementing an ip-address is not helpful in the context of network I/O but considerSeems like a pretty flakey way to go about determining
> a network-aware application which configures the ip-stack of the OS. In such cases you
> could have some 'configuration rules' (maybe triggered by some legacy applications) like:
> 'the ip-address of the network-peer is one above/below) the configured ip-address of
> this system'. The 'network-peer' might be a another node in a cluster or a hot-stanby-pair ...
>
peers/resources, why not use one of the many zero-conf techniques out
there... that said I'll bite.
Would there be wrap around? For example, in ipv4, what would a
decrement to the following address of 0.0.0.0 result in?
Would the result of the inc/dec always be a valid address of the same
type? For example, in ipv4, what would an increment to the following
address 223.255.255.255 result in?
Is it intended to become a multicast address, even though it isn't
pre-increment?
> At least the software produced by the company I'm working for has such requirements.Could you please provide a more detailed description of what it is
> Of course you could parse the textual representation of an ip-address convert and
> increment it but this is hackish - at least for IPv6 addresses
mistakes can easily
> made.
>
you're proposing should happen.
Would there be wrap around? For example, in ipv4, what would a
decrement to the following address of 0.0.0.0 result in?
Would the result of the inc/dec always be a valid address of the same
type? For example, in ipv4, what would an increment to the following
address 223.255.255.255 result in?
Is it intended to become a multicast address, even though it isn't
pre-increment?
Does the current ip::address class have any way to get at
the bytes of the address, other than conversion to text?
Does the current ip::address class have any way to get at
the bytes of the address, other than conversion to text?
If not, it might be a good idea to add an interface for that.
Adding an increment operation on top of that should be
comparatively easy.
Put differently: What would your "increment" code look like
with the current ip::address interface and with byte-based access
suggested above?
2013/9/8 Jens Maurer <Jens....@gmx.net>
Does the current ip::address class have any way to get at
the bytes of the address, other than conversion to text?
If not, it might be a good idea to add an interface for that.
Adding an increment operation on top of that should be
comparatively easy.
Put differently: What would your "increment" code look like
with the current ip::address interface and with byte-based access
suggested above?I would add the operators for address_v4 and address_v6 not address.address_v4:pre-increment operator: casting internal representation (in_addr) to u_long and increment by one
On 09/07/2013 06:36 AM, Oliver Kowalke wrote:This sounds like the 0.1% fringe case that I'd like not to
> I'd like to suggest an to add operator++()/operator--() to
> ip::address_v4 and ip::address_v6.
support in the standard.
Ok, I understand that's your use case.
> Incrementing an ip-address is not helpful in the context of network
> I/O but consider a network-aware application which configures the
> ip-stack of the OS. In such cases you could have some 'configuration
> rules' (maybe triggered by some legacy applications) like: 'the
> ip-address of the network-peer is one above/below) the configured
> ip-address of this system'. The 'network-peer' might be a another
> node in a cluster or a hot-stanby-pair ...
Well, address_v4 already has a to_ulong, so you can doaddress_v4 a1{whatever};
address_v4 a1_incr {++a1.to_ulong()};
I work with all sorts of routers and other networking equipment that deal with address ranges for various
purposes (like ranges of ip addresses that are given out by dhcp), being able to perform arithmetic
operations would be very helpful in manipulating such ranges. address_v4 seems to have sufficientfunctionality, address_v6 makes such manipulations quite inconvenient. I'm not sure whether this
is such a fringe case.
However, my question was not about adding the operators (it's obvious
this can be done), but what your current "increment" function looks like,
given the rest of the interface we already have:
ip::address_v4 increment(ip::address_v4)
{
// what's here?
}
> pre-increment operator: internal representation in6_addr is an array of 16 uint8_tand you have to
> address_v4:
> pre-increment operator: casting internal representation (in_addr) to u_long and increment by one
>
> address_v6:
> check the first least-significant block for overflow (255) if incremented.Ok. Thanks.
> if yes set it to zero and check the next block, otherwise increment the block.
For such a special-purpose application, such an implementation doesn't look overly
burdensome to me.
Agreed, but which of those use-cases requires which operations?
When I configure an interface, I can't see why I would use
operator++ absent some special-case hackery as in your case.
And when implementing a tree for routing, operator++ is probably
the least interesting operation for that.
And, for IPsec, where is the need for operator++ there? Which
operation on an address does IPsec need?
When I configure an interface, I can't see why I would useoperator++ absent some special-case hackery as in your case.
The standard does not prevent code from inexperienced developers
that iterate beyond the end of a std::vector, either.
Your example (textual conversion, then half-way parsing, then increment,
then probably textual conversion back to ip::address_vX)
sounds a lot like shooting yourself in the foot on purpose, something
that C/C++ has never attempted to prevent.
The operator ++ for ip addresses won't fit all needs. On one hand it should be a low level operation that just increments the bit representation of the address (=small function). On the other hand one might expect that it skips the broadcast (.255) and network (.0) addresses or has some more knowledge about what the addresses mean (=hard to misuse). In the first case: whatever code “requires” the operator ++ ties itself to a solution instead of relying on an address range interface (dependency inversion principle). In the latter case the logic is too heavy for the address class.
Not every “solution” that can be made to accomplish a task should make it into the standard. In my opinion the operator ++ is not clearly defined as a general yet simple function. The proposed low-level increment is useless without further logic and feels like a loaded gun given to you. I'd rather accept an address range class that allows traversal of the range.
It isn't quite the same is is_multicast() and friends do add additional
value, in that they "know" which bits to test to determine if the
address is a multicast address, etc.
I have no particular position (yet) on whether this is a good addition,
except to say that I don't think operator++/-- are good names for it.
From memory, one of the suggestions from Bristol was that operator< be
replaced with a specialisation of std::less, which I presume was on the
basis of making the classes look *less* like arithmetic types. Perhaps
the names next/prev or a separate address range enumerator would be more
appropriate?
In any case, feel free to fork this and experiment with proposed
changes:
https://github.com/chriskohlhoff/ip-address
In any case, feel free to fork this and experiment with proposed
changes:
https://github.com/chriskohlhoff/ip-address
On Mon, Sep 9, 2013 at 3:36 AM, Oliver Kowalke <oliver....@gmail.com> wrote:[snip]
> Am Sonntag, 8. September 2013 22:45:19 UTC+2 schrieb Frank Birbacher:
It seems quite obvious to me the semantics of operator++ and operator-- if
> 4.) ' the operator ++ is not clearly defined as a general' - in my opinion
> operator++() == generate the successor address, operator--() == generate the
> predecessor address.
we already have a operator<.
Incrementing IP addresses is weird at the corner cases (crossing class boundaries, for instance).
While there certainly is a natural ordering for certain subsets, I don't know that there is a natural total ordering over all IP addresses.
2013/9/10 Nevin Liber <ne...@eviloverlord.com>
Incrementing IP addresses is weird at the corner cases (crossing class boundaries, for instance).could you explain it in more detail please?
While there certainly is a natural ordering for certain subsets, I don't know that there is a natural total ordering over all IP addresses.
IPv4 is a 32bit field and IPv6 is a 128bit field - why is it not totally ordered?
On Tue, Sep 10, 2013 at 5:50 PM, Nevin Liber <ne...@eviloverlord.com> wrote:You do not find this property important to an object: b = a, a < ++b ?
> On 10 September 2013 15:45, Felipe Magno de Almeida
> <felipe.m...@gmail.com> wrote:
>>
>> > Is it? Does operator< produce the same ordering on big endian and
>> > little
>> > endian machines?
>> >
>> > Just asking...
>>
>> I don't know. But if operator< is broken, then it should be fixed.
>
>
> IMO, that would not make operator< broken. All that is needed is a strict
> weak ordering for use as a key in a set/map, and you would want the natural
> ordering so as not to incur a performance penalty (by either doing a byte by
> byte comparison or forcing an endian swap on some architectures).
A strict weak ordering for use as a key in a set/map is given by std::less,
operator< should always be about natural ordering, not performance, IMO.
> Is it? Does operator< produce the same ordering on big endian and littleI don't know. But if operator< is broken, then it should be fixed.
> endian machines?
>
> Just asking...
Why would I ever want to increment from, say 126.255.255.255 to 127.0.0.0? Why would anyone ever want to increment to loopback?
That is a different question than specifying what that ordering is.