3 ;;; System-specific functions
5 ;;; (c) 2008 Straylight/Edgeware
8 ;;;----- Licensing notice ---------------------------------------------------
10 ;;; This program is free software; you can redistribute it and/or modify
11 ;;; it under the terms of the GNU General Public License as published by
12 ;;; the Free Software Foundation; either version 2 of the License, or
13 ;;; (at your option) any later version.
15 ;;; This program is distributed in the hope that it will be useful,
16 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;;; GNU General Public License for more details.
20 ;;; You should have received a copy of the GNU General Public License
21 ;;; along with this program; if not, write to the Free Software Foundation,
22 ;;; Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 ;;;--------------------------------------------------------------------------
27 ;;; Functions provided.
30 (cffi:defcfun gethostname :int
36 "Return the hostname (not necessarily canonical) of the current host."
39 (unix:unix-gethostname)
42 (sb-unix:unix-gethostname)
45 (os:uname-nodename (os:uname))
48 (cffi:with-foreign-pointer-as-string (buffer 256 len)
49 (let ((rc (gethostname buffer len)))
51 (error "gethostname(2) failed (rc = ~A)." rc))))
53 #-(or cmu sbcl clisp ecl)
56 (export 'resolve-hostname)
57 (defun resolve-hostname (name)
58 "Resolve a hostname to an IP address using the DNS, or return nil."
61 (let ((he (ext:lookup-host-entry name)))
62 (and he (ext:host-entry-addr he)))
66 (let* ((he (sb-bsd-sockets:get-host-by-name name))
67 (addr (sb-bsd-sockets:host-ent-address he)))
68 (reduce (lambda (acc byte) (logior (ash acc 8) byte)) addr))
69 (sb-bsd-sockets:name-service-error () nil))
72 (let ((he (ext:resolve-host-ipaddr name)))
73 (and he (string-ipaddr (car (ext:hostent-addr-list he)))))
76 (nth-value 2 (ext:lookup-host-entry name))
78 #-(or cmu sbcl clisp ecl)
81 (export 'canonify-hostname)
82 (defun canonify-hostname (name)
83 "Resolve a hostname to canonical form using the DNS, or return nil."
86 (let ((he (ext:lookup-host-entry name)))
87 (and he (ext:host-entry-name he)))
91 (let ((he (sb-bsd-sockets:get-host-by-name name)))
92 (sb-bsd-sockets:host-ent-name he))
93 (sb-bsd-sockets:name-service-error () nil))
96 (let ((he (ext:resolve-host-ipaddr name)))
97 (and he (ext:hostent-name he)))
100 (nth-value 0 (ext:lookup-host-entry name))
102 #-(or cmu sbcl clisp ecl)
105 ;;;----- That's all, folks --------------------------------------------------