author | Claus Gittinger <cg@exept.de> |
Sat, 14 Jan 2006 16:08:55 +0100 | |
changeset 1585 | 32eba58e5498 |
parent 1559 | 609a0707ab22 |
child 1877 | d143433fd007 |
permissions | -rw-r--r-- |
100 | 1 |
" |
2 |
COPYRIGHT (c) 1995 by Claus Gittinger |
|
1164 | 3 |
All Rights Reserved |
100 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
||
1023 | 13 |
"{ Package: 'stx:libbasic2' }" |
14 |
||
818 | 15 |
SocketAddress variableByteSubclass:#IPSocketAddress |
1164 | 16 |
instanceVariableNames:'' |
1273
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
17 |
classVariableNames:'' |
488 | 18 |
poolDictionaries:'' |
816 | 19 |
category:'OS-Sockets' |
100 | 20 |
! |
21 |
||
1273
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
22 |
IPSocketAddress class instanceVariableNames:'addrCache nameCache' |
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
23 |
|
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
24 |
" |
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
25 |
No other class instance variables are inherited by this class. |
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
26 |
" |
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
27 |
! |
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
28 |
|
100 | 29 |
!IPSocketAddress class methodsFor:'documentation'! |
30 |
||
31 |
copyright |
|
32 |
" |
|
33 |
COPYRIGHT (c) 1995 by Claus Gittinger |
|
1164 | 34 |
All Rights Reserved |
100 | 35 |
|
36 |
This software is furnished under a license and may be used |
|
37 |
only in accordance with the terms of that license and with the |
|
38 |
inclusion of the above copyright notice. This software may not |
|
39 |
be provided or otherwise made available to, or used by, any |
|
40 |
other person. No title to or ownership of the software is |
|
41 |
hereby transferred. |
|
42 |
" |
|
43 |
! |
|
44 |
||
45 |
documentation |
|
46 |
" |
|
111 | 47 |
Instances of IPSocketAddress represent tcp/ip-domain socket addresses. |
48 |
These consist of an ip address (4 bytes) and a port number. |
|
49 |
||
100 | 50 |
ST-80 compatibility class. |
51 |
This may be required when existing code has to be ported to ST/X; |
|
52 |
however, it may not be complete and more protocol may be added in the future. |
|
53 |
The code here was created when public domain code (Manchester) had to |
|
54 |
be ported to ST/X and missing classes/methods were encountered, and code added |
|
55 |
by reasoning 'what the original class could probably do there'. |
|
56 |
||
57 |
This is an additional goody class; therefore: |
|
58 |
||
59 |
THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTOR ``AS IS'' AND |
|
60 |
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
61 |
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
62 |
ARE DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTOR BE LIABLE |
|
63 |
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
|
64 |
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
|
65 |
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
|
66 |
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
67 |
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
|
68 |
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
|
69 |
SUCH DAMAGE. |
|
70 |
" |
|
71 |
! ! |
|
72 |
||
1233 | 73 |
!IPSocketAddress class methodsFor:'instance creation'! |
74 |
||
1559
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1452
diff
changeset
|
75 |
addressString:aString |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1452
diff
changeset
|
76 |
"convert an address given in a dot notation like 123.456.78.9" |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1452
diff
changeset
|
77 |
|
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1452
diff
changeset
|
78 |
^ self hostAddress:(self hostAddressFromString:aString). |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1452
diff
changeset
|
79 |
|
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1452
diff
changeset
|
80 |
" |
1585 | 81 |
IPSocketAddress addressString:'1.2.3.4' |
1559
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1452
diff
changeset
|
82 |
" |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1452
diff
changeset
|
83 |
! |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1452
diff
changeset
|
84 |
|
1233 | 85 |
hostName:name serviceName:portNrOrName type:socketTypeSymbol |
1262
d3daddd36a99
no longer callBack into sockets getHostName/getAddress code.
Claus Gittinger <cg@exept.de>
parents:
1261
diff
changeset
|
86 |
"get a new instance given a hostname, port or service and type. |
d3daddd36a99
no longer callBack into sockets getHostName/getAddress code.
Claus Gittinger <cg@exept.de>
parents:
1261
diff
changeset
|
87 |
Redefined to cache the result of the name-lookup." |
1233 | 88 |
|
89 |
|addrBytes sa| |
|
90 |
||
91 |
portNrOrName isString ifTrue:[ |
|
92 |
^ super hostName:name serviceName:portNrOrName type:socketTypeSymbol |
|
93 |
]. |
|
94 |
||
1273
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
95 |
addrBytes := self addressCacheAt:name. |
1233 | 96 |
addrBytes notNil ifTrue:[ |
97 |
sa := self hostAddress:addrBytes. |
|
98 |
portNrOrName notNil ifTrue:[ |
|
99 |
sa port:portNrOrName. |
|
100 |
]. |
|
101 |
] ifFalse:[ |
|
102 |
sa := super hostName:name serviceName:portNrOrName type:socketTypeSymbol. |
|
103 |
||
1273
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
104 |
self addressCacheAt:name put:(sa hostAddress). |
1233 | 105 |
]. |
106 |
^ sa |
|
107 |
||
108 |
" |
|
1333 | 109 |
SocketAddress hostName:'localhost' serviceName:10 type:#stream |
1233 | 110 |
IPSocketAddress hostName:'localhost' serviceName:'echo' type:#datagram |
1333 | 111 |
IPSocketAddress hostName:'localhost' serviceName:'echo' type:nil |
112 |
IPSocketAddress hostName:'localhost' |
|
1559
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1452
diff
changeset
|
113 |
IPv6SocketAddress hostName:'localhost' |
1233 | 114 |
" |
1559
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1452
diff
changeset
|
115 |
! |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1452
diff
changeset
|
116 |
|
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1452
diff
changeset
|
117 |
localHost |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1452
diff
changeset
|
118 |
"get a new instance representing the local-host address" |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1452
diff
changeset
|
119 |
|
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1452
diff
changeset
|
120 |
^ self hostAddress:(self local) port:self anyPort |
1233 | 121 |
! ! |
122 |
||
1164 | 123 |
!IPSocketAddress class methodsFor:'addressing'! |
124 |
||
125 |
anyAddress |
|
1281 | 126 |
"return the anonymous addresses bytes" |
1164 | 127 |
|
1281 | 128 |
^ #[0 0 0 0] |
1164 | 129 |
! |
130 |
||
131 |
anyPort |
|
132 |
"return the anon port number" |
|
133 |
||
134 |
^ 0 |
|
135 |
! |
|
100 | 136 |
|
1281 | 137 |
broadcastAddress |
138 |
"return the broadcast address" |
|
139 |
||
140 |
^ #[255 255 255 255] |
|
141 |
! |
|
142 |
||
1164 | 143 |
firstUnreservedPort |
144 |
"return the first unreserved port number" |
|
145 |
||
146 |
^ 1024 |
|
147 |
! |
|
148 |
||
149 |
local |
|
150 |
"return IN_ADDR_ANY, the address matching any local address" |
|
151 |
||
152 |
^ #[127 0 0 1] |
|
100 | 153 |
! |
154 |
||
1164 | 155 |
maxPort |
156 |
"return the maximum port number" |
|
100 | 157 |
|
1164 | 158 |
^ 16rffff |
816 | 159 |
! |
160 |
||
1164 | 161 |
thisHost |
1226
0114bd044aa9
vw compatible domainSymbols (afXXX)
Claus Gittinger <cg@exept.de>
parents:
1164
diff
changeset
|
162 |
"return the bytes of IN_ADDR_ANY, the address matching any local address" |
1164 | 163 |
|
164 |
^ #[0 0 0 0] |
|
165 |
! ! |
|
166 |
||
1273
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
167 |
!IPSocketAddress class methodsFor:'caching'! |
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
168 |
|
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
169 |
addressCacheAt:aHostName |
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
170 |
addrCache notNil ifTrue:[ |
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
171 |
^ addrCache at:aHostName ifAbsent:nil. |
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
172 |
]. |
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
173 |
^ nil |
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
174 |
! |
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
175 |
|
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
176 |
addressCacheAt:aName put:aHostAddress |
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
177 |
(addrCache isNil or:[addrCache size > 30]) ifTrue:[ |
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
178 |
addrCache := Dictionary new. |
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
179 |
]. |
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
180 |
|
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
181 |
addrCache at:aName put:aHostAddress. |
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
182 |
! |
1261 | 183 |
|
184 |
flushAddressCache |
|
1273
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
185 |
addrCache := nil |
1261 | 186 |
|
187 |
" |
|
188 |
self flushAddressCache |
|
189 |
" |
|
1273
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
190 |
! |
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
191 |
|
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
192 |
flushNameCache |
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
193 |
nameCache := Dictionary new. |
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
194 |
! |
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
195 |
|
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
196 |
nameCacheAt:aHostAddress |
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
197 |
nameCache notNil ifTrue:[ |
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
198 |
^ nameCache at:aHostAddress ifAbsent:nil. |
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
199 |
]. |
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
200 |
^ nil |
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
201 |
! |
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
202 |
|
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
203 |
nameCacheAt:aHostAddress put:aName |
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
204 |
(nameCache isNil or:[nameCache size > 30]) ifTrue:[ |
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
205 |
nameCache := Dictionary new. |
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
206 |
]. |
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
207 |
|
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
208 |
nameCache at:aHostAddress put:aName. |
1261 | 209 |
! ! |
210 |
||
1559
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1452
diff
changeset
|
211 |
!IPSocketAddress class methodsFor:'conversion'! |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1452
diff
changeset
|
212 |
|
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1452
diff
changeset
|
213 |
hostAddressFromString:aString |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1452
diff
changeset
|
214 |
"convert an address given in a dot notation like 123.456.78.9" |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1452
diff
changeset
|
215 |
|
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1452
diff
changeset
|
216 |
|components bytes| |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1452
diff
changeset
|
217 |
|
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1452
diff
changeset
|
218 |
components := aString asCollectionOfSubstringsSeparatedBy:$.. |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1452
diff
changeset
|
219 |
components size ~~ 4 ifTrue:[ |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1452
diff
changeset
|
220 |
^ NameLookupError raiseRequestWith:aString errorString:' - bad address string'. |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1452
diff
changeset
|
221 |
]. |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1452
diff
changeset
|
222 |
|
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1452
diff
changeset
|
223 |
bytes := components collect:[:eachComponent| |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1452
diff
changeset
|
224 |
Integer readFromString:eachComponent onError:[^ NameLookupError raiseRequestWith:aString errorString:' - bad address string']. |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1452
diff
changeset
|
225 |
]. |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1452
diff
changeset
|
226 |
|
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1452
diff
changeset
|
227 |
^ bytes asByteArray. |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1452
diff
changeset
|
228 |
|
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1452
diff
changeset
|
229 |
|
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1452
diff
changeset
|
230 |
" |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1452
diff
changeset
|
231 |
IPSocketAddress hostAddressFromString:'1.2.3.4' |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1452
diff
changeset
|
232 |
IPSocketAddress hostAddressFromString:'255.255.255.255' |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1452
diff
changeset
|
233 |
" |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1452
diff
changeset
|
234 |
! ! |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1452
diff
changeset
|
235 |
|
1164 | 236 |
!IPSocketAddress class methodsFor:'queries'! |
816 | 237 |
|
1164 | 238 |
domainSymbol |
239 |
||
1226
0114bd044aa9
vw compatible domainSymbols (afXXX)
Claus Gittinger <cg@exept.de>
parents:
1164
diff
changeset
|
240 |
^ #'AF_INET' |
0114bd044aa9
vw compatible domainSymbols (afXXX)
Claus Gittinger <cg@exept.de>
parents:
1164
diff
changeset
|
241 |
! |
0114bd044aa9
vw compatible domainSymbols (afXXX)
Claus Gittinger <cg@exept.de>
parents:
1164
diff
changeset
|
242 |
|
0114bd044aa9
vw compatible domainSymbols (afXXX)
Claus Gittinger <cg@exept.de>
parents:
1164
diff
changeset
|
243 |
obsoleteDomainSymbol |
1164 | 244 |
^ #inet |
245 |
! |
|
246 |
||
1226
0114bd044aa9
vw compatible domainSymbols (afXXX)
Claus Gittinger <cg@exept.de>
parents:
1164
diff
changeset
|
247 |
vwDomainSymbol |
0114bd044aa9
vw compatible domainSymbols (afXXX)
Claus Gittinger <cg@exept.de>
parents:
1164
diff
changeset
|
248 |
^ #afInet |
100 | 249 |
! ! |
250 |
||
251 |
!IPSocketAddress methodsFor:'accessing'! |
|
252 |
||
818 | 253 |
hostAddress |
1164 | 254 |
^ (ByteArray new:4) replaceFrom:1 to:4 with:self startingAt:5 |
816 | 255 |
! |
256 |
||
1164 | 257 |
hostAddress:aByteArray |
258 |
^ self replaceFrom:5 to:8 with:aByteArray startingAt:1 |
|
818 | 259 |
! |
260 |
||
261 |
port |
|
1164 | 262 |
^ self unsignedShortAt:3 bigEndian:true |
818 | 263 |
! |
264 |
||
265 |
port:aPortNr |
|
1164 | 266 |
self unsignedShortAt:3 put:aPortNr bigEndian:true |
267 |
! ! |
|
268 |
||
269 |
!IPSocketAddress methodsFor:'obsolete'! |
|
270 |
||
271 |
address |
|
1452 | 272 |
<resource: #obsolete> |
273 |
||
1164 | 274 |
^ self hostAddress |
275 |
! |
|
276 |
||
277 |
portOrName |
|
1452 | 278 |
<resource: #obsolete> |
279 |
||
1164 | 280 |
^ self port |
100 | 281 |
! ! |
282 |
||
770 | 283 |
!IPSocketAddress methodsFor:'printing & storing'! |
284 |
||
1333 | 285 |
printAddressOn:aStream |
286 |
|i1 i2| |
|
100 | 287 |
|
1233 | 288 |
i1 := self adrBytesStart. |
289 |
i2 := i1 + self numAdrBytes - 1. |
|
290 |
i1 to:i2 do:[:i | |
|
291 |
i ~~ i1 ifTrue:[ |
|
292 |
aStream nextPut:$. |
|
293 |
]. |
|
294 |
(self at:i) printOn:aStream |
|
1164 | 295 |
]. |
488 | 296 |
! ! |
297 |
||
1233 | 298 |
!IPSocketAddress methodsFor:'private'! |
299 |
||
300 |
adrBytesStart |
|
301 |
^ 5 |
|
302 |
! |
|
303 |
||
304 |
numAdrBytes |
|
305 |
^ 4 |
|
306 |
! ! |
|
307 |
||
308 |
!IPSocketAddress methodsFor:'queries'! |
|
309 |
||
310 |
hostName |
|
1273
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
311 |
|addr name| |
1233 | 312 |
|
1273
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
313 |
addr := self hostAddress. |
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
314 |
|
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
315 |
name := self class nameCacheAt:addr. |
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
316 |
name notNil ifTrue:[^ name]. |
1233 | 317 |
|
318 |
name := super hostName. |
|
319 |
name notNil ifTrue:[ |
|
1273
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
320 |
self class nameCacheAt:addr put:name. |
1233 | 321 |
]. |
322 |
^ name |
|
1337 | 323 |
! |
324 |
||
325 |
networkAddress |
|
326 |
"Extract and return the network address from the host address." |
|
327 |
||
328 |
|highAddrByte| |
|
329 |
||
330 |
highAddrByte := self at: 5. |
|
331 |
(highAddrByte bitAnd: 16r80) == 0 ifTrue: [^ByteArray with: highAddrByte]. |
|
332 |
(highAddrByte bitAnd: 16rC0) == 16r80 ifTrue: [^ByteArray with: highAddrByte with: (self at: 6)]. |
|
333 |
(highAddrByte bitAnd: 16rC0) == 16rC0 ifTrue: [^ByteArray with: highAddrByte with: (self at: 6) with: (self at: 7)]. |
|
334 |
^ self error: 'unknown network class' |
|
335 |
||
336 |
" |
|
337 |
(IPSocketAddress hostName:'exept.eu.org') networkAddress |
|
338 |
(IPSocketAddress hostName:'exept.exept.de') networkAddress |
|
339 |
(IPSocketAddress hostName:'ibm.com') networkAddress |
|
340 |
(IPSocketAddress hostName:'cnn.com') networkAddress |
|
341 |
" |
|
342 |
! |
|
343 |
||
344 |
networkClass |
|
345 |
"Extract and return the network class (as a symbol) from the host address. |
|
346 |
Returns one of #classA #classB #classC." |
|
347 |
||
348 |
|highAddrByte| |
|
349 |
||
350 |
highAddrByte := self at: 5. |
|
351 |
(highAddrByte bitAnd: 16r80) == 0 ifTrue: [^#classA]. |
|
352 |
(highAddrByte bitAnd: 16rC0) == 16r80 ifTrue: [^#classB]. |
|
353 |
(highAddrByte bitAnd: 16rC0) == 16rC0 ifTrue: [^#classC]. |
|
354 |
^ self error: 'unknown network class' |
|
355 |
||
356 |
" |
|
357 |
(IPSocketAddress hostName:'exept.eu.org') networkClass |
|
358 |
" |
|
1233 | 359 |
! ! |
360 |
||
1366
e01d0f6c102a
New method #isLocal returning true for local addresses
Stefan Vogel <sv@exept.de>
parents:
1337
diff
changeset
|
361 |
!IPSocketAddress methodsFor:'testing'! |
e01d0f6c102a
New method #isLocal returning true for local addresses
Stefan Vogel <sv@exept.de>
parents:
1337
diff
changeset
|
362 |
|
e01d0f6c102a
New method #isLocal returning true for local addresses
Stefan Vogel <sv@exept.de>
parents:
1337
diff
changeset
|
363 |
isLocal |
e01d0f6c102a
New method #isLocal returning true for local addresses
Stefan Vogel <sv@exept.de>
parents:
1337
diff
changeset
|
364 |
"answer true, if this address adresses a peer on the same host" |
e01d0f6c102a
New method #isLocal returning true for local addresses
Stefan Vogel <sv@exept.de>
parents:
1337
diff
changeset
|
365 |
|
e01d0f6c102a
New method #isLocal returning true for local addresses
Stefan Vogel <sv@exept.de>
parents:
1337
diff
changeset
|
366 |
^ self hostAddress first == 127 |
e01d0f6c102a
New method #isLocal returning true for local addresses
Stefan Vogel <sv@exept.de>
parents:
1337
diff
changeset
|
367 |
! ! |
e01d0f6c102a
New method #isLocal returning true for local addresses
Stefan Vogel <sv@exept.de>
parents:
1337
diff
changeset
|
368 |
|
488 | 369 |
!IPSocketAddress class methodsFor:'documentation'! |
100 | 370 |
|
488 | 371 |
version |
1585 | 372 |
^ '$Header: /cvs/stx/stx/libbasic2/IPSocketAddress.st,v 1.29 2006-01-14 15:08:55 cg Exp $' |
100 | 373 |
! ! |