eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'IPSocketAddress':

Home

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

Class: IPSocketAddress


Inheritance:

   Object
   |
   +--Collection
      |
      +--SequenceableCollection
         |
         +--ArrayedCollection
            |
            +--UninterpretedBytes
               |
               +--SocketAddress
                  |
                  +--IPSocketAddress
                     |
                     +--IPv6SocketAddress

Package:
stx:libbasic2
Category:
OS-Sockets
Version:
rev: 1.72 date: 2023/11/29 15:46:30
user: cg
file: IPSocketAddress.st directory: libbasic2
module: stx stc-classLibrary: libbasic2

Description:


Instances of IPSocketAddress represent tcp/ip-domain socket addresses.
These consist of an ip address (4 bytes) and a port number.

Notice that for performance, name and address translations are cached here
for some time, in order to speed up heavy lookup such as when operating a webserver or similar
application which does many address-to-hostname translations.

For systems, when the name translation is fast (unix), you may want to disable it,
as it prevents new addresses to be detected for some time (for example, if the own address
changes due to a new dhcp address being acquired).
You can also change the caching-interval time 
(see caching protocol, flush*Cache, cachingIntervalTime, *CacheSize).

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
return the anonymous address's bytes

o  anyPort
return the anon port number

o  broadcastAddress
return the broadcast address

o  firstUnreservedPort
return the first unreserved port number

o  local
return the ip address bytes of the loopback interface

o  maxPort
return the maximum port number

o  thisHost
return the bytes of IN_ADDR_ANY, the address matching any local address

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

caching
o  addressCacheAt: aHostName
retrieve a cached address for aHostName,
or nil if not in the cache

o  addressCacheAt: aName put: anAddressList
put a aHostName -> list-of-addresses into the cache

o  addressCacheSize
get the number of cached name entries.
If never set explicitly, the default is 50 names

o  addressCacheSize: aNumber
set the number of cached name entries.
If never set explicitly, the default is 50 names

o  cacheInvalidationTimeInterval
return the cache invalidation interval.
If never set explicitly, the default is 30 seconds

o  cacheInvalidationTimeInterval: seconds
set the cache invalidation interval.
If never set explicitly, the default is 30 seconds

o  flushAddressCache
self flushAddressCache

o  flushNameCache
self flushNameCache

o  nameCacheAt: aHostAddress
return a cached hostname, given a host address.
The cache is flushed after cacheInvalidationTime seconds

o  nameCacheAt: aHostAddress put: aName

o  nameCacheSize

o  nameCacheSize: aNumber

conversion
o  hostAddressFromString: aString
convert an address given in a dot notation like 123.456.78.9

Usage example(s):

     IPSocketAddress hostAddressFromString:'1.2.3.4'
     IPSocketAddress hostAddressFromString:'255.255.255.255'
     IPSocketAddress hostAddressFromString:'0xff.255.255.255'

instance creation
o  addressString: aString
convert an address given in a dot notation like '123.456.78.9'.
Handles IPv6SocketAddresses too (if the string contains more than one colon).

Usage example(s):

     IPSocketAddress addressString:'1.2.3.4'
     IPSocketAddress addressString:'1.2.3.4:22'
     IPSocketAddress addressString:'2001:4dd0:ffa3::1'
     IPSocketAddress addressString:'[2001:4dd0:ffa3::1]'
     IPSocketAddress addressString:'[2001:4dd0:ffa3::1]:22'

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.
Redefined to cache the result of the name-lookup.

Take care, this resolves to IPv4-addresses only!
Use SocketAddress to resolve to both IPv4 and IPv6-addresses.

Usage example(s):

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

     IPSocketAddress allForHostName:'localhost' serviceName:'echo' type:#datagram
     IPv6SocketAddress allForHostName:'localhost' serviceName:'echo' type:#datagram

o  hostAddress: aByteArray
(comment from inherited method)
get a new instance given addr-bytes

o  localHost
get a new instance representing the local-host address as seen internally

Usage example(s):

     self localHost
     self localHost hostName

o  localHostAddress
NO NO NEVER!
Do not use this, because:
1. It does not work on hosts that get their IP address via dhcp (at least on unix/linux)
2. Usually OperatingSystem>>#getHostName does not return a fully qualified domain name
3. This does not work well on multi-homed hosts

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

queries
o  domain
ST/X (and a few other dialects) use the define-name in the C include file
as domain symbol. VisualWorks uses other names (see vwDomainSymbol)

o  hostAddressLen
answer the number of bytes of the host address

o  isLocalHostName: aString
answer true, if aString is or resolves to a local address.
Note: all adresses in the 127 Class A network are local!

Usage example(s):

        self isLocalHostName:'127.0.0.1'
        self isLocalHostName:'127.1.2.3'
        self isLocalHostName:'127.Test'
        self isLocalHostName:'localHost'
        self isLocalHostName:'exept.de'

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

o  vwDomainSymbol
ST/X (and a few other dialects) use the define-name in the C include file
as domain symbol. VisualWorks uses another name


Instance protocol:

accessing
o  hostAddress

o  hostAddress: aByteArray
(comment from inherited method)
generic method, subclasses usually redefine this

o  port

o  port: aPortNr

comparing
o  sameHostAddress: aSocketAddress
answer true, if myself and aSocketAddress have the same host address
(but possibly different ports).

converting
o  asIPv4SocketAddress

o  asIPv6SocketAddress
convert a IPv4 address to a mapped IPv6SocketAddress

Usage example(s):

        (self localHost port:80) asIPv6SocketAddress
        (self localHost port:80) asIPv6SocketAddress asIPv4SocketAddress

obsolete
o  address

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

printing & storing
o  printAddressOn: aStream
}

Usage example(s):

     String streamContents:[:s | (IPSocketAddress hostName:'localhost') printAddressOn:s]
     (IPSocketAddress hostName:'localhost') printString
     (IPSocketAddress hostName:'localhost') hostAddress printString
     (IPSocketAddress hostName:'exeptn') printString
     (IPSocketAddress hostName:'exeptn') hostAddress printString

private
o  adrBytesStart

o  numAdrBytes

queries
o  hostName
(comment from inherited method)
(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  netmaskSize
If this is an address mask: answer the number of mask bits in the address mask

Usage example(s):

      (IPSocketAddress addressString:'255.255.0.0') netmaskSize              => 16
      (IPSocketAddress addressString:'255.255.128.0') netmaskSize            => 17
      (IPv6SocketAddress addressString:'FFFF:FFFF:FFFF:FFFF::') netmaskSize  => 16
      (IPv6SocketAddress addressString:'FFFF:FFFF:FFFF:FFF0::') netmaskSize  => 16
      (IPv6SocketAddress addressString:'F0FF:FFFF:FFFF:FFF0::') netmaskSize  => 4

o  networkAddress
THINK TWICE before using this!
This is deprecated, it doesn't make sense any longer since CIDR, subnetting and netmasks
have been introduced.

Extract and return the network part from the host address.

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

o  networkClass
THINK TWICE before using this!
This is deprecated, it doesn't make sense any longer since subnetting and netmasks
have been introduced.

Extract and return the network class (as a symbol) from the host address.
Returns one of #classA #classB #classC.

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

o  portOrName

testing
o  isBroadcast
answer true, if this is a broadcast address

Usage example(s):

        (self hostAddress:self broadcastAddress) isBroadcast

o  isIPSocketAddress

o  isIPv4SocketAddress

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

Usage example(s):

        self localHost isLocal

o  isMulticast
answer true, if this address is a multicast address 224.0.0.0/4 or Class D

o  isMyAddress
answer true, if the address refers to my own host

Usage example(s):

        (IPSocketAddress hostAddress:#[172 23 1 88] port:80) isMyAddress.
        (IPSocketAddress hostAddress:#[192 168 23 29] port:80) isMyAddress.
        (IPv6SocketAddress addressString:'2003:6A:682B:4500:A288:B4FF:FEC6:1514') isMyAddress.
        (IPv6SocketAddress addressString:'2001:6A:682B:4500:A288:B4FF:FEC6:1514') isMyAddress.



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