author | Claus Gittinger <cg@exept.de> |
Wed, 09 Jul 2003 16:26:27 +0200 | |
changeset 1259 | 0a557e59ea4a |
parent 1232 | 49ce4681f1c0 |
child 1262 | d3daddd36a99 |
permissions | -rw-r--r-- |
100 | 1 |
" |
2 |
COPYRIGHT (c) 1995 by Claus Gittinger |
|
3 |
All Rights Reserved |
|
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 |
||
1164 | 13 |
"{ Package: 'stx:libbasic2' }" |
14 |
||
818 | 15 |
UninterpretedBytes variableByteSubclass:#SocketAddress |
488 | 16 |
instanceVariableNames:'' |
1229 | 17 |
classVariableNames:'DomainToClassMapping' |
488 | 18 |
poolDictionaries:'' |
816 | 19 |
category:'OS-Sockets' |
100 | 20 |
! |
21 |
||
22 |
!SocketAddress class methodsFor:'documentation'! |
|
23 |
||
24 |
copyright |
|
25 |
" |
|
26 |
COPYRIGHT (c) 1995 by Claus Gittinger |
|
27 |
All Rights Reserved |
|
28 |
||
29 |
This software is furnished under a license and may be used |
|
30 |
only in accordance with the terms of that license and with the |
|
31 |
inclusion of the above copyright notice. This software may not |
|
32 |
be provided or otherwise made available to, or used by, any |
|
33 |
other person. No title to or ownership of the software is |
|
34 |
hereby transferred. |
|
35 |
" |
|
36 |
! |
|
37 |
||
38 |
documentation |
|
39 |
" |
|
111 | 40 |
Abstract superclass for subclasses implementing various IPC addressing schemes. |
41 |
See concrete examples IPSocketAddress and UDSocketAddress. |
|
42 |
||
100 | 43 |
ST-80 compatibility class. |
44 |
This may be required when existing code has to be ported to ST/X; |
|
45 |
however, it may not be complete and more protocol may be added in the future. |
|
46 |
The code here was created when public domain code (Manchester) had to |
|
47 |
be ported to ST/X and missing classes/methods were encountered, and code added |
|
48 |
by reasoning 'what the original class could probably do there'. |
|
49 |
||
50 |
This is an additional goody class; therefore: |
|
51 |
||
52 |
THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTOR ``AS IS'' AND |
|
53 |
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
54 |
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
55 |
ARE DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTOR BE LIABLE |
|
56 |
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
|
57 |
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
|
58 |
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
|
59 |
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
60 |
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
|
61 |
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
|
62 |
SUCH DAMAGE. |
|
63 |
" |
|
64 |
! ! |
|
65 |
||
816 | 66 |
!SocketAddress class methodsFor:'instance creation'! |
67 |
||
1228
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
68 |
hostAddress:addr |
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
69 |
"get a new instance given addr-bytes" |
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
70 |
|
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
71 |
^ self hostAddress:addr port:0 |
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
72 |
! |
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
73 |
|
816 | 74 |
hostAddress:addr port:portNr |
1228
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
75 |
"get a new instance given addr-bytes and a portNr" |
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
76 |
|
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
77 |
^ self new hostAddress:addr; port:portNr |
816 | 78 |
! |
79 |
||
1164 | 80 |
hostName:name |
1228
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
81 |
"get a new instance given a hostname" |
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
82 |
|
1164 | 83 |
^ self hostName:name serviceName:nil type:nil |
84 |
! |
|
85 |
||
816 | 86 |
hostName:name port:portNr |
1228
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
87 |
"get a new instance given a hostname and port" |
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
88 |
|
1164 | 89 |
^ self hostName:name serviceName:portNr type:nil |
90 |
! |
|
91 |
||
92 |
hostName:name serviceName:portNrOrName type:socketTypeSymbol |
|
1228
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
93 |
"get a new instance given a hostname, port or service and type" |
1164 | 94 |
|
95 |
|addressInfo serviceName port sa| |
|
96 |
||
97 |
portNrOrName isString ifTrue:[ |
|
98 |
serviceName := portNrOrName |
|
99 |
] ifFalse:[ |
|
100 |
port := portNrOrName. |
|
101 |
]. |
|
102 |
||
1226
0114bd044aa9
vw compatible domainSymbols (afXXX)
Claus Gittinger <cg@exept.de>
parents:
1225
diff
changeset
|
103 |
addressInfo := self |
0114bd044aa9
vw compatible domainSymbols (afXXX)
Claus Gittinger <cg@exept.de>
parents:
1225
diff
changeset
|
104 |
getAddressInfo:name |
0114bd044aa9
vw compatible domainSymbols (afXXX)
Claus Gittinger <cg@exept.de>
parents:
1225
diff
changeset
|
105 |
serviceName:serviceName |
0114bd044aa9
vw compatible domainSymbols (afXXX)
Claus Gittinger <cg@exept.de>
parents:
1225
diff
changeset
|
106 |
domain:(self domainSymbol) |
0114bd044aa9
vw compatible domainSymbols (afXXX)
Claus Gittinger <cg@exept.de>
parents:
1225
diff
changeset
|
107 |
type:socketTypeSymbol |
0114bd044aa9
vw compatible domainSymbols (afXXX)
Claus Gittinger <cg@exept.de>
parents:
1225
diff
changeset
|
108 |
protocol:nil |
0114bd044aa9
vw compatible domainSymbols (afXXX)
Claus Gittinger <cg@exept.de>
parents:
1225
diff
changeset
|
109 |
flags:0. |
1164 | 110 |
|
111 |
sa := addressInfo first socketAddress. |
|
112 |
addressInfo size > 1 ifTrue:[ |
|
113 |
(addressInfo contains:[:entry| entry socketAddress ~= sa]) ifTrue:[ |
|
1232
49ce4681f1c0
dont wine if we get multiple host addresses for a name
Claus Gittinger <cg@exept.de>
parents:
1229
diff
changeset
|
114 |
'SocketAddress [warning]: multiple hostAddresses for host' infoPrintCR. |
1164 | 115 |
]. |
116 |
]. |
|
117 |
port notNil ifTrue:[ |
|
118 |
sa port:port. |
|
119 |
]. |
|
120 |
^ sa |
|
121 |
||
122 |
" |
|
123 |
SocketAddress hostName:'localhost' serviceName:10 type:#stream |
|
124 |
IPSocketAddress hostName:'localhost' serviceName:'echo' type:#datagram |
|
125 |
IPSocketAddress hostName:'localhost' serviceName:'echo' type:nil |
|
126 |
" |
|
818 | 127 |
! |
128 |
||
129 |
new |
|
1228
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
130 |
|numBytes| |
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
131 |
|
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
132 |
self == SocketAddress ifTrue:[ |
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
133 |
self error:'SocketAddress is abstract'. |
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
134 |
]. |
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
135 |
|
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
136 |
numBytes := self socketAddressSize. |
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
137 |
numBytes isNil ifTrue:[ |
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
138 |
self error:'unsupported domain'. |
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
139 |
^ nil |
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
140 |
]. |
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
141 |
^ (self new:numBytes) domainCode:(self domainCode) |
1164 | 142 |
|
143 |
" |
|
1228
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
144 |
IPSocketAddress new |
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
145 |
IPv6SocketAddress new |
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
146 |
UDSocketAddress new |
1164 | 147 |
AppletalkSocketAddress new |
148 |
" |
|
149 |
! |
|
818 | 150 |
|
1164 | 151 |
newDomain:domain |
152 |
"answer an new socket address for a given domain" |
|
153 |
||
154 |
^ (self knownClassFromCode:domain) new |
|
155 |
||
156 |
" |
|
1228
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
157 |
self newDomain:#afUnix |
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
158 |
self newDomain:#afInet |
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
159 |
|
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
160 |
self newDomain:#'AF_UNIX' |
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
161 |
self newDomain:#'AF_INET' |
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
162 |
|
1164 | 163 |
self newDomain:#unix |
164 |
self newDomain:#inet |
|
165 |
" |
|
1259
0a557e59ea4a
instance creation refactored
Claus Gittinger <cg@exept.de>
parents:
1232
diff
changeset
|
166 |
! |
0a557e59ea4a
instance creation refactored
Claus Gittinger <cg@exept.de>
parents:
1232
diff
changeset
|
167 |
|
0a557e59ea4a
instance creation refactored
Claus Gittinger <cg@exept.de>
parents:
1232
diff
changeset
|
168 |
peerName:peerName port:port |
0a557e59ea4a
instance creation refactored
Claus Gittinger <cg@exept.de>
parents:
1232
diff
changeset
|
169 |
self error:'unsupported domain'. |
816 | 170 |
! ! |
171 |
||
100 | 172 |
!SocketAddress class methodsFor:'queries'! |
173 |
||
1164 | 174 |
domainCode |
175 |
"answer the numerical domain code used in socket addresses" |
|
176 |
||
177 |
^ OperatingSystem socketAccessor domainCodeOf:self domainSymbol |
|
178 |
! |
|
179 |
||
100 | 180 |
domainCodeFromName:aNameSymbol |
816 | 181 |
"this is a compatibility method; |
182 |
VW returns the internal unix codes here - however, in ST/X, |
|
1228
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
183 |
symbols are returned, which are translated later" |
816 | 184 |
|
1228
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
185 |
aNameSymbol == #afUnix ifTrue:[^ #'AF_UNIX']. |
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
186 |
aNameSymbol == #afInet ifTrue:[^ #'AF_INET']. |
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
187 |
aNameSymbol == #afIpV6 ifTrue:[^ #'AF_INET6']. |
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
188 |
aNameSymbol == #afAppletalk ifTrue:[^ #'AF_APPLETALK']. |
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
189 |
aNameSymbol == #afDecnet ifTrue:[^ #'AF_DECnet']. |
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
190 |
aNameSymbol == #afSna ifTrue:[^ #'AF_SNA']. |
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
191 |
aNameSymbol == #afNs ifTrue:[^ #'AF_NS']. |
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
192 |
aNameSymbol == #afCcitt ifTrue:[^ #'AF_CCITT']. |
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
193 |
aNameSymbol == #afImplink ifTrue:[^ #'AF_IMPLINK']. |
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
194 |
aNameSymbol == #afPup ifTrue:[^ #'AF_PUP']. |
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
195 |
aNameSymbol == #afChaos ifTrue:[^ #'AF_CHAOS']. |
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
196 |
aNameSymbol == #afEcma ifTrue:[^ #'AF_ECMA']. |
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
197 |
aNameSymbol == #afDatakit ifTrue:[^ #'AF_DATAKIT']. |
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
198 |
aNameSymbol == #afDli ifTrue:[^ #'AF_DLI']. |
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
199 |
aNameSymbol == #afLat ifTrue:[^ #'AF_LAT']. |
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
200 |
aNameSymbol == #afHylink ifTrue:[^ #'AF_HYLINK']. |
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
201 |
|
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
202 |
aNameSymbol == #afUnspec ifTrue:[^ #'AF_UNSPEC']. |
816 | 203 |
|
100 | 204 |
"/ |
205 |
"/ could someone tell me which symbols are used in ST-80's SocketAddress class ? |
|
206 |
"/ |
|
207 |
self error:'no more mimicri implemented yet ...' |
|
602 | 208 |
|
209 |
"Modified: / 9.1.1998 / 10:03:56 / stefan" |
|
816 | 210 |
! |
211 |
||
212 |
domainNameFromCode:code |
|
213 |
"this is a compatibility method; |
|
214 |
VW expects the internal unix codes here - however, in ST/X, |
|
215 |
symbols are expected - keeping the numeric values secret (in Socket)" |
|
216 |
||
1228
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
217 |
code == #unix ifTrue:[^ #afUnix]. |
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
218 |
code == #'AF_UNIX' ifTrue:[^ #afUnix]. |
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
219 |
code == #inet ifTrue:[^ #afInet]. |
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
220 |
code == #'AF_INET' ifTrue:[^ #afInet]. |
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
221 |
code == #inet6 ifTrue:[^ #afIpV6]. |
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
222 |
code == #'AF_INET6' ifTrue:[^ #afIpV6]. |
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
223 |
code == #appletalk ifTrue:[^ #afAppletalk]. |
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
224 |
code == #'AF_APPLETALK' ifTrue:[^ #afAppletalk]. |
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
225 |
code == #DECnet ifTrue:[^ #afDecnet]. |
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
226 |
code == #'AF_DECNET' ifTrue:[^ #afDecnet]. |
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
227 |
code == #sna ifTrue:[^ #afSna]. |
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
228 |
code == #'AF_SNA' ifTrue:[^ #afSna]. |
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
229 |
code == #xns ifTrue:[^ #afNs]. |
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
230 |
code == #'AF_NS' ifTrue:[^ #afNs]. |
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
231 |
code == #ccitt ifTrue:[^ #afCcitt]. |
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
232 |
code == #'AF_CCITT' ifTrue:[^ #afCcitt]. |
816 | 233 |
|
234 |
"/ |
|
235 |
"/ could someone tell me which symbols are used in ST-80's SocketAddress class ? |
|
236 |
"/ |
|
237 |
self error:'no more mimicri implemented yet ...' |
|
238 |
! |
|
239 |
||
1164 | 240 |
domainSymbol |
241 |
"answer the domain symbol. Subclasses redefine this" |
|
242 |
||
243 |
self == SocketAddress ifTrue:[ |
|
244 |
^ nil |
|
245 |
] ifFalse:[ |
|
246 |
self subclassResponsibility |
|
247 |
] |
|
248 |
! |
|
249 |
||
250 |
getAddressInfo:hostName serviceName:serviceName domain:domainArg type:typeArg protocol:protoArg flags:flags |
|
251 |
"answer an Array of socket addresses for serviceName on hostName |
|
252 |
Domain, type, protocol may be nil or specify a hint for the socket |
|
253 |
addresses to be returned." |
|
254 |
||
255 |
^ OperatingSystem socketAccessor |
|
256 |
getAddressInfo:hostName serviceName:serviceName |
|
257 |
domain:domainArg type:typeArg protocol:protoArg flags:flags |
|
258 |
||
259 |
" |
|
260 |
self getAddressInfo:'localhost' serviceName:nil |
|
261 |
domain:nil type:nil protocol:nil flags:nil |
|
262 |
self getAddressInfo:'localhost' serviceName:nil |
|
263 |
domain:#inet type:#stream protocol:nil flags:nil |
|
264 |
self getAddressInfo:'localhost' serviceName:nil |
|
265 |
domain:#inet type:#stream protocol:#tcp flags:nil |
|
266 |
self getAddressInfo:'blurb.exept.de' serviceName:nil |
|
267 |
domain:#inet type:nil protocol:nil flags:nil |
|
268 |
self getAddressInfo:'1.2.3.4' serviceName:'6' |
|
269 |
domain:#inet type:nil protocol:nil flags:nil |
|
270 |
self getAddressInfo:'localhost' serviceName:'echo' |
|
271 |
domain:#inet6 type:nil protocol:nil flags:nil |
|
272 |
" |
|
273 |
! |
|
274 |
||
1167 | 275 |
getAddressInfo:hostName serviceName:serviceName type:typeArg protocol:protoArg flags:flags |
276 |
"answer an Array of socket addresses for serviceName on hostName |
|
277 |
Domain, type, protocol may be nil or specify a hint for the socket |
|
278 |
addresses to be returned." |
|
279 |
||
1232
49ce4681f1c0
dont wine if we get multiple host addresses for a name
Claus Gittinger <cg@exept.de>
parents:
1229
diff
changeset
|
280 |
^ self |
49ce4681f1c0
dont wine if we get multiple host addresses for a name
Claus Gittinger <cg@exept.de>
parents:
1229
diff
changeset
|
281 |
getAddressInfo:hostName serviceName:serviceName |
49ce4681f1c0
dont wine if we get multiple host addresses for a name
Claus Gittinger <cg@exept.de>
parents:
1229
diff
changeset
|
282 |
domain:(self domainCode) type:typeArg protocol:protoArg flags:flags |
1167 | 283 |
|
284 |
" |
|
285 |
IPSocketAddress getAddressInfo:'localhost' serviceName:nil |
|
286 |
type:nil protocol:nil flags:nil |
|
287 |
IPSocketAddress getAddressInfo:'localhost' serviceName:nil |
|
288 |
type:#stream protocol:nil flags:nil |
|
289 |
IPSocketAddress getAddressInfo:'localhost' serviceName:nil |
|
290 |
type:#stream protocol:#tcp flags:nil |
|
291 |
IPSocketAddress getAddressInfo:'blurb.exept.de' serviceName:nil |
|
292 |
type:nil protocol:nil flags:nil |
|
293 |
IPSocketAddress getAddressInfo:'1.2.3.4' serviceName:'6' |
|
294 |
type:nil protocol:nil flags:nil |
|
295 |
IPSocketAddress getAddressInfo:'localhost' serviceName:'echo' |
|
296 |
type:nil protocol:nil flags:nil |
|
297 |
" |
|
298 |
! |
|
299 |
||
1164 | 300 |
getNameInfo:socketAddress wantHostName:wantHostName wantServiceName:wantServiceName datagram:useDatagram flags:flags |
301 |
"answer an Array containing the hostName and serviceName |
|
302 |
in socketAddress. SocketType may be one " |
|
303 |
||
304 |
^ OperatingSystem socketAccessor |
|
305 |
getNameInfo:socketAddress wantHostName:wantHostName |
|
306 |
wantServiceName:wantServiceName datagram:useDatagram flags:flags |
|
307 |
||
308 |
" |
|
309 |
self getNameInfo: |
|
310 |
(self getAddressInfo:'localhost' serviceName:'echo' |
|
311 |
domain:#inet type:#stream protocol:nil flags:nil) first socketAddress |
|
312 |
wantHostName:true wantServiceName:true datagram:false flags:0 |
|
313 |
" |
|
314 |
! |
|
315 |
||
816 | 316 |
knownClassFromCode:code |
317 |
"this is a compatibility method; |
|
318 |
VW expects the internal unix codes here - however, in ST/X, |
|
319 |
symbols are expected - keeping the numeric values secret (in Socket)" |
|
320 |
||
1229 | 321 |
|cls| |
322 |
||
323 |
DomainToClassMapping isNil ifTrue:[ |
|
324 |
DomainToClassMapping := IdentityDictionary new |
|
325 |
]. |
|
326 |
cls := DomainToClassMapping at:code ifAbsent:nil. |
|
327 |
cls notNil ifTrue:[^ cls]. |
|
1259
0a557e59ea4a
instance creation refactored
Claus Gittinger <cg@exept.de>
parents:
1232
diff
changeset
|
328 |
|
1226
0114bd044aa9
vw compatible domainSymbols (afXXX)
Claus Gittinger <cg@exept.de>
parents:
1225
diff
changeset
|
329 |
code notNil ifTrue:[ |
1259
0a557e59ea4a
instance creation refactored
Claus Gittinger <cg@exept.de>
parents:
1232
diff
changeset
|
330 |
"/ some are always known... |
0a557e59ea4a
instance creation refactored
Claus Gittinger <cg@exept.de>
parents:
1232
diff
changeset
|
331 |
DomainToClassMapping at:#unix put:UDSocketAddress. |
0a557e59ea4a
instance creation refactored
Claus Gittinger <cg@exept.de>
parents:
1232
diff
changeset
|
332 |
DomainToClassMapping at:#inet put:IPSocketAddress. |
0a557e59ea4a
instance creation refactored
Claus Gittinger <cg@exept.de>
parents:
1232
diff
changeset
|
333 |
DomainToClassMapping at:#inet6 put:IPv6SocketAddress. |
0a557e59ea4a
instance creation refactored
Claus Gittinger <cg@exept.de>
parents:
1232
diff
changeset
|
334 |
DomainToClassMapping at:#appletalk put:AppletalkSocketAddress. |
0a557e59ea4a
instance creation refactored
Claus Gittinger <cg@exept.de>
parents:
1232
diff
changeset
|
335 |
DomainToClassMapping at:#decnet put:DecNetSocketAddress. |
0a557e59ea4a
instance creation refactored
Claus Gittinger <cg@exept.de>
parents:
1232
diff
changeset
|
336 |
|
1229 | 337 |
self allSubclassesDo:[:aSubClass| |
338 |
(aSubClass domainCode == code |
|
339 |
or:[aSubClass domainSymbol == code |
|
340 |
or:[aSubClass obsoleteDomainSymbol == code |
|
341 |
or:[aSubClass vwDomainSymbol == code]]]) |
|
342 |
ifTrue:[ |
|
343 |
DomainToClassMapping at:code put:aSubClass. |
|
344 |
^ aSubClass |
|
1226
0114bd044aa9
vw compatible domainSymbols (afXXX)
Claus Gittinger <cg@exept.de>
parents:
1225
diff
changeset
|
345 |
]. |
1164 | 346 |
]. |
347 |
]. |
|
348 |
^ SocketAddress |
|
816 | 349 |
|
1164 | 350 |
" |
1229 | 351 |
self knownClassFromCode:#'AF_UNIX' |
1226
0114bd044aa9
vw compatible domainSymbols (afXXX)
Claus Gittinger <cg@exept.de>
parents:
1225
diff
changeset
|
352 |
self knownClassFromCode:#'AF_INET' |
0114bd044aa9
vw compatible domainSymbols (afXXX)
Claus Gittinger <cg@exept.de>
parents:
1225
diff
changeset
|
353 |
|
0114bd044aa9
vw compatible domainSymbols (afXXX)
Claus Gittinger <cg@exept.de>
parents:
1225
diff
changeset
|
354 |
self knownClassFromCode:1 |
0114bd044aa9
vw compatible domainSymbols (afXXX)
Claus Gittinger <cg@exept.de>
parents:
1225
diff
changeset
|
355 |
self knownClassFromCode:2 |
0114bd044aa9
vw compatible domainSymbols (afXXX)
Claus Gittinger <cg@exept.de>
parents:
1225
diff
changeset
|
356 |
|
0114bd044aa9
vw compatible domainSymbols (afXXX)
Claus Gittinger <cg@exept.de>
parents:
1225
diff
changeset
|
357 |
self knownClassFromCode:#unix obsolete ST/X codes |
1164 | 358 |
self knownClassFromCode:#inet |
1226
0114bd044aa9
vw compatible domainSymbols (afXXX)
Claus Gittinger <cg@exept.de>
parents:
1225
diff
changeset
|
359 |
|
0114bd044aa9
vw compatible domainSymbols (afXXX)
Claus Gittinger <cg@exept.de>
parents:
1225
diff
changeset
|
360 |
self knownClassFromCode:#afUnix visualWorks codes |
0114bd044aa9
vw compatible domainSymbols (afXXX)
Claus Gittinger <cg@exept.de>
parents:
1225
diff
changeset
|
361 |
self knownClassFromCode:#afInet |
1164 | 362 |
" |
363 |
! |
|
816 | 364 |
|
1226
0114bd044aa9
vw compatible domainSymbols (afXXX)
Claus Gittinger <cg@exept.de>
parents:
1225
diff
changeset
|
365 |
obsoleteDomainSymbol |
0114bd044aa9
vw compatible domainSymbols (afXXX)
Claus Gittinger <cg@exept.de>
parents:
1225
diff
changeset
|
366 |
^ nil |
0114bd044aa9
vw compatible domainSymbols (afXXX)
Claus Gittinger <cg@exept.de>
parents:
1225
diff
changeset
|
367 |
! |
0114bd044aa9
vw compatible domainSymbols (afXXX)
Claus Gittinger <cg@exept.de>
parents:
1225
diff
changeset
|
368 |
|
1259
0a557e59ea4a
instance creation refactored
Claus Gittinger <cg@exept.de>
parents:
1232
diff
changeset
|
369 |
peerNameFromPeer:peer |
0a557e59ea4a
instance creation refactored
Claus Gittinger <cg@exept.de>
parents:
1232
diff
changeset
|
370 |
^ peer hostName |
0a557e59ea4a
instance creation refactored
Claus Gittinger <cg@exept.de>
parents:
1232
diff
changeset
|
371 |
! |
0a557e59ea4a
instance creation refactored
Claus Gittinger <cg@exept.de>
parents:
1232
diff
changeset
|
372 |
|
1164 | 373 |
socketAddressSize |
374 |
"answer the OS specific size of a socket address" |
|
375 |
||
1228
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
376 |
^ OperatingSystem socketAccessor socketAddressSize:(self domainSymbol) |
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
377 |
|
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
378 |
" |
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
379 |
UDSocketAddress socketAddressSize |
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
380 |
IPSocketAddress socketAddressSize |
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
381 |
IPv6SocketAddress socketAddressSize |
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
382 |
AppletalkSocketAddress socketAddressSize |
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
383 |
DecNetSocketAddress socketAddressSize |
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
384 |
" |
1226
0114bd044aa9
vw compatible domainSymbols (afXXX)
Claus Gittinger <cg@exept.de>
parents:
1225
diff
changeset
|
385 |
! |
0114bd044aa9
vw compatible domainSymbols (afXXX)
Claus Gittinger <cg@exept.de>
parents:
1225
diff
changeset
|
386 |
|
0114bd044aa9
vw compatible domainSymbols (afXXX)
Claus Gittinger <cg@exept.de>
parents:
1225
diff
changeset
|
387 |
vwDomainSymbol |
0114bd044aa9
vw compatible domainSymbols (afXXX)
Claus Gittinger <cg@exept.de>
parents:
1225
diff
changeset
|
388 |
^ nil |
100 | 389 |
! ! |
390 |
||
818 | 391 |
!SocketAddress methodsFor:'accessing'! |
392 |
||
1164 | 393 |
domainCode |
394 |
^ self unsignedShortAt:1 |
|
395 |
! |
|
396 |
||
397 |
domainCode:anInteger |
|
398 |
self unsignedShortAt:1 put:anInteger |
|
399 |
! |
|
400 |
||
1223 | 401 |
hostAddress:addressBytes |
1164 | 402 |
"generic method, subclasses usually redefine this" |
818 | 403 |
|
1223 | 404 |
"/ the first 2-bytes (a short) is the domainCode |
405 |
self replaceBytesFrom:1+2 to:addressBytes size+2 with:addressBytes startingAt:1 |
|
406 |
||
407 |
" |
|
408 |
IPSocketAddress hostAddress:#[193 141 12 193] port:80 |
|
409 |
" |
|
818 | 410 |
! |
411 |
||
1223 | 412 |
hostAddress:addressBytes port:portNr |
413 |
self hostAddress:addressBytes. |
|
818 | 414 |
self port:portNr |
415 |
||
416 |
" |
|
417 |
IPSocketAddress hostAddress:#[193 141 12 193] port:10 |
|
418 |
" |
|
1223 | 419 |
! |
818 | 420 |
|
1223 | 421 |
port |
422 |
self subclassResponsibility |
|
423 |
! |
|
424 |
||
425 |
port:portNr |
|
426 |
self subclassResponsibility |
|
818 | 427 |
! ! |
428 |
||
1164 | 429 |
!SocketAddress methodsFor:'printing & storing'! |
430 |
||
431 |
displayString |
|
1228
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
432 |
"redefine from Collection" |
1164 | 433 |
|
434 |
|s| |
|
435 |
||
436 |
s := WriteStream on:''. |
|
437 |
self printOn:s. |
|
438 |
^ s contents. |
|
439 |
! ! |
|
440 |
||
441 |
!SocketAddress methodsFor:'private'! |
|
442 |
||
443 |
fromBytes:aByteArray |
|
444 |
"Copy the internal representation of a SocketAddress to myself |
|
445 |
||
446 |
This is an internal interface!!" |
|
447 |
||
1225 | 448 |
self replaceBytesFrom:1 to:(self size) with:aByteArray startingAt:1. |
449 |
||
450 |
||
1164 | 451 |
! ! |
452 |
||
100 | 453 |
!SocketAddress methodsFor:'queries'! |
454 |
||
488 | 455 |
address |
456 |
^ self subclassResponsibility |
|
457 |
! |
|
458 |
||
111 | 459 |
hostName |
1164 | 460 |
^ (self class getNameInfo:self wantHostName:true |
461 |
wantServiceName:false datagram:false flags:0) first |
|
111 | 462 |
|
1164 | 463 |
" |
1259
0a557e59ea4a
instance creation refactored
Claus Gittinger <cg@exept.de>
parents:
1232
diff
changeset
|
464 |
(IPSocketAddress hostAddress:#[127 0 0 1]) hostName |
0a557e59ea4a
instance creation refactored
Claus Gittinger <cg@exept.de>
parents:
1232
diff
changeset
|
465 |
(IPSocketAddress hostName:'localhost') address |
0a557e59ea4a
instance creation refactored
Claus Gittinger <cg@exept.de>
parents:
1232
diff
changeset
|
466 |
(IPSocketAddress hostName:'www.google.com') address |
0a557e59ea4a
instance creation refactored
Claus Gittinger <cg@exept.de>
parents:
1232
diff
changeset
|
467 |
|
0a557e59ea4a
instance creation refactored
Claus Gittinger <cg@exept.de>
parents:
1232
diff
changeset
|
468 |
(IPSocketAddress hostAddress:#[127 0 0 1] port:7) hostName |
0a557e59ea4a
instance creation refactored
Claus Gittinger <cg@exept.de>
parents:
1232
diff
changeset
|
469 |
(IPSocketAddress hostAddress:#[193 141 12 193] port:10) hostName |
1228
b766b9873ba6
refactored & dead code eliminated
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
470 |
(IPSocketAddress hostAddress:#[193 141 12 244]) hostName |
1164 | 471 |
" |
111 | 472 |
! |
473 |
||
100 | 474 |
portOrName |
210 | 475 |
^ self subclassResponsibility |
1164 | 476 |
! |
477 |
||
478 |
serviceName |
|
479 |
^ (self class getNameInfo:self wantHostName:false |
|
480 |
wantServiceName:true datagram:false flags:0) second |
|
481 |
||
482 |
" |
|
483 |
(IPSocketAddress hostAddress:#[127 0 0 1] port:7) serviceName |
|
484 |
(IPSocketAddress hostAddress:#[193 141 12 193] port:10) serviceName |
|
485 |
" |
|
100 | 486 |
! ! |
487 |
||
488 | 488 |
!SocketAddress class methodsFor:'documentation'! |
489 |
||
490 |
version |
|
1259
0a557e59ea4a
instance creation refactored
Claus Gittinger <cg@exept.de>
parents:
1232
diff
changeset
|
491 |
^ '$Header: /cvs/stx/stx/libbasic2/SocketAddress.st,v 1.18 2003-07-09 14:26:06 cg Exp $' |
488 | 492 |
! ! |