IPSocketAddress.st
author Claus Gittinger <cg@exept.de>
Wed, 09 Jul 2003 16:26:27 +0200
changeset 1259 0a557e59ea4a
parent 1233 999feaf57b80
child 1261 ce4c9f258766
permissions -rw-r--r--
instance creation refactored (dispatch from Socket via peerFromDomain:name:port:)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
100
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     1
"
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     2
 COPYRIGHT (c) 1995 by Claus Gittinger
1164
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
     3
	      All Rights Reserved
100
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     5
 This software is furnished under a license and may be used
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
 hereby transferred.
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
"
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    12
1023
12bc2a0f60b5 + bytesToName:
Claus Gittinger <cg@exept.de>
parents: 818
diff changeset
    13
"{ Package: 'stx:libbasic2' }"
12bc2a0f60b5 + bytesToName:
Claus Gittinger <cg@exept.de>
parents: 818
diff changeset
    14
818
2f8331ad12d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
    15
SocketAddress variableByteSubclass:#IPSocketAddress
1164
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
    16
	instanceVariableNames:''
1233
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    17
	classVariableNames:'NameCache AddrCache'
488
b0c17a5ff8ea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 113
diff changeset
    18
	poolDictionaries:''
816
489e7876ab3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 799
diff changeset
    19
	category:'OS-Sockets'
100
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
!
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
!IPSocketAddress class methodsFor:'documentation'!
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
copyright
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
"
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
 COPYRIGHT (c) 1995 by Claus Gittinger
1164
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
    27
	      All Rights Reserved
100
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    28
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    29
 This software is furnished under a license and may be used
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
 only in accordance with the terms of that license and with the
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
 inclusion of the above copyright notice.   This software may not
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
 be provided or otherwise made available to, or used by, any
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
 other person.  No title to or ownership of the software is
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
 hereby transferred.
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
"
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
!
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    38
documentation
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
"
111
92392ae9a0f0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 100
diff changeset
    40
    Instances of IPSocketAddress represent tcp/ip-domain socket addresses.
92392ae9a0f0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 100
diff changeset
    41
    These consist of an ip address (4 bytes) and a port number.
92392ae9a0f0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 100
diff changeset
    42
100
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    43
    ST-80 compatibility class.
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    44
    This may be required when existing code has to be ported to ST/X;
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    45
    however, it may not be complete and more protocol may be added in the future.
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    46
    The code here was created when public domain code (Manchester) had to
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    47
    be ported to ST/X and missing classes/methods were encountered, and code added
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    48
    by reasoning 'what the original class could probably do there'.
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    49
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    50
    This is an additional goody class; therefore:
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    51
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    52
    THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTOR ``AS IS'' AND
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    53
    ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    54
    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    55
    ARE DISCLAIMED.  IN NO EVENT SHALL THE CONTRIBUTOR BE LIABLE
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    56
    FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    57
    DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    58
    OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    59
    HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    60
    LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    61
    OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    62
    SUCH DAMAGE.
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    63
"
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    64
! !
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    65
1233
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    66
!IPSocketAddress class methodsFor:'instance creation'!
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    67
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    68
hostName:name serviceName:portNrOrName type:socketTypeSymbol
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    69
    "get a new instance given a hostname, port or service and type"
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    70
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    71
    |addrBytes sa|
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    72
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    73
    portNrOrName isString ifTrue:[
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    74
        ^ super hostName:name serviceName:portNrOrName type:socketTypeSymbol
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    75
    ].
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    76
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    77
    AddrCache notNil ifTrue:[
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    78
        addrBytes := AddrCache at:name ifAbsent:nil.
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    79
    ].
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    80
    addrBytes notNil ifTrue:[
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    81
        sa := self hostAddress:addrBytes.
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    82
        portNrOrName notNil ifTrue:[
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    83
            sa port:portNrOrName.
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    84
        ].
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    85
    ] ifFalse:[
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    86
        sa := super hostName:name serviceName:portNrOrName type:socketTypeSymbol.
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    87
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    88
        (AddrCache isNil or:[AddrCache size > 30]) ifTrue:[
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    89
            AddrCache := Dictionary new
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    90
        ].
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    91
        AddrCache at:name put:(sa hostAddress).
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    92
    ].
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    93
    ^ sa
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    94
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    95
    "
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    96
     SocketAddress hostName:'localhost' serviceName:10 type:#stream
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    97
     IPSocketAddress hostName:'localhost' serviceName:'echo' type:#datagram 
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    98
     IPSocketAddress hostName:'localhost' serviceName:'echo' type:nil
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    99
    "
1259
0a557e59ea4a instance creation refactored
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   100
!
0a557e59ea4a instance creation refactored
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   101
0a557e59ea4a instance creation refactored
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   102
peerName:peerName port:port
0a557e59ea4a instance creation refactored
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   103
    ^ self hostAddress:(Socket ipAddressOfHost:peerName) port:port
1233
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   104
! !
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   105
1164
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   106
!IPSocketAddress class methodsFor:'addressing'!
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   107
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   108
anyAddress
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   109
    "return the broadcast address"
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   110
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   111
    ^ #[255 255 255 255]
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   112
!
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   113
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   114
anyPort
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   115
    "return the anon port number"
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   116
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   117
    ^ 0
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   118
!
100
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   119
1164
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   120
firstUnreservedPort
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   121
    "return the first unreserved port number"
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   122
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   123
    ^ 1024
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   124
!
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   125
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   126
local
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   127
    "return IN_ADDR_ANY, the address matching any local address"
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   128
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   129
    ^ #[127 0 0 1]
100
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   130
!
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   131
1164
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   132
maxPort
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   133
    "return the maximum port number"
100
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   134
1164
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   135
    ^ 16rffff
816
489e7876ab3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 799
diff changeset
   136
!
489e7876ab3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 799
diff changeset
   137
1164
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   138
thisHost
1226
0114bd044aa9 vw compatible domainSymbols (afXXX)
Claus Gittinger <cg@exept.de>
parents: 1164
diff changeset
   139
    "return the bytes of IN_ADDR_ANY, the address matching any local address"
1164
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   140
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   141
    ^ #[0 0 0 0]
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   142
! !
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   143
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   144
!IPSocketAddress class methodsFor:'queries'!
816
489e7876ab3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 799
diff changeset
   145
1164
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   146
domainSymbol
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   147
1226
0114bd044aa9 vw compatible domainSymbols (afXXX)
Claus Gittinger <cg@exept.de>
parents: 1164
diff changeset
   148
    ^ #'AF_INET'
0114bd044aa9 vw compatible domainSymbols (afXXX)
Claus Gittinger <cg@exept.de>
parents: 1164
diff changeset
   149
!
0114bd044aa9 vw compatible domainSymbols (afXXX)
Claus Gittinger <cg@exept.de>
parents: 1164
diff changeset
   150
0114bd044aa9 vw compatible domainSymbols (afXXX)
Claus Gittinger <cg@exept.de>
parents: 1164
diff changeset
   151
obsoleteDomainSymbol
1164
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   152
    ^ #inet
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   153
!
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   154
1226
0114bd044aa9 vw compatible domainSymbols (afXXX)
Claus Gittinger <cg@exept.de>
parents: 1164
diff changeset
   155
vwDomainSymbol
0114bd044aa9 vw compatible domainSymbols (afXXX)
Claus Gittinger <cg@exept.de>
parents: 1164
diff changeset
   156
    ^ #afInet
100
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   157
! !
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   158
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   159
!IPSocketAddress methodsFor:'accessing'!
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   160
818
2f8331ad12d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
   161
hostAddress
1164
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   162
    ^ (ByteArray new:4) replaceFrom:1 to:4 with:self startingAt:5
816
489e7876ab3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 799
diff changeset
   163
!
489e7876ab3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 799
diff changeset
   164
1164
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   165
hostAddress:aByteArray
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   166
    ^ self replaceFrom:5 to:8 with:aByteArray startingAt:1
818
2f8331ad12d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
   167
!
2f8331ad12d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
   168
2f8331ad12d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
   169
port
1164
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   170
    ^ self unsignedShortAt:3 bigEndian:true
818
2f8331ad12d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
   171
!
2f8331ad12d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
   172
2f8331ad12d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
   173
port:aPortNr
1164
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   174
    self unsignedShortAt:3 put:aPortNr bigEndian:true
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   175
! !
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   176
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   177
!IPSocketAddress methodsFor:'obsolete'!
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   178
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   179
address
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   180
    ^ self hostAddress
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   181
!
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   182
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   183
portOrName
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   184
    ^ self port
100
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   185
! !
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   186
770
32ad77c9ed74 added #printOn:
Claus Gittinger <cg@exept.de>
parents: 514
diff changeset
   187
!IPSocketAddress methodsFor:'printing & storing'!
32ad77c9ed74 added #printOn:
Claus Gittinger <cg@exept.de>
parents: 514
diff changeset
   188
32ad77c9ed74 added #printOn:
Claus Gittinger <cg@exept.de>
parents: 514
diff changeset
   189
printOn:aStream
32ad77c9ed74 added #printOn:
Claus Gittinger <cg@exept.de>
parents: 514
diff changeset
   190
    "append a user printed representation of the receiver to aStream.
32ad77c9ed74 added #printOn:
Claus Gittinger <cg@exept.de>
parents: 514
diff changeset
   191
     The format is suitable for a human - not meant to be read back."
32ad77c9ed74 added #printOn:
Claus Gittinger <cg@exept.de>
parents: 514
diff changeset
   192
1233
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   193
    |port i1 i2|
100
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   194
1233
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   195
    i1 := self adrBytesStart.
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   196
    i2 := i1 + self numAdrBytes - 1.
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   197
    i1 to:i2 do:[:i | 
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   198
        i ~~ i1 ifTrue:[
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   199
            aStream nextPut:$.
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   200
        ].
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   201
        (self at:i) printOn:aStream
1164
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   202
    ].
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   203
    (port := self port) ~~ 0 ifTrue:[
1233
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   204
        aStream nextPut:$:.
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   205
        port printOn:aStream.
1164
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   206
    ].
488
b0c17a5ff8ea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 113
diff changeset
   207
! !
b0c17a5ff8ea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 113
diff changeset
   208
1233
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   209
!IPSocketAddress methodsFor:'private'!
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   210
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   211
adrBytesStart
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   212
    ^ 5
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   213
!
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   214
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   215
numAdrBytes
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   216
    ^ 4
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   217
! !
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   218
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   219
!IPSocketAddress methodsFor:'queries'!
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   220
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   221
hostName
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   222
    |name|
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   223
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   224
    NameCache notNil ifTrue:[
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   225
        name := NameCache at:(self hostAddress) ifAbsent:nil.
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   226
        name notNil ifTrue:[^ name].
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   227
    ].
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   228
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   229
    name := super hostName.
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   230
    name notNil ifTrue:[
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   231
        (NameCache isNil or:[NameCache size > 30]) ifTrue:[
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   232
            NameCache := Dictionary new
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   233
        ].
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   234
        NameCache at:(self hostAddress) put:name.
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   235
    ].
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   236
    ^ name
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   237
! !
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   238
488
b0c17a5ff8ea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 113
diff changeset
   239
!IPSocketAddress class methodsFor:'documentation'!
100
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   240
488
b0c17a5ff8ea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 113
diff changeset
   241
version
1259
0a557e59ea4a instance creation refactored
Claus Gittinger <cg@exept.de>
parents: 1233
diff changeset
   242
    ^ '$Header: /cvs/stx/stx/libbasic2/IPSocketAddress.st,v 1.19 2003-07-09 14:26:11 cg Exp $'
100
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   243
! !