|
Class: SocketAddress
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
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.
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
-
** This method must be redefined in concrete classes (subclassResponsibility) **
instance creation
-
allForHostName: name
-
get a collection of new instances given a hostname
-
allForHostName: name port: portNr
-
get a collection of new instances given a hostname and port
-
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
|
-
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
|
-
anyHost
-
get a new instance representing the ANY-host address
-
domainFromBytes: bytesArg ifUnknown: exceptionValue
-
extract the address family from bytes (ByteArray)
-
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)
-
hostAddress: addr
-
get a new instance given addr-bytes
Usage example(s):
IPSocketAddress hostAddress:#[127 0 0 1]
|
-
hostAddress: addr port: portNr
-
get a new instance given addr-bytes and a portNr
-
hostName: name
-
get a new instance given a hostname
Usage example(s):
-
hostName: name port: portNr
-
get a new instance given a hostname and port
-
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.
|
-
new
-
IPSocketAddress new
IPv6SocketAddress new
UDSocketAddress new
AppletalkSocketAddress new
-
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
-
domain
-
Answer the domain symbol. Subclasses redefine this
** This method must be redefined in concrete classes (subclassResponsibility) **
-
domainCode
-
answer the numerical domain code used in socket addresses
-
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
-
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) **
-
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
|
-
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
|
-
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
|
-
hostAddressLen
-
answer the number of bytes of the host address
** This method must be redefined in concrete classes (subclassResponsibility) **
-
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.
-
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
|
-
obsoleteDomainSymbol
-
old ST/X domain symbol - should no longer be used; see domain
-
peerNameFromPeer: peer
-
-
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
|
-
vwDomainSymbol
-
mhmh - actually subclassResponsibility
accessing
-
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
-
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
-
hostAddress: addressBytes
-
generic method, subclasses usually redefine this
Usage example(s):
IPSocketAddress hostAddress:#[193 141 12 193] port:80
|
-
hostAddress: addressBytes port: portNr
-
IPSocketAddress hostAddress:#[193 141 12 193] port:10
-
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'
|
-
port
-
** This method must be redefined in concrete classes (subclassResponsibility) **
-
port: portNr
-
** This method must be redefined in concrete classes (subclassResponsibility) **
comparing
-
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
-
asIPv4SocketAddressIfPossible
-
hashing
-
hash
-
generate a SmallInteger hash for the socket address - use all the bytes
printing & storing
-
displayOn: aGCOrStream
-
redefine from Collection
-
inspectorValueStringInListFor: anInspector
( an extension from the stx:libtool package )
-
returns a string to be shown in the inspector's list
-
printAddressOn: arg
-
raise an error: must be redefined in concrete subclass(es)
** This method must be redefined in concrete classes (subclassResponsibility) **
-
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.
-
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.
-
printPortOn: aStream
-
private
-
fromBytes: aByteArray
-
Copy the internal representation of a SocketAddress to myself
This is an internal interface!
queries
-
address
-
** This method must be redefined in concrete classes (subclassResponsibility) **
-
domain
-
anwer the domain symbol used to creat a socket
-
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
-
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'
|
-
portOrName
-
** This method must be redefined in concrete classes (subclassResponsibility) **
-
serviceName
-
(IPSocketAddress hostAddress:#[127 0 0 1] port:7) serviceName
(IPSocketAddress hostAddress:#[193 141 12 193] port:10) serviceName
testing
-
isIPSocketAddress
-
-
isIPv4SocketAddress
-
-
isIPv6SocketAddress
-
-
isLocal
-
answer true, if this address addresses a peer on the same host
** This method must be redefined in concrete classes (subclassResponsibility) **
-
isMyAddress
-
answer true, if the address refers to my own host.
Subclasses may redefine this to check the local configuration, too.
-
isSocketAddress
-
|