Mercurial > core / lisp/lib/net/util.lisp
changeset 698: |
96958d3eb5b0 |
parent: |
7c1383c08493
|
author: |
Richard Westhaver <ellis@rwest.io> |
date: |
Fri, 04 Oct 2024 22:04:59 -0400 |
permissions: |
-rw-r--r-- |
description: |
fixes |
3 (defvar *localhost* #(127 0 0 1)) 6 (defun get-address-by-name (name) 7 "Return the address of a host by NAME." 8 (multiple-value-bind (host4 host6) 9 (get-host-by-name name) 10 (let ((addr4 (when host4 11 (car (sb-bsd-sockets::host-ent-addresses host4)))) 13 (car (sb-bsd-sockets::host-ent-addresses host6))))) 14 (values addr4 addr6)))) 16 ;; from https://github.com/eudoxia0/find-port 17 (defun port-open-p (port &key (host *localhost*)) 18 "Determine if a PORT is open on the given HOST." 20 (let ((socket (make-instance 'inet-socket :type :stream))) 21 (setf (sockopt-reuse-address socket) t) 22 (socket-bind socket host port) 23 (socket-close socket)) 24 (address-in-use-error (condition) 25 (declare (ignore condition)) 28 (defun find-port (&key (min 32000) (max 48000) (host *localhost*)) 29 "Return the first available port in a range of port numbers." 30 (loop :for port :from min :to max :when (port-open-p port :host host) :return port)) 32 ;; (get-address-by-name "localhost")