File: validate_mac.tcl

package info (click to toggle)
libapache2-mod-rivet 3.2.0-1
  • links: PTS
  • area: main
  • in suites: bullseye
  • size: 5,868 kB
  • sloc: xml: 8,496; tcl: 7,212; ansic: 6,959; sh: 5,030; makefile: 261; sql: 91; lisp: 78
file content (38 lines) | stat: -rw-r--r-- 1,078 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# -- validate_mac 
#
# mac address validator to be used with the form broker 

    proc validate_mac {_mac_address_d} {
        upvar $_mac_address_d mac_address_d

        dict with mac_address_d {

            set var [string trim $var]
            if {[regexp {^[[:xdigit:]]{2}([:-][[:xdigit:]]{2}){5}$} $var]} {

                set var [string tolower $var]

                # we normalize the mac address to the Unix form.
                # The dash '-' characters in the windows representation 
                # are replaced by columns ':'

                set var [regsub -all -- {-} $var :]

                # the 'constrain' field is bidirectional:
                # it tells the validator to curb/change the value
                # within the bonds/forms/representation suitable. 
                # By setting it the validator tells the FormBroker
                # to copy the value back in the response array

                set constrain 1
                return FB_OK

            } else {

                return FB_WRONG_MAC

            }

        }
    }