Documentation ¶
Overview ¶
Oui Lookup Library
This package allows lookin up manufacturer information from MAC addresses.
Package home: http://github.com/klauspost/oui
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errors.New("not found")
ErrNotFound will be returned when LookUp function fails to find the entry in the database.
Functions ¶
func Update ¶
Update will read and replace the content of the database. The database will remain usable while the update/parsing is taking place. If an error occurs during read or parsing, the database will not be replaced and the previous version will continue to be served.
func UpdateFile ¶
UpdateFile will read a file and replace the content of the database. The database will remain usable while the update/parsing is taking place. If an error occurs during read or parsing, the database will not be replaced and the previous version will continue to be served.
func UpdateHttp ¶
UpdateHttp will download from a URL and replace the content of the database. The database will remain usable while the updating/parsing is taking place. If an error occurs during read or parsing, the database will not be replaced and the previous version will continue to be served.
Types ¶
type DynamicDB ¶
DynamicDB is a database containing OUI entries that can be safely updated while queries are running. See the OuiDB interface for query functions.
func Open ¶
Open will read the content of the given reader and return a database with the content. You can update the returned database using the Update/UpdateFile/UpdateHttp functions.
type Entry ¶
type Entry struct { Manufacturer string `json:"manufacturer"` Address []string `json:"address"` Prefix HardwareAddr `json:"prefix"` Country string `json:"country,omitempty"` Local bool `json:"local,omitempty"` Multicast bool `json:"multicast,omitempty"` }
A database Entry the represents the data in the oui database. Local and Multicast
func (*Entry) MarshalJSON ¶
func (*Entry) MarshalJSONBuf ¶
func (mj *Entry) MarshalJSONBuf(buf fflib.EncodingBuffer) error
type ErrInvalidMac ¶
This error will be returned by ParseMac if the Mac address cannot be decoded.
func (ErrInvalidMac) Error ¶
func (e ErrInvalidMac) Error() string
Error returns a string representation of the error.
type HardwareAddr ¶
type HardwareAddr [3]byte
HardwareAddr is the OUI part of a mac address. An easy way to get a hardware address is to use the ParseMac function The hardware address is in transmission bit order.
func ParseMac ¶
func ParseMac(mac string) (*HardwareAddr, error)
ParseMac will parse a string Mac address and return the first 3 entries. It will attempt to find a separator, ':' and '-' supported. If none of these are matched, it will assume there is none.
func (HardwareAddr) Local ¶
func (h HardwareAddr) Local() bool
Local returns true if the address is in the "locally administered" segment.
func (HardwareAddr) MarshalJSON ¶
func (h HardwareAddr) MarshalJSON() ([]byte, error)
This function will return the address as a quoted hex string.
func (HardwareAddr) Multicast ¶
func (h HardwareAddr) Multicast() bool
Multicast returns true if the address is in the multicast segment.
func (HardwareAddr) String ¶
func (h HardwareAddr) String() string
String returns a hex string identifying the OUI. This will be as "xx:yy:zz" where elements are separated by ':' and written in transmission bit order
func (*HardwareAddr) UnmarshalJSON ¶
func (h *HardwareAddr) UnmarshalJSON(in []byte) error
This function will return the address as a quoted hex string.
type OuiDB ¶
type OuiDB interface { // Query the database for an entry based on the mac address // If none are found ErrNotFound will be returned. Query(string) (*Entry, error) // Look up a hardware address and return the entry if any are found. // If none are found ErrNotFound will be returned. LookUp(HardwareAddr) (*Entry, error) // Returns the generation time of the database // May return the zero time if unparsable Generated() time.Time // contains filtered or unexported methods }
OuiDB represents a database that allow you to look up Hardware Addresses
type RawGetter ¶
This interface can be used to access the raw database. This interface is available on Static databases.
type StaticDB ¶
StaticDB is a database containing OUI entries that doesn't allow updates, but on the other hand allows access to the underlying data structure. See the OuiDB interface for query functions.
func OpenStatic ¶
OpenStatic will read the content of the given reader and return a database with the content. You will not be able to update this database, but you can request the raw database with the RawDB() function.
func OpenStaticFile ¶
OpenStaticFile will read the content of a oui.txt file and return a database with the content. You will not be able to update this database, but you can request the raw database with the RawDB() function.
func OpenStaticHttp ¶
OpenStaticHttp will request the content of the URL given, parse it as a oui.txt file and return a database with the content. You will not be able to update this database, but you can request the raw database with the RawDB() function.
type Updater ¶
type Updater interface { // UpdateEntry will update/add a single entry to the database. UpdateEntry(HardwareAddr, Entry) // DeleteEntry will remove an entry from the database. If the element does not exist, nothing should happen DeleteEntry(HardwareAddr) // contains filtered or unexported methods }
The Updater interface will be satisfied if the database was opened as a dynamic database. This can be used to safely update the database, even while queries are running.