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

OUI constructor does not support inputs it claims to support #248

Open
JonathonReinhart opened this issue Jul 17, 2022 · 0 comments
Open

Comments

@JonathonReinhart
Copy link

JonathonReinhart commented Jul 17, 2022

The OUI constructor OUI.__init__ claims to support accepting a regular old MAC address as an input:

Also accepts and parses full MAC/EUI-48 address strings (but not MAC/EUI-48 integers)

def __init__(self, oui):
"""
Constructor
:param oui: an OUI string ``XX-XX-XX`` or an unsigned integer. \
Also accepts and parses full MAC/EUI-48 address strings (but not \
MAC/EUI-48 integers)!
"""
super(OUI, self).__init__()

It handles a hyphen-separated OUI okay:

>>> OUI('f4-6d-04')
OUI('F4-6D-04')

But doesn't work as advertised in the doc string with any of the formats (supported by EUI parser):

Bare MAC:

>>> oui = OUI('f46d04112233')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3/dist-packages/netaddr/eui/__init__.py", line 101, in __init__
    raise NotRegisteredError('OUI %r not registered!' % oui)
netaddr.core.NotRegisteredError: OUI 'f46d04112233' not registered!

Hyphen-separated MAC:

>>> oui = OUI('f4-6d-04-11-22-33')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3/dist-packages/netaddr/eui/__init__.py", line 101, in __init__
    raise NotRegisteredError('OUI %r not registered!' % oui)
netaddr.core.NotRegisteredError: OUI 'f4-6d-04-11-22-33' not registered!

Colon-separated MAC:

>>> OUI('f4:6d:04:11:22:33')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3/dist-packages/netaddr/eui/__init__.py", line 83, in __init__
    self._value = int(oui.replace('-', ''), 16)
ValueError: invalid literal for int() with base 16: 'f4:6d:04:11:22:33'

FWIW I'm testing on version 0.7.19 (Debian bullseye) but the code I've linked to is in master.


There are a number of TODOs here:

if isinstance(oui, str):
#TODO: Improve string parsing here.
#TODO: Accept full MAC/EUI-48 addressses as well as XX-XX-XX
#TODO: and just take /16 (see IAB for details)
self._value = int(oui.replace('-', ''), 16)

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

No branches or pull requests

1 participant