eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'SocketAddress':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: SocketAddress


Inheritance:

   Object
   |
   +--Collection
      |
      +--SequenceableCollection
         |
         +--ArrayedCollection
            |
            +--UninterpretedBytes
               |
               +--SocketAddress
                  |
                  +--AppletalkSocketAddress
                  |
                  +--DecNetSocketAddress
                  |
                  +--IPSocketAddress
                  |
                  +--LinkSocketAddress
                  |
                  +--UDSocketAddress

Package:
stx:libbasic2
Category:
OS-Sockets
Version:
rev: 1.84 date: 2024/02/26 16:53:08
user: cg
file: SocketAddress.st directory: libbasic2
module: stx stc-classLibrary: libbasic2

Description:


Abstract superclass for subclasses implementing various IPC addressing schemes.
See concrete examples IPSocketAddress and UDSocketAddress.

ST-80 compatibility class.
This may be required when existing code has to be ported to ST/X;
however, it may not be complete and more protocol may be added in the future.
The code here was created when public domain code (Manchester) had to
be ported to ST/X and missing classes/methods were encountered, and code added
by reasoning 'what the original class could probably do there'.

This is an additional goody class; therefore:

THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTOR ``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 CONTRIBUTOR 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.

copyright

COPYRIGHT (c) 1995 by Claus Gittinger All Rights Reserved This software is furnished under a license and may be used only in accordance with the terms of that license and with the inclusion of the above copyright notice. This software may not be provided or otherwise made available to, or used by, any other person. No title to or ownership of the software is hereby transferred.

Class protocol:

addressing
o  anyAddress

** This method must be redefined in concrete classes (subclassResponsibility) **

instance creation
o  allForHostName: name
get a collection of new instances given a hostname

o  allForHostName: name port: portNr
get a collection of new instances given a hostname and port

o  allForHostName: name serviceName: portNrOrName domain: domainSymbol type: socketTypeSymbol
get a collection of new instances given a hostname, port or service and type.
Multi-homed hosts return more than one entry

Usage example(s):

     SocketAddress allForHostName:'localhost' serviceName:10 type:#stream
     SocketAddress allForHostName:'localhost' serviceName:'10' type:#stream
     IPSocketAddress allForHostName:'localhost' serviceName:'echo' type:#datagram 
     IPSocketAddress allForHostName:'localhost' serviceName:'echo' type:nil
     SocketAddress allForHostName:'google.com' serviceName:'http' type:#stream
     IPSocketAddress allForHostName:'google.com' serviceName:'http' type:nil
     IPSocketAddress allForHostName:nil serviceName:'http' type:nil

o  allForHostName: name serviceName: portNrOrName type: socketTypeSymbol
get a collection of new instances given a hostname, port or service and type.
Multi-homed hosts return more than one entry

Usage example(s):

     SocketAddress allForHostName:'localhost' serviceName:10 type:#stream
     SocketAddress allForHostName:'localhost' serviceName:'10' type:#stream
     IPSocketAddress allForHostName:'localhost' serviceName:'echo' type:#datagram 
     IPSocketAddress allForHostName:'localhost' serviceName:'echo' type:nil
     SocketAddress allForHostName:'google.com' serviceName:'http' type:#stream
     IPSocketAddress allForHostName:'google.com' serviceName:'http' type:nil

o  anyHost
get a new instance representing the ANY-host address

o  domainFromBytes: bytesArg ifUnknown: exceptionValue
extract the address family from bytes (ByteArray)

o  fromBytes: bytesArg
create a socket address from bytes (ByteArray),
returned by the primitive syscalls.
Raises an error, if the domainType is not supported by this Smalltalk
(i.e. if libbasic was compiled without support for the corresponding AF_xxx support)

o  hostAddress: addr
get a new instance given addr-bytes

Usage example(s):

     IPSocketAddress hostAddress:#[127 0 0 1]

o  hostAddress: addr port: portNr
get a new instance given addr-bytes and a portNr

o  hostName: name
get a new instance given a hostname

Usage example(s):

        self hostName:'::1'

o  hostName: name port: portNr
get a new instance given a hostname and port

o  hostName: name serviceName: portNrOrName type: socketTypeSymbol
get a new instance given a hostname, port or service and type.
Do not use this, since it does not work for multi-homed hosts

Usage example(s):

     IPSocketAddress hostName:'localhost' serviceName:10 type:#stream  
     IPSocketAddress hostName:'localhost' serviceName:'echo' type:#datagram 
     IPSocketAddress hostName:'localhost' serviceName:'echo' type:nil
     IPSocketAddress hostName:'www.google.com' serviceName:'http' type:nil
     IPSocketAddress hostName:nil serviceName:'http' type:nil
     SocketAddress allForHostName:'localhost' serviceName:10 type:#stream.
     SocketAddress allForHostName:'www.google.com' serviceName:10 type:#stream.
     SocketAddress allForHostName:nil serviceName:10 type:#stream.

o  new
IPSocketAddress new
IPv6SocketAddress new
UDSocketAddress new
AppletalkSocketAddress new

o  newDomain: domain
answer an new socket address for a given domain

Usage example(s):

    self newDomain:#afUnix    
    self newDomain:#afInet    

    self newDomain:#'AF_UNIX' 
    self newDomain:#'AF_INET' 

    self newDomain:#unix
    self newDomain:#inet

queries
o  domain
Answer the domain symbol. Subclasses redefine this

** This method must be redefined in concrete classes (subclassResponsibility) **

o  domainCode
answer the numerical domain code used in socket addresses

o  domainCodeFromName: aNameSymbol
this is a compatibility method;
VW returns the internal unix codes here - however, in ST/X,
symbols are returned, which are translated later

o  domainNameFromCode: code
this is a compatibility method;
VW expects the internal unix codes here - however, in ST/X,
symbols are expected - keeping the numeric values secret (in Socket)

** This is an obsolete interface - do not use it (it may vanish in future versions) **

o  getAddressInfo: hostNameArg serviceName: serviceName domain: domainArg type: typeArg protocol: protoArg flags: flags
answer an Array of socket addresses for serviceName on hostName
Domain, type, protocol may be nil or specify a hint for the socket
addresses to be returned.

Usage example(s):

     self getAddressInfo:'localhost' serviceName:nil 
            domain:nil type:nil protocol:nil flags:nil
     self getAddressInfo:'localhost' serviceName:nil 
            domain:#AF_INET type:#stream protocol:nil flags:nil
     self getAddressInfo:'localhost' serviceName:nil 
            domain:#AF_INET type:#stream protocol:#tcp flags:nil
     self getAddressInfo:'blurb.exept.de' serviceName:nil 
            domain:#AF_INET type:nil protocol:nil flags:nil
     self getAddressInfo:'1.2.3.4' serviceName:'6' 
            domain:#AF_INET type:nil protocol:nil flags:nil
     self getAddressInfo:'localhost' serviceName:'echo' 
            domain:#AF_INET6 type:nil protocol:nil flags:nil
     self getAddressInfo:nil serviceName:'echo' 
            domain:#AF_INET6 type:nil protocol:nil flags:nil

     self getAddressInfo:'::1' serviceName:nil 
            domain:#AF_INET6 type:#stream protocol:nil flags:nil
     self getAddressInfo:'[::1]' serviceName:nil 
            domain:#AF_INET6 type:#stream protocol:nil flags:nil

o  getAddressInfo: hostName serviceName: serviceName type: typeArg protocol: protoArg flags: flags
answer an Array of socket addresses for serviceName on hostName
Domain, type, protocol may be nil or specify a hint for the socket
addresses to be returned.

Usage example(s):

     IPSocketAddress getAddressInfo:'localhost' serviceName:nil 
                     type:nil protocol:nil flags:nil
     IPSocketAddress getAddressInfo:'localhost' serviceName:nil 
                     type:#stream protocol:nil flags:nil
     IPSocketAddress getAddressInfo:'localhost' serviceName:nil 
                     type:#stream protocol:#tcp flags:nil
     IPSocketAddress getAddressInfo:'blurb.exept.de' serviceName:nil 
                     type:nil protocol:nil flags:nil
     IPSocketAddress getAddressInfo:'1.2.3.4' serviceName:'6' 
                     type:nil protocol:nil flags:nil
     IPSocketAddress getAddressInfo:'localhost' serviceName:'echo' 
                     type:nil protocol:nil flags:nil

o  getNameInfo: socketAddress wantHostName: wantHostName wantServiceName: wantServiceName datagram: useDatagram flags: flags
answer an Array containing the hostName and/or serviceName
for a given socketAddress.

Usage example(s):

     self getNameInfo:
         (self getAddressInfo:'localhost' serviceName:'echo' 
                domain:#inet type:#stream protocol:nil flags:nil) first socketAddress
         wantHostName:true wantServiceName:true datagram:false flags:0     

o  hostAddressLen
answer the number of bytes of the host address

** This method must be redefined in concrete classes (subclassResponsibility) **

o  isAbstract
Return if this class is an abstract class.
True is returned here for myself only; false for subclasses.
Abstract subclasses must redefine this again.

o  knownClassFromCode: codeOrNr
this is a compatibility method;
VW expects the internal unix codes here - however, in ST/X,
symbols are expected - keeping the numeric values secret (in Socket)

Usage example(s):

     DomainToClassMapping := nil.

     self knownClassFromCode:#'AF_UNIX'     => UDSocketAddress
     self knownClassFromCode:#'AF_INET'     => IPSocketAddress
     self knownClassFromCode:#'AF_INET6'    => IPv6SocketAddress

     self knownClassFromCode:1              => UDSocketAddress
     self knownClassFromCode:2              => IPSocketAddress
     self knownClassFromCode:18             => LinkSocketAddress
     self knownClassFromCode:30             => IPv6SocketAddress

     obsolete ST/X codes;
     self knownClassFromCode:#unix          => UDSocketAddress   
     self knownClassFromCode:#inet          => IPSocketAddress
     self knownClassFromCode:#inet6         => IPv6SocketAddress

     visualWorks codes:
     self knownClassFromCode:#afUnix        => UDSocketAddress   
     self knownClassFromCode:#afInet        => IPSocketAddress
     self knownClassFromCode:#afInet6       => IPv6SocketAddress
     
     self knownClassFromCode:#bla           => SocketAddress

o  obsoleteDomainSymbol
old ST/X domain symbol - should no longer be used; see domain

o  peerNameFromPeer: peer

o  socketAddressSize
answer the OS specific size of a socket address.
Returns nil, if the domain is not supported or invalid.

Usage example(s):

     SocketAddress socketAddressSize  
     UDSocketAddress socketAddressSize  
     IPSocketAddress socketAddressSize  
     IPv6SocketAddress socketAddressSize 
     AppletalkSocketAddress socketAddressSize  
     DecNetSocketAddress socketAddressSize     

o  vwDomainSymbol
mhmh - actually subclassResponsibility


Instance protocol:

accessing
o  domainCode
this opaquely returns the first two bytes as a short integer;
Notice: some systems store the domainCode in those 2 bytes,
whereas others (IOS) store the size of the addr-struct in byte 1,
and the actual domain code in byte 2

o  domainCode: anInteger
this opaquely sets the first two bytes as a short integer;
Notice: some systems store the domainCode in those 2 bytes,
whereas others (IOS) store the size of the addr-struct in byte 1,
and the actual domain code in byte 2

o  hostAddress: addressBytes
generic method, subclasses usually redefine this

Usage example(s):

     IPSocketAddress hostAddress:#[193 141 12 193] port:80

o  hostAddress: addressBytes port: portNr
IPSocketAddress hostAddress:#[193 141 12 193] port:10

o  hostAddressString
answer the string representation of the address

Usage example(s):

     (IPSocketAddress hostName:'localhost') hostAddressString        => '127.0.0.1'
     (IPSocketAddress hostName:'localhost') hostName                 => 'localhost'
     (IPSocketAddress hostAddress:#[192 168 8 33]) hostAddressString => '192.168.8.33'
     (IPSocketAddress hostAddress:#[192 168 8 33]) hostName          => 'fooBar'

o  port

** This method must be redefined in concrete classes (subclassResponsibility) **

o  port: portNr

** This method must be redefined in concrete classes (subclassResponsibility) **

comparing
o  sameHostAddress: aSocketAddress
answer true, if aSocketAddres has the same hostaddress as myself

Usage example(s):

     (IPSocketAddress hostAddress:#[193 141 12 193] port:80)
        sameHostAddress:
     (IPSocketAddress hostAddress:#[193 141 12 193] port:81)

converting
o  asIPv4SocketAddressIfPossible

hashing
o  hash
generate a SmallInteger hash for the socket address - use all the bytes

printing & storing
o  displayOn: aGCOrStream
redefine from Collection

o  inspectorValueStringInListFor: anInspector
( an extension from the stx:libtool package )
returns a string to be shown in the inspector's list

o  printAddressOn: arg
raise an error: must be redefined in concrete subclass(es)

** This method must be redefined in concrete classes (subclassResponsibility) **

o  printOn: aStream
append a user printed representation of the receiver to aStream.
The format is suitable for a human - not meant to be read back.

o  printOn: aStream withPort: withPort
append a user printed representation of the receiver to aStream.
The format is suitable for a human - not meant to be read back.

o  printPortOn: aStream

private
o  fromBytes: aByteArray
Copy the internal representation of a SocketAddress to myself

This is an internal interface!

queries
o  address

** This method must be redefined in concrete classes (subclassResponsibility) **

o  domain
anwer the domain symbol used to creat a socket

o  hostName
(IPSocketAddress hostAddress:#[127 0 0 1]) hostName
(IPSocketAddress hostName:'localhost') address
(IPSocketAddress hostName:'www.google.com') address

(IPSocketAddress hostAddress:#[127 0 0 1] port:7) hostName
(IPSocketAddress hostAddress:#[172 23 1 1] port:10) hostName
(IPSocketAddress hostAddress:#[172 24 1 244]) hostName
(IPv6SocketAddress hostAddress: #[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1]) hostName
(IPv6SocketAddress hostAddress: #[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2]) hostName
(IPv6SocketAddress hostAddress: #[0 0 0 0 0 0 0 0 0 0 255 255 127 0 0 1]) hostName
(IPv6SocketAddress hostAddress: #[0 0 0 0 0 0 0 0 0 0 255 255 172 23 1 1]) hostName

o  hostNameOrAddressString
answer the host name or the string representation
of the address

Usage example(s):

     (IPSocketAddress hostName:'localhost') hostNameOrAddressString         => 'localhost'
     (IPSocketAddress hostAddress:#[192 168 8 33]) hostNameOrAddressString  => '192.168.8.33'

o  portOrName

** This method must be redefined in concrete classes (subclassResponsibility) **

o  serviceName
(IPSocketAddress hostAddress:#[127 0 0 1] port:7) serviceName
(IPSocketAddress hostAddress:#[193 141 12 193] port:10) serviceName

testing
o  isIPSocketAddress

o  isIPv4SocketAddress

o  isIPv6SocketAddress

o  isLocal
answer true, if this address addresses a peer on the same host

** This method must be redefined in concrete classes (subclassResponsibility) **

o  isMyAddress
answer true, if the address refers to my own host.
Subclasses may redefine this to check the local configuration, too.

o  isSocketAddress



ST/X 7.7.0.0; WebServer 1.702 at 20f6060372b9.unknown:8081; Mon, 18 Nov 2024 04:25:17 GMT