|
Class: IPSocketAddress
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
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).
copyrightCOPYRIGHT (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.
addressing
-
anyAddress
-
return the anonymous address's bytes
-
anyPort
-
return the anon port number
-
broadcastAddress
-
return the broadcast address
-
firstUnreservedPort
-
return the first unreserved port number
-
local
-
return the ip address bytes of the loopback interface
-
maxPort
-
return the maximum port number
-
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
-
addressCacheAt: aHostName
-
retrieve a cached address for aHostName,
or nil if not in the cache
-
addressCacheAt: aName put: anAddressList
-
put a aHostName -> list-of-addresses into the cache
-
addressCacheSize
-
get the number of cached name entries.
If never set explicitly, the default is 50 names
-
addressCacheSize: aNumber
-
set the number of cached name entries.
If never set explicitly, the default is 50 names
-
cacheInvalidationTimeInterval
-
return the cache invalidation interval.
If never set explicitly, the default is 30 seconds
-
cacheInvalidationTimeInterval: seconds
-
set the cache invalidation interval.
If never set explicitly, the default is 30 seconds
-
flushAddressCache
-
self flushAddressCache
-
flushNameCache
-
self flushNameCache
-
nameCacheAt: aHostAddress
-
return a cached hostname, given a host address.
The cache is flushed after cacheInvalidationTime seconds
-
nameCacheAt: aHostAddress put: aName
-
-
nameCacheSize
-
-
nameCacheSize: aNumber
-
conversion
-
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
-
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'
|
-
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
|
-
hostAddress: aByteArray
-
(comment from inherited method)
get a new instance given addr-bytes
-
localHost
-
get a new instance representing the local-host address as seen internally
Usage example(s):
self localHost
self localHost hostName
|
-
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
-
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)
-
hostAddressLen
-
answer the number of bytes of the host address
-
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'
|
-
obsoleteDomainSymbol
-
old ST/X domain symbol - should no longer be used; see domain
-
vwDomainSymbol
-
ST/X (and a few other dialects) use the define-name in the C include file
as domain symbol. VisualWorks uses another name
accessing
-
hostAddress
-
-
hostAddress: aByteArray
-
(comment from inherited method)
generic method, subclasses usually redefine this
-
port
-
-
port: aPortNr
-
comparing
-
sameHostAddress: aSocketAddress
-
answer true, if myself and aSocketAddress have the same host address
(but possibly different ports).
converting
-
asIPv4SocketAddress
-
-
asIPv6SocketAddress
-
convert a IPv4 address to a mapped IPv6SocketAddress
Usage example(s):
(self localHost port:80) asIPv6SocketAddress
(self localHost port:80) asIPv6SocketAddress asIPv4SocketAddress
|
obsolete
-
address
-
** This is an obsolete interface - do not use it (it may vanish in future versions) **
printing & storing
-
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
-
adrBytesStart
-
-
numAdrBytes
-
queries
-
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
-
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
|
-
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) **
-
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) **
-
portOrName
-
testing
-
isBroadcast
-
answer true, if this is a broadcast address
Usage example(s):
(self hostAddress:self broadcastAddress) isBroadcast
|
-
isIPSocketAddress
-
-
isIPv4SocketAddress
-
-
isLocal
-
answer true, if this address addresses a peer on the same host
Usage example(s):
-
isMulticast
-
answer true, if this address is a multicast address 224.0.0.0/4 or Class D
-
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.
|
|