Skip to content

Commit

Permalink
Version 0.7.80
Browse files Browse the repository at this point in the history
  • Loading branch information
mpenning committed Jan 4, 2025
1 parent 7a178bc commit 832849c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
8 changes: 7 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@
- Summary:
- Insert something here

## Version: 0.7.80

- Released: 2025-01-04
- Summary:
- Add more error-checking for IPv4 embedded in IPv6

## Version: 0.7.79

- Released: 2025-01-04
- Summary:
- Attempt to fix problems with IPv4 addresses embedded in IPv6Obj (such as ':ffff:192.0.2.4')
- Attempt to fix problems with IPv4 addresses embedded in IPv6Obj (such as '::ffff:192.0.2.4')

## Version: 0.7.78

Expand Down
2 changes: 1 addition & 1 deletion ciscoconfparse2/__about__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.7.79'
__version__ = '0.7.80'
18 changes: 16 additions & 2 deletions ciscoconfparse2/ccp_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -2279,14 +2279,28 @@ def as_decimal(self):
"""Returns the IP address as a decimal integer"""
num_strings = str(self.ip.exploded).split(":")

# Handle IPv4 embeddded in IPv6 strings (such as ':ffff:192.0.2.4')

########################################################################
# Handle IPv4 embeddded in IPv6 strings (such as '::ffff:192.0.2.4')
# in Python 3.13 and higher...
########################################################################
replacements = list()
for index, part in enumerate(num_strings):
try:
obj = IPv4Obj(part)
num_strings[index] = hex(obj.as_decimal).lstrip('0x')
replacements.append((index, hex(obj.as_decimal).lstrip('0x')))
except AddressValueError:
pass

# There must not be more than one ipv4 embedded in an IPv6 address
if len(replacements) > 1:
raise ValueError(str(self.ip))

for replacement in replacements:
index = replacement[0]
value = replacement[1]
num_strings[index] = value

num_strings.reverse() # reverse the order

return sum(
Expand Down

0 comments on commit 832849c

Please sign in to comment.