Previous: , Up: linux   [Index]


7.10 Ethernet address manipulation routines

Some of the following functions act upon the system file /etc/ethers; such file may not be present in all the GNU+Linux installations, but it is quite easy to create one; (*manpages*)Ethernet address to IP number database. Notice that the address of an Ethernet interface can be found in the output of the command:

$ /usr/sbin/ip address

The following bindings are exported by the library (vicare linux).

Function: ether-ntoa ether-addr-bv
Function: ether-ntoa-r ether-addr-bv

Interfaces to the C functions ether_ntoa() and ether_ntoa_r(), (*manpages*)ether_ntoa. Convert a bytevector holding a struct ether_addr into the string representation of the address. If successful return a bytevector holding the ASCIIZ string representing the address; else raise an exception.

Function: ether-ntoa/string ether-addr-bv
Function: ether-ntoa-r/string ether-addr-bv

Like ether-ntoa and ether-ntoa-r, but return a Scheme string.

(import (vicare)
  (prefix (vicare linux) lx.))

(define-constant eth0.str "20:6a:8a:f6:b5:ed")

(lx.ether-ntoa/string (lx.ether-aton eth0.str #f))
⇒ "20:6a:8a:f6:b5:ed"
Function: ether-aton addr.str addr.len
Function: ether-aton-r addr.str addr.len

Interfaces to the C functions ether_aton() and ether_aton_r(), (*manpages*)ether_ntoa. Convert a string representing an Ethernet address into a struct ether_addr. If successful return a bytevector holding the C structure, otherwise raise an exception.

The arguments addr.str and addr.len must represent a generalised C ASCIIZ string, (vicare-libs)Introduction to generalised C strings.

Function: ether-ntohost ether-addr-bv

Interface to the C function ether_ntohost(), (*manpages*)ether_ntohost. Convert a bytevector holding a struct ether_addr into the corresponding hostname string found in the file /etc/ethers. If successful return a bytevector holding the ASCIIZ string representing the address; else raise an exception.

Function: ether-ntohost/string ether-addr-bv

Like ether-ntohost, but return a Scheme string.

(import (vicare)
  (prefix (vicare linux) lx.))

(define-constant eth0.str "20:6a:8a:f6:b5:ed")

;;Assuming "/etc/ethers" contains:
;;
;; 20:6a:8a:f6:b5:ed	localhost
;;
(lx.ether-ntohost/string (lx.ether-aton eth0.str #f))
⇒ "localhost"
Function: ether-hostton hostname.str hostname.len

Interface to the C function ether_hostton(), (*manpages*)ether_hostton. Convert a string representing a hostname address into the corresponding address in found in the file /etc/ethers, represented as struct ether_addr. If successful return a bytevector holding the C structure, otherwise raise an exception.

The arguments hostname.str and hostname.len must represent a generalised C ASCIIZ string, (vicare-libs)Introduction to generalised C strings.

(import (vicare)
  (prefix (vicare linux) lx.))

;;Assuming "/etc/ethers" contains:
;;
;; 20:6a:8a:f6:b5:ed	localhost
;;
(lx.ether-ntoa/string (lx.ether-hostton "localhost" #f))
⇒ "20:6a:8a:f6:b5:ed"
Function: ether-line line.str line.len

Interface to the C function ether_line(), (*manpages*)ether_line. Parse a string representing a line in the format of the file /etc/ethers. If successful return 2 values: a bytevector representing a struct ether_addr and a bytevector representing the hostname as ASCIIZ string; else raise an exception.

The arguments line.str and line.len must represent a generalised C ASCIIZ string, (vicare-libs)Introduction to generalised C strings.

Function: ether-line/string line.str line.len

Like ether-line, but, when successful, return a Scheme string as second value.

(import (vicare)
  (prefix (vicare linux) lx.))

(receive (addr hostname)
    (lx.ether-line/string "20:6a:8a:f6:b5:ed localhost" #f)
  (list (lx.ether-ntoa/string addr) hostname))
⇒ ("20:6a:8a:f6:b5:ed" "localhost")

Previous: , Up: linux   [Index]