-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Lots more readability courtesy of nigeltao.
- Loading branch information
Showing
8 changed files
with
135 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Copyright (c) 2012 Google, Inc. All rights reserved. | ||
|
||
// +build ignore | ||
|
||
// Package gopacket_mac_fetcher is a binary that pulls the list of known MAC | ||
// prefixes from IEEE and writes them out to a go file which is compiled | ||
// into gopacket. It should be run as follows: | ||
// | ||
// go run gen.go | gofmt > valid_mac_prefixes.go | ||
package main | ||
|
||
import ( | ||
"bufio" | ||
"encoding/hex" | ||
"flag" | ||
"io" | ||
"fmt" | ||
"net/http" | ||
"os" | ||
"regexp" | ||
"time" | ||
) | ||
|
||
const header = `// Copyright (c) 2012 Google, Inc. All rights reserved. | ||
package gopacket | ||
// Created by gopacket_mac_fetcher, don't edit manually | ||
// Generated at %s | ||
// Fetched from %q | ||
// ValidMACPrefixMap maps a valid MAC address prefix to the name of the | ||
// organization that owns the rights to use it. We map it to a hidden | ||
// variable so it won't show up in godoc, since it's a very large map. | ||
var ValidMACPrefixMap = validMACPrefixMap | ||
var validMACPrefixMap = map[[3]byte]string{ | ||
` | ||
|
||
var url = flag.String("url", "http://standards.ieee.org/develop/regauth/oui/oui.txt", "URL to fetch MACs from") | ||
|
||
func main() { | ||
fmt.Fprintf(os.Stderr, "Fetching MACs from %q\n", *url) | ||
resp, err := http.Get(*url) | ||
if err != nil { | ||
panic(err) | ||
} | ||
defer resp.Body.Close() | ||
buffered := bufio.NewReader(resp.Body) | ||
finder := regexp.MustCompile(`^([0-9A-F]{6})\s+\(base 16\)\s+(.*)`) | ||
fmt.Fprintln(os.Stderr, "Starting write to standard output") | ||
fmt.Printf(header, time.Now(), *url); | ||
for { | ||
line, err := buffered.ReadString('\n') | ||
if err == io.EOF { | ||
break | ||
} else if err != nil { | ||
panic(err) | ||
} | ||
if matches := finder.FindStringSubmatch(line); matches != nil { | ||
bytes := make([]byte, 3) | ||
hex.Decode(bytes, []byte(matches[1])) | ||
company := matches[2] | ||
if company == "" { | ||
company = "PRIVATE" | ||
} | ||
fmt.Printf("\t[3]byte{%d, %d, %d}: %q,\n", bytes[0], bytes[1], bytes[2], company) | ||
} | ||
} | ||
fmt.Println("}") | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters