This is hostinfo.egg.info, produced by makeinfo version 4.7 from
eggdoc-output.texi.

INFO-DIR-SECTION The Algorithmic Language Scheme
START-INFO-DIR-ENTRY
* hostinfo.egg: (hostinfo.egg).		Look up host, protocol, and service information
END-INFO-DIR-ENTRY


File: hostinfo.egg.info,  Node: Top,  Next: About this egg,  Up: (dir)

hostinfo egg
************

Look up host, protocol, and service information

Written by Zbigniew (http://3e8.org/zb)

   This manual corresponds to version 1.0 of the hostinfo extension
library for Chicken Scheme.

* Menu:

* About this egg::
* Documentation::
* Bugs::
* Examples::
* License::
* Index::


File: hostinfo.egg.info,  Node: About this egg,  Next: Documentation,  Prev: Top,  Up: Top

1 About this egg
****************

* Menu:

* Version history::
* Requirements::
* Usage::


File: hostinfo.egg.info,  Node: Version history,  Next: Requirements,  Up: About this egg

1.1 Version history
===================

`1.0'
     Initial release


File: hostinfo.egg.info,  Node: Requirements,  Next: Usage,  Prev: Version history,  Up: About this egg

1.2 Requirements
================

This egg requires the following extensions:

   `vector-lib'


File: hostinfo.egg.info,  Node: Usage,  Prev: Requirements,  Up: About this egg

1.3 Usage
=========

Load this egg like so:

   `(require-extension hostinfo)'


File: hostinfo.egg.info,  Node: Documentation,  Next: Bugs,  Prev: About this egg,  Up: Top

2 Documentation
***************

This extension performs host, protocol and service information lookups
via underlying calls to _gethostbyname(3)_, _getprotobyname(3)_, and
_getservbyname(3)_.  Depending on your system, this may consult DNS,
NIS, _/etc/hosts_, _/etc/services_, _/etc/protocols_, and so on.

   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.

   IP addresses are represented by 4 (IPv4) or 16 (IPv6) byte
`u8vectors'. The interface requires, and returns, addresses in this
format; functions are provided to convert between the string and
`u8vector' representations. However, the "do what I want" procedures
(e.g. `host-information') will do the conversion for you.

* Menu:

* Short and sweet::
* Records::
* Record lookup::
* One-stop shops::
* Utility functions::


File: hostinfo.egg.info,  Node: Short and sweet,  Next: Records,  Up: Documentation

2.1 Short and sweet
===================

Quickly perform the most common lookups.  Convenient and efficient for
one-off use, but perform a new lookup each time.  They return `#f' on
failure.

 -- procedure: hostname->ip
          (hostname->ip HOSTNAME)

     Look up string `HOSTNAME' and return IP address as `u8vector'.

 -- procedure: ip->hostname
          (ip->hostname IPADDR)

     Look up `u8vector' `IPADDR' and return hostname as string.

 -- procedure: protocol-name->number
          (protocol-name->number PROTOCOL-NAME)

     Look up string `PROTOCOL-NAME' and return protocol number.

 -- procedure: protocol-number->name
          (protocol-number->name PROTOCOL-NUMBER)

     Look up `PROTOCOL-NUMBER' and return protocol name as string.

 -- procedure: service-port->name
          (service-port->name SERVICE-PORT [PROTO])

     Look up `SERVICE-PORT' number and return service name as string.
     Optional `PROTO' argument, which must be a string, constrains
     lookup to that protocol.

 -- procedure: service-name->port
          (service-name->port SERVICE-NAME [PROTO])

     Look up string `SERVICE-NAME' and return the canonical port for
     that service.  Optional `PROTO' argument as above.


File: hostinfo.egg.info,  Node: Records,  Next: Record lookup,  Prev: Short and sweet,  Up: Documentation

2.2 Records
===========

Some lookups return a host, protocol, or service record.  These records
print nicely on the screen, for convenient interactive use.

 -- procedure: hostinfo-address
          (hostinfo-address h)

     Retrieves the `address' field of the `hostinfo' record `h'.
     Accessors are similar for other records and their fields.

 -- record: hostinfo
    `name'
          Hostname

    `addresses'
          A vector of one or more u8vector IP addresses

    `aliases'
          A vector of any alternate hostnames

    `address'
          The first IP address (u8vector) in addresses

    `type'
          'AF_INET (IPv4) or 'AF_INET6 (IPv6)

    `length'
          IP address length in bytes

 -- record: protoinfo
    `name'
          Protocol name

    `number'
          Protocol number

    `aliases'
          Vector of alternate names for this protocol

 -- record: servinfo
    `name'
          Service name

    `number'
          Service number

    `aliases'
          Vector of alternate names for this service

    `protocol'
          Name of protocol this service uses


File: hostinfo.egg.info,  Node: Record lookup,  Next: One-stop shops,  Prev: Records,  Up: Documentation

2.3 Record lookup
=================

 -- procedure: hostname->hostinfo
 -- procedure: ip->hostinfo
 -- procedure: service-name->servinfo
 -- procedure: service-port->servinfo
 -- procedure: protocol-name->protoinfo
 -- procedure: protocol-number->protoinfo
          (hostname->hostinfo NAME)
          (ip->hostinfo IPADDR)
          (service-name->servinfo NAME)
          (service-port->servinfo NUM)
          (protocol-name->protoinfo NAME)
          (protocol-number->protoinfo NUM)

     These lookups correspond to those described in _Short and sweet_,
     but return a full record.  The entire record is filled in a single
     system call.


File: hostinfo.egg.info,  Node: One-stop shops,  Next: Utility functions,  Prev: Record lookup,  Up: Documentation

2.4 One-stop shops
==================

These decipher your argument, call the appropriate lookup, and return
an information record.

 -- procedure: host-information
          (host-information HOST)

     Look up and return a hostinfo record, or `#f'. `HOST' is a string
     hostname, a string numeric IP address, or a `u8vector' IP address.

 -- procedure: protocol-information
          (protocol-information PROTO)

     Look up and return a protoinfo record, or `#f'. `PROTO' is a
     protocol number or string name.

 -- procedure: service-information
          (service-information SERVICE [PROTO])

     Look up and return a servinfo record, or `#f'. `SERVICE' is a
     service number or string name. `PROTO' is an optional protocol
     number or string name, which will constrain lookups to that
     particular protocol.

     *NOTE:* if the protocol number is illegal, an error is thrown,
     since this was probably unintentional.


File: hostinfo.egg.info,  Node: Utility functions,  Prev: One-stop shops,  Up: Documentation

2.5 Utility functions
=====================

 -- procedure: string->ip
          (string->ip IP-STRING)

     Convert an IPv4 or IPv6 address string in canonical format to a
     `u8vector', which can be considered an "IP address object".
     Returns `#f' on failure.

 -- procedure: ip->string
          (ip->string IPADDR)

     Convert a 4 (IPv4) or 16 (IPv6) element `u8vector' to a string in
     canonical format.  Throws an error if the `u8vector' is not 4 or
     16 bytes long.  This call should only fail on system error, in
     which case it will return `#f' (perhaps not the best behaviour).


File: hostinfo.egg.info,  Node: Bugs,  Next: Examples,  Prev: Documentation,  Up: Top

3 Bugs
******

IPv6 lookup is not yet supported.  However, IPv6<->string conversion
works fine.

   System errors return failure (`#f') and so are indistinguishable
from failed lookups.  They should probably signal an error or an
exception.


File: hostinfo.egg.info,  Node: Examples,  Next: License,  Prev: Bugs,  Up: Top

4 Examples
**********


(host-information "www.call-with-current-continuation.org")
(host-information '#u8(194 97 107 133))
(host-information "194.97.107.133")
   ; => #,(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


File: hostinfo.egg.info,  Node: License,  Next: Index,  Prev: Examples,  Up: Top

5 License
*********


Copyright (c) 2005, 2006 Jim "Zb" Ursetto.  All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

  Redistributions of source code must retain the above copyright notice,
  this list of conditions and the following disclaimer. Redistributions in
  binary form must reproduce the above copyright notice, this list of
  conditions and the following disclaimer in the documentation and/or
  other materials provided with the distribution. Neither the name of the
  author nor the names of its contributors may be used to endorse or
  promote products derived from this software without specific prior
  written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


File: hostinfo.egg.info,  Node: Index,  Prev: License,  Up: Top

Index
*****

 [index ]
* Menu:

* host-information:                      One-stop shops.       (line 10)
* hostinfo:                              Records.              (line 16)
* hostinfo-address:                      Records.              (line 10)
* hostname->hostinfo:                    Record lookup.        (line  7)
* hostname->ip:                          Short and sweet.      (line 11)
* ip->hostinfo:                          Record lookup.        (line  8)
* ip->hostname:                          Short and sweet.      (line 16)
* ip->string:                            Utility functions.    (line 14)
* protocol-information:                  One-stop shops.       (line 16)
* protocol-name->number:                 Short and sweet.      (line 21)
* protocol-name->protoinfo:              Record lookup.        (line 11)
* protocol-number->name:                 Short and sweet.      (line 26)
* protocol-number->protoinfo:            Record lookup.        (line 12)
* protoinfo:                             Records.              (line 35)
* service-information:                   One-stop shops.       (line 22)
* service-name->port:                    Short and sweet.      (line 38)
* service-name->servinfo:                Record lookup.        (line  9)
* service-port->name:                    Short and sweet.      (line 31)
* service-port->servinfo:                Record lookup.        (line 10)
* servinfo:                              Records.              (line 45)
* string->ip:                            Utility functions.    (line  7)



Tag Table:
Node: Top257
Node: About this egg636
Node: Version history822
Node: Requirements984
Node: Usage1188
Node: Documentation1351
Node: Short and sweet2353
Node: Records3665
Node: Record lookup4881
Node: One-stop shops5641
Node: Utility functions6707
Node: Bugs7410
Node: Examples7741
Node: License9664
Node: Index11261

End Tag Table
