guix-commits
[Top][All Lists]
Advanced

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

[dhcp] 02/03: dhcp: correct copyright in send.scm


From: Rohan Prinja
Subject: [dhcp] 02/03: dhcp: correct copyright in send.scm
Date: Wed, 10 Jun 2015 04:18:07 +0000

wenderen pushed a commit to branch master
in repository dhcp.

commit a60c0f4e88df49ccf9aeaf8d7d1f520f00508323
Author: Rohan Prinja <address@hidden>
Date:   Wed Jun 10 09:47:20 2015 +0530

    dhcp: correct copyright in send.scm
---
 dhcp/client.scm        |    7 ++--
 dhcp/dhcp.scm          |   85 +++++++++++++++++++++++------------------------
 dhcp/interfaces.scm    |   13 +++----
 dhcp/messages.scm      |   27 +++++++--------
 dhcp/options/base.scm  |    5 +--
 dhcp/options/names.scm |    3 +-
 dhcp/send.scm          |    5 +--
 7 files changed, 69 insertions(+), 76 deletions(-)

diff --git a/dhcp/client.scm b/dhcp/client.scm
index 0fa0174..ced9a40 100644
--- a/dhcp/client.scm
+++ b/dhcp/client.scm
@@ -22,12 +22,11 @@ coding: utf-8
 
 ; DHCP client module
 (define-module (dhcp client)
+  #:use-module (dhcp dhcp)
+  #:use-module (ice-9 getopt-long)
+  #:use-module (dhcp messages)
   #:export (main))
 
-(use-modules (dhcp dhcp)
-            (ice-9 getopt-long)
-            (dhcp messages))
-
 (define *help-message* "\
 dhcp-client [options]
   -v, --version    Display version
diff --git a/dhcp/dhcp.scm b/dhcp/dhcp.scm
index cee2fa1..74aed88 100644
--- a/dhcp/dhcp.scm
+++ b/dhcp/dhcp.scm
@@ -16,71 +16,70 @@
 ;;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 (define-module (dhcp dhcp)
+  #:use-module (dhcp messages)
+  #:use-module (oop goops)
+  #:use-module (rnrs base)
+  #:use-module (ice-9 regex)
+  #:use-module (srfi srfi-9)
+  #:use-module ((srfi srfi-1) #:select (find))
   #:export (<dhcp>
+           dhcp-xid set-dhcp-xid!
+           dhcp-state set-dhcp-state!
+           dhcp-tries set-dhcp-tries!
+           
            dhcp-start
            dhcp-renew
            dhcp-release
            dhcp-stop
            dhcp-inform
+           
            get-most-recent-lease
            generate-different-xid
            generate-random-xid))
 
-(use-modules (dhcp messages)
-            (oop goops)
-            (rnrs base)
-            (ice-9 regex)
-            ((srfi srfi-1) #:select (find)))
-
-; Class for DHCP objects.
-; A <dhcp> object is held by an interface, and contains
-; information about the configuration process for that
-; specific interface.
-(define-class <dhcp> ()
-  ; transaction identifier of last sent request
-  xid
-  ; number of retries for current request
-  tries
-  ; current state, see Page 34, RFC 2131 for the transition diagram
-  (state #:init-form 'DHCP-INIT
-        #:init-keyword #:state)
-  
-  t1_renew_time ; time until next renew try
-  t2_rebind_time ; time until next rebind try
-  lease_ack ; time since last DHCPACK
-  t0_timeout ; time until lease expiry
-
-  offered_ip_addr
-  offered_sn_mask
-  offered_gw_addr
-
-  offered_t0_lease
-  offered_t1_renew
-  offered_t2_rebind
-
-  (config-started-at #:init-form (current-time))
-  dhcpdiscover-sent-at)
-
-; Generate a random 32-bit number to be used as
-; a transaction id.
+;; Class for DHCP objects.
+;; A <dhcp> object is held by an interface, and contains
+;; information about the configuration process for that
+;; specific interface.
+(define-record-type <dhcp>
+  (make-dhcp xid state tries
+            t0 t1 t2
+            lease-ack
+            ip-addr sn-mask gw-addr)
+
+  dhcp?
+
+  (xid dhcp-xid set-dhcp-xid!)
+  (state dhcp-state set-dhcp-state!) ; see Page 34, RFC 2131 for the state 
transition diagram
+  (tries dhcp-tries set-dhcp-tries!) ; number of retries for current request
+
+  (t0 dhcp-t0) ; time until lease expiry
+  (t1 dhcp-t1) ; time until next renew try
+  (t2 dhcp-t2) ; time until next rebind try
+  (lease-ack dhcp-lease-ack) ; time since last DHCPACK
+
+  ;; Offered IP address, subnet mask and gateway address.
+  (ip-addr dhcp-ip-addr)
+  (sn-mask dhcp-sn-mask)
+  (gw-addr dhcp-gw-addr)
+
+  ;; Time at which configuration process was started.
+  (config-start dhcp-config-start set-dhcp-config-start!))
+
 (define (generate-random-xid)
+  "Generate a random 32-bit number to be used as
+a transaction id."
   (random (expt 2 32)))
 
 (define-method (generate-different-xid (dhcp <dhcp>))
   "Generate a new, different transaction id for
 a dhcp object. We simply increment the old one."
-  (1+ (slot-ref dhcp 'xid)))
-
-; config-start: time when config process began
-; dhcpdiscover-sent-at: time at which most recent
-; DHCPDISCOVER packet was sent
-; config-start and dhcpdiscover-sent-at are stored
-; as seconds since epoch
-
-; TODO: make a separate lease file for each interface rather than
-; logging all interfaces into the same log file. This means no "interface"
-; field in the leases file. Apart from this, the file format is the same
-; as that of dhclient. See dhclient.conf (5) for more information.
+  (1+ (dhcp-xid dhcp)))
+
+;; TODO: make a separate lease file for each interface rather than
+;; logging all interfaces into the same log file. This means no "interface"
+;; field in the leases file. Apart from this, the file format is the same
+;; as that of dhclient. See dhclient.conf (5) for more information.
 (define *leases-file* "/var/lib/dhcp/dhclient.leases")
 
 (define (parse-lease-string lease-str)
diff --git a/dhcp/interfaces.scm b/dhcp/interfaces.scm
index e1854bd..5b01e12 100644
--- a/dhcp/interfaces.scm
+++ b/dhcp/interfaces.scm
@@ -16,6 +16,12 @@
 ;;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 (define-module (dhcp interfaces)
+  #:use-module (dhcp dhcp)
+  #:use-module (system foreign)
+  #:use-module (oop goops)
+  #:use-module (guix build syscalls)
+  #:use-module (rnrs base)
+  #:use-module (rnrs bytevectors)
   #:export (<net-interface>
            hardware-address
            hardware-family
@@ -23,13 +29,6 @@
            print-hardware-address
            make-network-interface))
 
-(use-modules (dhcp dhcp)
-            (system foreign)
-            (oop goops)
-            (guix build syscalls)
-            (rnrs base)
-            (rnrs bytevectors))
-
 ;;; Taken/modified from (guix build syscalls) begin
 
 (define SIOCGIFHWADDR
diff --git a/dhcp/messages.scm b/dhcp/messages.scm
index 30261c3..84ff350 100644
--- a/dhcp/messages.scm
+++ b/dhcp/messages.scm
@@ -15,8 +15,16 @@
 ;;; You should have received a copy of the GNU General Public License
 ;;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-; Module for constructing and parsing DHCP messages
+;; Module for constructing and parsing DHCP messages
 (define-module (dhcp messages)
+  #:use-module (dhcp interfaces)
+  #:use-module (dhcp dhcp)
+  #:use-module (dhcp options base)
+  #:use-module (dhcp options names)
+  #:use-module (oop goops)
+  #:use-module (rnrs base)
+  #:use-module (rnrs bytevectors)
+  #:use-module (rnrs enums)
   #:export (<dhcp-message>
            set-broadcast-bit
            unset-broadcast-bit
@@ -27,15 +35,6 @@
            make-dhcpdiscover
            map-type-to-code))
 
-(use-modules (dhcp interfaces)
-            (dhcp dhcp)
-            (dhcp options base)
-            (dhcp options names)
-            (oop goops)
-            (rnrs base)
-            (rnrs bytevectors)
-            (rnrs enums))
-
 ; Magic cookie that starts off the 'options' field
 ; in a DHCP message packet.
 (define *magic-cookie* #vu8(99 130 83 99))
@@ -97,8 +96,8 @@ simply ignored whilst serializing."
          (if (eq? #nil opt)
              (loop (1+ i))
              (let ((code i)
-                   (len (slot-ref opt 'len))
-                   (val (slot-ref opt 'val)))
+                   (len (dhcp-option-len opt))
+                   (val (dhcp-option-val opt)))
                (begin
                  (if (zero? len)
                      (bytevector-u8-set! dst idx code)
@@ -205,14 +204,14 @@ from BV starting at index START"
 (define-method (set-option! (msg <dhcp-message>) (opt <dhcp-option>))
   "Set an <option> in a <dhcp-message>."
   (vector-set! (slot-ref msg 'options)
-              (slot-ref opt 'code)
+              (dhcp-option-code opt)
               opt))
 
 (define-method (option-value (msg <dhcp-message>) code)
   "Retrieve an option's value from a <dhcp-message>."
   (let* ((opts (slot-ref msg 'options))
         (opt (vector-ref opts code))
-        (val (slot-ref opt 'val)))
+        (val (dhcp-option-val opt)))
     val))
 
 ; Get the DHCP message type. See Section 9.6, RFC 2132.
diff --git a/dhcp/options/base.scm b/dhcp/options/base.scm
index 2391fdb..19fb41d 100644
--- a/dhcp/options/base.scm
+++ b/dhcp/options/base.scm
@@ -16,6 +16,8 @@
 ;;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 (define-module (dhcp options base)
+  #:use-module (srfi srfi-9)
+  #:use-module (rnrs bytevectors)
   #:export (<dhcp-option>
            make-dhcp-option
            dhcp-option?
@@ -23,9 +25,6 @@
            dhcp-option-len
            dhcp-option-val))
 
-(use-modules (srfi srfi-9)
-            (rnrs bytevectors))
-
 ; DHCP option object.
 ; See RFC 2132 for a list of DHCP options.
 (define-record-type <dhcp-option>
diff --git a/dhcp/options/names.scm b/dhcp/options/names.scm
index 750f884..c1838d2 100644
--- a/dhcp/options/names.scm
+++ b/dhcp/options/names.scm
@@ -16,10 +16,9 @@
 ;;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 (define-module (dhcp options names)
+  #:use-module (rnrs enums)
   #:export (map-name-to-code))
 
-(use-modules (rnrs enums))
-
 ; For the options marked UNUSED, refer to RFC 3679.
 (define *option-names*
   (make-enumeration '(PAD
diff --git a/dhcp/send.scm b/dhcp/send.scm
index f15aaee..19aa46d 100644
--- a/dhcp/send.scm
+++ b/dhcp/send.scm
@@ -1,6 +1,6 @@
 ;;; GNU Guix DHCP Client.
 ;;;
-;;; Copyright 2015 Free Software Foundation, Inc.
+;;; Copyright � 2015 Rohan Prinja <address@hidden>
 ;;;
 ;;; 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
@@ -16,13 +16,12 @@
 ;;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 (define-module (dhcp send)
+  #:use-module (rnrs bytevectors)
   #:export (make-dgram-sock
            make-broadcast-sockaddr
            *client-in-port*
            *client-out-port*))
 
-(use-modules (rnrs bytevectors))
-
 (define-syntax-rule (make-dgram-sock)
   (socket PF_INET SOCK_DGRAM IPPROTO_UDP))
 



reply via email to

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