Previous: TCP Sockets, Up: Operating-System Interface


15.9 Miscellaneous OS Facilities

This section contains assorted operating-system facilities that don't fit into other categories.

— variable: microcode-id/operating-system
— variable: microcode-id/operating-system-name

microcode-id/operating-system is bound to a symbol that specifies the type of operating system that Scheme is running under. There are two possible values: unix or nt.

microcode-id/operating-system-name is a string containing the same name as microcode-id/operating-system; the latter is created by interning the former as a symbol.

— variable: microcode-id/operating-system-variant

This variable is a string that identifies the particular variant of the operating system that Scheme is running under. Here are some of the possible values:

          "GNU/Linux"
          "MacOSX"
          "Microsoft Windows NT 4.0 (Build 1381; Service Pack 3)"
     

For Windows systems, it is recommended that you match on the prefix of this string and ignore the "Build" suffix. This is because the suffix may contain information about service packs or fixes, while the prefix will be constant for a particular version of Windows.

The next few procedures provide access to the domain name service (DNS), which maintains associations between internet host names such as "www.swiss.ai.mit.edu" and IP addresses, such as 18.23.0.16. In MIT/GNU Scheme, we represent an internet host name as a string, and an IP address as a byte vector of length 4 (byte vectors are just character strings that are accessed using vector-8b-ref rather than string-ref). The bytes in an IP address read in the same order as they do when written out:

     (get-host-by-name "www.swiss") => #("\022\027\000\020")
— procedure: get-host-by-name host-name

Looks up the internet host name host-name using the DNS, returning a vector of IP addresses for the corresponding host, or #f if there is no such host. Usually the returned vector has only one element, but if a host has more than one network interface, the vector might have more than one element.

          (get-host-by-name "www.swiss") => #("\022\027\000\020")
     
— procedure: get-host-by-address ip-address

Does a reverse DNS lookup on ip-address, returning the internet host name corresponding to that address, or #f if there is no such host.

          (get-host-by-address "\022\027\000\020") => "swissnet.ai.mit.edu"
     
— procedure: canonical-host-name host-name

Finds the “canonical” internet host name for host-name. For example:

          (canonical-host-name "zurich")    => "zurich.ai.mit.edu"
          (canonical-host-name "www.swiss") => "swissnet.ai.mit.edu"
     

In both examples, the default internet domain `ai.mit.edu' is added to host-name. In the second example, "www.swiss" is an alias for another computer named "swissnet".

— procedure: get-host-name

Returns the string that identifies the computer that MIT/GNU Scheme is running on. Usually this is an unqualified internet host name, i.e. the host name without the domain suffix:

          (get-host-name) => "aarau"
     
— procedure: os/hostname

Returns the canonical internet host name of the computer that MIT/GNU Scheme is running on. So, in contrast to the example for get-host-name:

          (os/hostname) => "aarau.ai.mit.edu"
     
— procedure: allocate-host-address

Allocates and returns an IP address object. This is just a string of a fixed length (current 4 bytes) into which an IP address may be stored. This procedure is used to generate an appropriate argument to be passed to tcp-server-connection-accept.

          (allocate-host-address) => "Xe\034\241"
     
— procedure: host-address-any

Return an IP address object that specifies “any host”. This object is useful only when passed as the address argument to open-tcp-server-socket.

          (host-address-any) => "\000\000\000\000"
     
— procedure: host-address-loopback

Return an IP address object that specifies the local loopback network interface. The loopback interface is a software network interface that can be used only for communicating between processes on the same computer. This address object is useful only when passed as the address argument to open-tcp-server-socket.

          (host-address-loopback) => "\177\000\000\001"