(use eggdoc) (include "eggdoc-zb.scm") (define examples `((pre #< #,(hostinfo name: "www003.lifemedien.de" ; addresses: #(#u8(194 97 107 133)) ; aliases: #("www.call-with-current-continuation.org")) (ip->hostname '#u8(194 97 107 133)) ; "www003.lifemedien.de" (string->ip "0708::0901") ; #u8(7 8 0 0 0 0 0 0 0 0 0 0 0 0 9 1) (ip->string '#u8(127 0 0 1)) ; "127.0.0.1" (hostinfo-aliases (hostname->hostinfo (ip->hostname (hostname->ip (hostinfo-name (host-information "www.call-with-current-continuation.org")))))) ; => #("www.call-with-current-continuation.org") (protocol-information 17) ; => #,(protoinfo name: "udp" number: 17 aliases: #("UDP")) (protoinfo-name (protocol-information 2)) ; => "igmp" (protoinfo-aliases (protocol-name->protoinfo (protocol-number->name (protoinfo-number (protocol-information "ospf"))))) ; => #("OSPFIGP") (protocol-name->number "OSPFIGP") ; 89 (you can look up aliases, too) (servinfo-protocol (service-name->servinfo (service-port->name (servinfo-port (service-information "ssh"))))) ; => "udp" (yes, really) (service-information "ssh" "tcp") ; => #,(servinfo name: "ssh" port: 22 aliases: #() protocol: "tcp") (service-information "ssh" "tco") ; => #f (service-information 512 "tcp") ; #,(servinfo name: "exec" port: 512 aliases: #() protocol: "tcp") (service-information 512 "udp") ; #,(servinfo name: "comsat" port: 512 aliases: #("biff") protocol: "udp") (service-information 512 17) ; same as previous (service-information 512 170000) ; Error: (service-information) illegal protocol number: 170000 EOF ))) (define doc `((eggdoc:begin (name "hostinfo") (description "Look up host, protocol, and service information") (author (a (@ (href ,zbigniew-homepage)) "Zbigniew")) (history (version "1.1" "Experimental Windows support [Daishi Kato]") (version "1.0" "Initial release")) (requires "vector-lib") (usage) (download "hostinfo.scm") (documentation (p "This extension performs host, protocol and service information lookups via underlying calls to " (i "gethostbyname(3)") ", " (i "getprotobyname(3)") ", and " (i "getservbyname(3)") ". Depending on your system, this may consult DNS, NIS, " (i "/etc/hosts") ", " (i "/etc/services") ", " (i "/etc/protocols") ", and so on.") (p "A simple interface is provided for the most commmon queries. Also provided is a more comprehensive interface using records, which contain all data available in a lookup.") (p "IP addresses are represented by 4 (IPv4) or 16 (IPv6) byte " (tt "u8vectors") ". " "The interface requires, and returns, addresses in this format; functions are provided to convert between the string and " (tt "u8vector") " representations. " "However, the \"do what I want\" procedures (e.g. " (tt "host-information") ") will do the conversion for you.") ;;; SHORT AND SWEET (subsection "Short and sweet" (p "Quickly perform the most common lookups. Convenient and efficient for one-off use, but perform a new lookup each time. They return " (tt "#f") " on failure.") (group (procedure "(hostname->ip HOSTNAME)" "Look up string " (tt "HOSTNAME") " and return IP address as " (tt "u8vector") ".") (procedure "(ip->hostname IPADDR)" (p "Look up " (tt "u8vector") " " (tt "IPADDR") " and return hostname as string.")) (procedure "(protocol-name->number PROTOCOL-NAME)" (p "Look up string " (tt "PROTOCOL-NAME") " and return protocol number.")) (procedure "(protocol-number->name PROTOCOL-NUMBER)" (p "Look up " (tt "PROTOCOL-NUMBER") " and return protocol name as string.")) (procedure "(service-port->name SERVICE-PORT [PROTO])" (p "Look up " (tt "SERVICE-PORT") " number and return service name as string. " "Optional "(tt "PROTO") " argument, which must be a string, constrains lookup to that protocol.")) (procedure "(service-name->port SERVICE-NAME [PROTO])" (p "Look up string " (tt "SERVICE-NAME") " and return the canonical port for that service. Optional " (tt "PROTO") " argument as above.")))) ;;; RECORDS (subsection "Records" (p "Some lookups return a host, protocol, or service record. These records print nicely on the screen, for convenient interactive use.") (group (procedure "(hostinfo-address h)" (p "Retrieves the " (tt "address") " field of the " (tt "hostinfo") " record " (tt "h") ". " "Accessors are similar for other records and their fields.")) (record "hostinfo" (symbol-table (describe "name" "Hostname") (describe "addresses" "A vector of one or more u8vector IP addresses") (describe "aliases" "A vector of any alternate hostnames") (describe "address" "The first IP address (u8vector) in addresses") (describe "type" "'AF_INET (IPv4) or 'AF_INET6 (IPv6)") (describe "length" "IP address length in bytes"))) (record "protoinfo" (symbol-table (describe "name" "Protocol name") (describe "number" "Protocol number") (describe "aliases" "Vector of alternate names for this protocol"))) (record "servinfo" (symbol-table (describe "name" "Service name") (describe "number" "Service number") (describe "aliases" "Vector of alternate names for this service") (describe "protocol" "Name of protocol this service uses"))))) ;;; RECORD LOOKUP (subsection "Record lookup" (group (definition (signatures (signature "procedure" "(hostname->hostinfo NAME)") (signature "procedure" "(ip->hostinfo IPADDR)") (signature "procedure" "(service-name->servinfo NAME)") (signature "procedure" "(service-port->servinfo NUM)") (signature "procedure" "(protocol-name->protoinfo NAME)") (signature "procedure" "(protocol-number->protoinfo NUM)")) (p "These lookups correspond to those described in " (i "Short and sweet") ", " "but return a full record. The entire record is filled in a single system call.")))) ;;; ONE STOP SHOPS (subsection "One-stop shops" (p "These decipher your argument, call the appropriate lookup, and return an information record.") (group (procedure "(host-information HOST)" (p "Look up and return a hostinfo record, or " (tt "#f") ". " (tt "HOST") " is a string hostname, a string numeric IP address, or a " (tt "u8vector") " IP address.")) (procedure "(protocol-information PROTO)" (p "Look up and return a protoinfo record, or " (tt "#f") ". " (tt "PROTO") " is a protocol number or string name.")) (procedure "(service-information SERVICE [PROTO])" (p "Look up and return a servinfo record, or " (tt "#f") ". " (tt "SERVICE") " is a service number or string name. " (tt "PROTO") " is an optional protocol number or string name, which will constrain " "lookups to that particular protocol. ") (p (b "NOTE:") " if the protocol number is illegal, an error is thrown, " "since this was probably unintentional.")))) ;;; UTILITIES (subsection "Utility functions" (group (procedure "(string->ip IP-STRING)" (p "Convert an IPv4 or IPv6 address string in canonical format to a " (tt "u8vector") ", which can be considered an \"IP address object\". Returns " (tt "#f") " on failure.")) (procedure "(ip->string IPADDR)" (p "Convert a 4 (IPv4) or 16 (IPv6) element " (tt "u8vector") " to a string in canonical format. Throws an error if the " (tt "u8vector") " is not 4 or 16 bytes long. This call should only fail on system error, in which case it will return " (tt "#f") " (perhaps not the best behaviour)."))))) (section "Bugs" (p "IPv6 lookup is not yet supported. However, IPv6<->string conversion works fine.") (p "System errors return failure (" (tt "#f") ") and so are indistinguishable from failed lookups. They should probably signal an error or an exception.")) (examples ,examples) ;;; Note: license sets id=license. Perhaps sections should do this automatically. (license ,licenses:zbigniew-bsd)))) #| ;; For REPL use (with-output-to-file "~/scheme/html/eggdoc-sxslt/hostinfo.html" (lambda () (eggdoc->html doc))) |# (eggdoc->html doc)