guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[dhcp] 01/12: dhcp: arp hardware address identifiers


From: Rohan Prinja
Subject: [dhcp] 01/12: dhcp: arp hardware address identifiers
Date: Sat, 06 Jun 2015 18:16:54 +0000

wenderen pushed a commit to branch master
in repository dhcp.

commit e733ce56eba2e7955c6c9ccaedf83f13ac331626
Author: Rohan Prinja <address@hidden>
Date:   Tue Jun 2 22:53:59 2015 +0530

    dhcp: arp hardware address identifiers
---
 arp/identifiers.scm       |   87 +++++++++++++++++++++++++++++++++++++++++++++
 tests/arp-identifiers.scm |   36 ++++++++++++++++++
 2 files changed, 123 insertions(+), 0 deletions(-)

diff --git a/arp/identifiers.scm b/arp/identifiers.scm
new file mode 100644
index 0000000..bbe9453
--- /dev/null
+++ b/arp/identifiers.scm
@@ -0,0 +1,87 @@
+;;; GNU Guix DHCP Client.
+;;;
+;;; Copyright 2015 Free Software Foundation, Inc.
+;;;
+;;; This program is free software; you can redistribute it and/or modify it
+;;; under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation; either version 3 of the License, or (at
+;;; your option) any later version.
+;;;
+;;; This program is distributed in the hope that it will be useful, but
+;;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;;; GNU General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+; ARP protocol HARDWARE identifiers.
+; Taken from <linux/if_arp.h>
+(define-module (arp identifiers)
+  #:export (ARPHRD_NETROM
+           ARPHRD_ETHER
+           ARPHRD_EETHER
+           ARPHRD_AX25
+           ARPHRD_PRONET
+           ARPHRD_CHAOS
+           ARPHRD_IEEE802
+           ARPHRD_ARCNET
+           ARPHRD_APPLETLK
+           ARPHRD_DLCI
+           ARPHRD_ATM
+           ARPHRD_METRICOM
+           ARPHRD_IEEE1394
+           ARPHRD_EUI64
+           ARPHRD_INFINIBAND
+
+           map-code-to-ident))
+
+(use-modules (rnrs enums)
+            ((srfi srfi-1) #:select (find)))
+
+; Define IDENT to have value VAL on GNU/Linux systems,
+; and -1 elsewhere (for now).
+(define-syntax-rule (identifier-value ident val)
+  (define ident
+    (if (string-contains %host-type "linux") val -1)))
+
+(identifier-value ARPHRD_NETROM 0)
+(identifier-value ARPHRD_ETHER 1)
+(identifier-value ARPHRD_EETHER 2)
+(identifier-value ARPHRD_AX25 3)
+(identifier-value ARPHRD_PRONET 4)
+(identifier-value ARPHRD_CHAOS 5)
+(identifier-value ARPHRD_IEEE802 6)
+(identifier-value ARPHRD_ARCNET 7)
+(identifier-value ARPHRD_APPLETLK 8)
+(identifier-value ARPHRD_DLCI 15)
+(identifier-value ARPHRD_ATM 19)
+(identifier-value ARPHRD_METRICOM 23)
+(identifier-value ARPHRD_IEEE1394 24)
+(identifier-value ARPHRD_EUI64 27)
+(identifier-value ARPHRD_INFINIBAND 32)
+
+(define *arp-hardware-identifiers*
+  '((ARPHRD_NETROM . 0)
+    (ARPHRD_ETHER . 1)
+    (ARPHRD_EETHER . 2)
+    (ARPHRD_AX25 . 3)
+    (ARPHRD_PRONET . 4)
+    (ARPHRD_CHAOS . 5)
+    (ARPHRD_IEEE802 . 6)
+    (ARPHRD_ARCNET . 7)
+    (ARPHRD_APPLETLK . 8)
+    (ARPHRD_DLCI . 15)
+    (ARPHRD_ATM . 19)
+    (ARPHRD_METRICOM . 23)
+    (ARPHRD_IEEE1394 . 24)
+    (ARPHRD_EUI64 . 27)
+    (ARPHRD_INFINIBAND . 32)))
+
+; Given an integer CODE return the corresponding ARP
+; hardware types as a symbol. This is needed because
+; there are "gaps", for example there is no ARP h/w
+; type for each of the integer values 9 through 14.
+(define (map-code-to-ident code)
+  (car (find (lambda (pair) (= (cdr pair) code))
+            *arp-hardware-identifiers*)))
diff --git a/tests/arp-identifiers.scm b/tests/arp-identifiers.scm
new file mode 100644
index 0000000..e8f1d50
--- /dev/null
+++ b/tests/arp-identifiers.scm
@@ -0,0 +1,36 @@
+;;; GNU Guix DHCP Client.
+;;;
+;;; Copyright 2015 Free Software Foundation, Inc.
+;;;
+;;; This program is free software; you can redistribute it and/or modify it
+;;; under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation; either version 3 of the License, or (at
+;;; your option) any later version.
+;;;
+;;; This program is distributed in the hope that it will be useful, but
+;;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;;; GNU General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+(add-to-load-path (string-append (dirname (current-filename))
+                                "/.."))
+
+(define-module (test-arp-identifiers))
+
+(use-modules (srfi srfi-64)
+            (arp identifiers))
+
+(test-begin "arp-identifiers")
+
+(test-eq "idempotence"
+        'ARPHRD_IEEE1394
+        (map-code-to-ident ARPHRD_IEEE1394))
+
+(test-equal "correct-mapping" ARPHRD_ETHER 1)
+
+(test-end)
+
+(exit (zero? (test-runner-fail-count (test-runner-current))))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]