HOWTO: Use Replace In Files to automatically convert OUI list into C/C++ header file

IEEE OUI and Company_id Assignments is a list of manufacturers and corresponding codes which are used in MAC addresses and protocol identifiers:

The three-octet OUI can be used to generate Universal LAN MAC addresses and Protocol Identifiers per ANSI/IEEE Std 802 for use in Local and Metropolitan Area Network applications.

If your firm manufactures or plans to manufacture products using ISO/IEC 8802 standards, you should apply to IEEE for your firm’s OUI. The Institute of Electrical and Electronics Engineers, Inc. has been designated by the ISO Council to act as the registration authority for the implementation of International Standards in the ISO/IEC 8802 series. This is the one world-wide source of registered OUIs.

The full list is located at http://standards.ieee.org/regauth/oui/oui.txt.

Alax.Info Replace In Files can be used to process the file to create a C/C++ compatible header file of the following format:

{ 0x00, 0x11, 0xDF, “Arecont Systems” },
//0011DF (base 16) Arecont Systems
// 177 N Church Ave suite 1010
// Tucson Arizona 85701
// UNITED STATES

{ 0x00, 0x11, 0xE0, “U-MEDIA Communications, Inc.” },
//0011E0 (base 16) U-MEDIA Communications, Inc.
// 9F, No.1, Jin-Shan 7th St.
// Hsinchu 300
// TAIWAN, REPUBLIC OF CHINA

{ 0x00, 0x11, 0xE1, “BEKO Electronics Co.” },
//0011E1 (base 16) BEKO Electronics Co.
// Beylikduzu Mevkii Buyukcekmece
// Istanbul 34901
// TURKEY


Below is the JavaScript file contents which perform the processing being invoked by console script host:

WScript.Echo("Script Name: " + WScript.ScriptFullName);
BasePath = WScript.ScriptFullName.replace(/^(.+)\\[^\\]+$/i, "$1");
FileSystemObject = WScript.CreateObject("Scripting.FileSystemObject");
WScript.Echo("Base Path: " + BasePath);

TextFile = FileSystemObject.OpenTextFile(BasePath + "\\oui.txt", 1, false, -2); // ForReading, TristateUseDefault
MemoryText = WScript.CreateObject("AlaxInfo.ReplaceInFiles.MemoryText");
MemoryText.Text = TextFile.ReadAll();

ReplaceText = WScript.CreateObject("AlaxInfo.ReplaceInFiles.ReplaceText");
ReplaceText.GlobalMatch = true;
ReplaceText.RegularExpressions = true;
ReplaceText.IgnoreCase = true;
ReplaceText.Multiline = true;
ReplaceText.FindPatterns =
"\"" + "^{[0-9A-F][0-9A-F]}\\-{[0-9A-F][0-9A-F]}\\-{[0-9A-F][0-9A-F]}\\b+\\(hex\\)\\b+{.+?}$" + "\"" + "," +
"\"" + "^{[^\\{].+}$" + "\"" + "," +
"";
ReplaceText.ReplacePatterns =
"\"" + "{ 0x\\1, 0x\\2, 0x\\3, \"\"\\4\"\" }," + "\"" + "," +
"\"" + "//\\1" + "\"" + "," +
"";
ReplaceText.Replace(MemoryText);

HeaderFile = FileSystemObject.CreateTextFile(BasePath + "\\oui.txt.h", true, false);
HeaderFile.Write(MemoryText.Text);

The script converts oui.txt into oui.txt.h file which can be then included into source code as follows:

static const struct { BYTE n0, n1, n2; LPCSTR pszName; } g_pMap[] =
{
#include "oui.txt.h"
};

Leave a Reply