author | Stefan Vogel <sv@exept.de> |
Thu, 11 Jul 2013 17:02:07 +0200 | |
changeset 3052 | e690209a5c52 |
parent 3049 | 3f7eeb76695e |
child 3057 | ac2356ba61ca |
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 |
" |
|
1023 | 12 |
"{ Package: 'stx:libbasic2' }" |
13 |
||
818 | 14 |
SocketAddress variableByteSubclass:#IPSocketAddress |
1164 | 15 |
instanceVariableNames:'' |
1877
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
16 |
classVariableNames:'CacheInvalidationTimeInterval AddressCacheSize NameCacheSize' |
488 | 17 |
poolDictionaries:'' |
816 | 18 |
category:'OS-Sockets' |
100 | 19 |
! |
20 |
||
1273
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
21 |
IPSocketAddress class instanceVariableNames:'addrCache nameCache' |
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
22 |
|
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 |
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
|
25 |
" |
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 |
|
100 | 28 |
!IPSocketAddress class methodsFor:'documentation'! |
29 |
||
30 |
copyright |
|
31 |
" |
|
32 |
COPYRIGHT (c) 1995 by Claus Gittinger |
|
1164 | 33 |
All Rights Reserved |
100 | 34 |
|
35 |
This software is furnished under a license and may be used |
|
36 |
only in accordance with the terms of that license and with the |
|
37 |
inclusion of the above copyright notice. This software may not |
|
38 |
be provided or otherwise made available to, or used by, any |
|
39 |
other person. No title to or ownership of the software is |
|
40 |
hereby transferred. |
|
41 |
" |
|
42 |
! |
|
43 |
||
44 |
documentation |
|
45 |
" |
|
111 | 46 |
Instances of IPSocketAddress represent tcp/ip-domain socket addresses. |
47 |
These consist of an ip address (4 bytes) and a port number. |
|
48 |
||
1877
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
49 |
Notice that for performance, name and address translations are cached here |
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
50 |
for some time, in order to speed up heavy lookup such as when operating a webserver or similar |
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
51 |
application which does many address-to-hostname translations. |
100 | 52 |
|
1877
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
53 |
For systems, when the name translation is fast (unix), you may want to disable it, |
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
54 |
as it prevents new addresses to be detected for some time (for example, if the own address |
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
55 |
changes due to a new dhcp address being aquired). |
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
56 |
You can also change the cacheing-interval time |
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
57 |
(see caching protocol, flush*Cache, cachingIntervalTime, *CacheSize). |
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
58 |
|
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
59 |
[author:] |
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
60 |
Claus Gittinger |
100 | 61 |
" |
62 |
! ! |
|
63 |
||
1233 | 64 |
!IPSocketAddress class methodsFor:'instance creation'! |
65 |
||
1559
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1452
diff
changeset
|
66 |
addressString:aString |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1452
diff
changeset
|
67 |
"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
|
68 |
|
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1452
diff
changeset
|
69 |
^ 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
|
70 |
|
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1452
diff
changeset
|
71 |
" |
1585 | 72 |
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
|
73 |
" |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1452
diff
changeset
|
74 |
! |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1452
diff
changeset
|
75 |
|
1909
c76efba26558
Methods to get all addresses for a given hostname (multihomed hosts)
Stefan Vogel <sv@exept.de>
parents:
1883
diff
changeset
|
76 |
allForHostName:name serviceName:portNrOrName type:socketTypeSymbol |
c76efba26558
Methods to get all addresses for a given hostname (multihomed hosts)
Stefan Vogel <sv@exept.de>
parents:
1883
diff
changeset
|
77 |
"get a collection of new instance given a hostname, port or service and type. |
c76efba26558
Methods to get all addresses for a given hostname (multihomed hosts)
Stefan Vogel <sv@exept.de>
parents:
1883
diff
changeset
|
78 |
Multi-homed hosts return more than one entry |
1262
d3daddd36a99
no longer callBack into sockets getHostName/getAddress code.
Claus Gittinger <cg@exept.de>
parents:
1261
diff
changeset
|
79 |
Redefined to cache the result of the name-lookup." |
1233 | 80 |
|
1909
c76efba26558
Methods to get all addresses for a given hostname (multihomed hosts)
Stefan Vogel <sv@exept.de>
parents:
1883
diff
changeset
|
81 |
|addressList| |
1233 | 82 |
|
83 |
portNrOrName isString ifTrue:[ |
|
1909
c76efba26558
Methods to get all addresses for a given hostname (multihomed hosts)
Stefan Vogel <sv@exept.de>
parents:
1883
diff
changeset
|
84 |
^ super allForHostName:name serviceName:portNrOrName type:socketTypeSymbol |
1233 | 85 |
]. |
86 |
||
1909
c76efba26558
Methods to get all addresses for a given hostname (multihomed hosts)
Stefan Vogel <sv@exept.de>
parents:
1883
diff
changeset
|
87 |
addressList := self addressCacheAt:name. |
c76efba26558
Methods to get all addresses for a given hostname (multihomed hosts)
Stefan Vogel <sv@exept.de>
parents:
1883
diff
changeset
|
88 |
addressList notNil ifTrue:[ |
2172 | 89 |
addressList := addressList |
90 |
collect:[:eachSocketAddress| |sa| |
|
91 |
sa := eachSocketAddress copy. |
|
92 |
sa port:(portNrOrName ? 0). |
|
93 |
sa |
|
94 |
]. |
|
1233 | 95 |
] ifFalse:[ |
1909
c76efba26558
Methods to get all addresses for a given hostname (multihomed hosts)
Stefan Vogel <sv@exept.de>
parents:
1883
diff
changeset
|
96 |
addressList := super allForHostName:name serviceName:portNrOrName type:socketTypeSymbol. |
2172 | 97 |
self addressCacheAt:name put:(addressList deepCopy). |
1233 | 98 |
]. |
1909
c76efba26558
Methods to get all addresses for a given hostname (multihomed hosts)
Stefan Vogel <sv@exept.de>
parents:
1883
diff
changeset
|
99 |
^ addressList |
1233 | 100 |
|
101 |
" |
|
1909
c76efba26558
Methods to get all addresses for a given hostname (multihomed hosts)
Stefan Vogel <sv@exept.de>
parents:
1883
diff
changeset
|
102 |
SocketAddress allForHostName:'localhost' serviceName:10 type:#stream |
c76efba26558
Methods to get all addresses for a given hostname (multihomed hosts)
Stefan Vogel <sv@exept.de>
parents:
1883
diff
changeset
|
103 |
IPSocketAddress allForHostName:'localhost' serviceName:'echo' type:#datagram |
c76efba26558
Methods to get all addresses for a given hostname (multihomed hosts)
Stefan Vogel <sv@exept.de>
parents:
1883
diff
changeset
|
104 |
IPSocketAddress allForHostName:'www.google.com' serviceName:80 type:nil |
1233 | 105 |
" |
2172 | 106 |
|
107 |
"Modified: / 17-06-2009 / 15:21:00 / sr" |
|
1559
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1452
diff
changeset
|
108 |
! |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1452
diff
changeset
|
109 |
|
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1452
diff
changeset
|
110 |
localHost |
1883 | 111 |
"get a new instance representing the local-host address as seen internally" |
1559
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1452
diff
changeset
|
112 |
|
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1452
diff
changeset
|
113 |
^ self hostAddress:(self local) port:self anyPort |
1877
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
114 |
|
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
115 |
" |
1909
c76efba26558
Methods to get all addresses for a given hostname (multihomed hosts)
Stefan Vogel <sv@exept.de>
parents:
1883
diff
changeset
|
116 |
self localHost |
1877
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
117 |
self localHost hostName |
1909
c76efba26558
Methods to get all addresses for a given hostname (multihomed hosts)
Stefan Vogel <sv@exept.de>
parents:
1883
diff
changeset
|
118 |
self hostName:(OperatingSystem getHostName) |
1877
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
119 |
" |
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
120 |
|
1883 | 121 |
"Modified: / 04-06-2007 / 21:34:22 / cg" |
122 |
! |
|
123 |
||
124 |
localHostAddress |
|
1909
c76efba26558
Methods to get all addresses for a given hostname (multihomed hosts)
Stefan Vogel <sv@exept.de>
parents:
1883
diff
changeset
|
125 |
"NO NO NEVER!! |
c76efba26558
Methods to get all addresses for a given hostname (multihomed hosts)
Stefan Vogel <sv@exept.de>
parents:
1883
diff
changeset
|
126 |
Do not use this, because: |
c76efba26558
Methods to get all addresses for a given hostname (multihomed hosts)
Stefan Vogel <sv@exept.de>
parents:
1883
diff
changeset
|
127 |
1. It does not work on hosts that get their IP address via dhcp (at least on unix/linux) |
c76efba26558
Methods to get all addresses for a given hostname (multihomed hosts)
Stefan Vogel <sv@exept.de>
parents:
1883
diff
changeset
|
128 |
2. Usually OperatingSystem>>#getHostName does not return a fully qualified domain name |
c76efba26558
Methods to get all addresses for a given hostname (multihomed hosts)
Stefan Vogel <sv@exept.de>
parents:
1883
diff
changeset
|
129 |
3. This does not work well on multi-homed hosts" |
1883 | 130 |
|
1909
c76efba26558
Methods to get all addresses for a given hostname (multihomed hosts)
Stefan Vogel <sv@exept.de>
parents:
1883
diff
changeset
|
131 |
<resource: #obsolete> |
c76efba26558
Methods to get all addresses for a given hostname (multihomed hosts)
Stefan Vogel <sv@exept.de>
parents:
1883
diff
changeset
|
132 |
|
c76efba26558
Methods to get all addresses for a given hostname (multihomed hosts)
Stefan Vogel <sv@exept.de>
parents:
1883
diff
changeset
|
133 |
self obsoleteMethodWarning:'Do not use this method'. |
c76efba26558
Methods to get all addresses for a given hostname (multihomed hosts)
Stefan Vogel <sv@exept.de>
parents:
1883
diff
changeset
|
134 |
^ self hostName:(OperatingSystem getHostName). |
1883 | 135 |
|
136 |
" |
|
1909
c76efba26558
Methods to get all addresses for a given hostname (multihomed hosts)
Stefan Vogel <sv@exept.de>
parents:
1883
diff
changeset
|
137 |
self localHostAddress |
1883 | 138 |
" |
139 |
||
1909
c76efba26558
Methods to get all addresses for a given hostname (multihomed hosts)
Stefan Vogel <sv@exept.de>
parents:
1883
diff
changeset
|
140 |
|
1883 | 141 |
"Modified: / 04-06-2007 / 21:17:25 / cg" |
1233 | 142 |
! ! |
143 |
||
1164 | 144 |
!IPSocketAddress class methodsFor:'addressing'! |
145 |
||
146 |
anyAddress |
|
1281 | 147 |
"return the anonymous addresses bytes" |
1164 | 148 |
|
1281 | 149 |
^ #[0 0 0 0] |
1164 | 150 |
! |
151 |
||
152 |
anyPort |
|
153 |
"return the anon port number" |
|
154 |
||
155 |
^ 0 |
|
156 |
! |
|
100 | 157 |
|
1281 | 158 |
broadcastAddress |
159 |
"return the broadcast address" |
|
160 |
||
161 |
^ #[255 255 255 255] |
|
162 |
! |
|
163 |
||
1164 | 164 |
firstUnreservedPort |
165 |
"return the first unreserved port number" |
|
166 |
||
167 |
^ 1024 |
|
168 |
! |
|
169 |
||
170 |
local |
|
171 |
"return IN_ADDR_ANY, the address matching any local address" |
|
172 |
||
173 |
^ #[127 0 0 1] |
|
100 | 174 |
! |
175 |
||
1164 | 176 |
maxPort |
177 |
"return the maximum port number" |
|
100 | 178 |
|
1164 | 179 |
^ 16rffff |
816 | 180 |
! |
181 |
||
1164 | 182 |
thisHost |
3044 | 183 |
<resource: #obsolete> |
1226
0114bd044aa9
vw compatible domainSymbols (afXXX)
Claus Gittinger <cg@exept.de>
parents:
1164
diff
changeset
|
184 |
"return the bytes of IN_ADDR_ANY, the address matching any local address" |
1164 | 185 |
|
3044 | 186 |
self obsoleteMethodWarning. |
187 |
^ self anyAddress |
|
1164 | 188 |
! ! |
189 |
||
1273
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
190 |
!IPSocketAddress class methodsFor:'caching'! |
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 |
addressCacheAt:aHostName |
1909
c76efba26558
Methods to get all addresses for a given hostname (multihomed hosts)
Stefan Vogel <sv@exept.de>
parents:
1883
diff
changeset
|
193 |
|addrAndTime addressList time| |
1877
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
194 |
|
1273
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
195 |
addrCache notNil ifTrue:[ |
1877
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
196 |
addrAndTime := addrCache at:aHostName ifAbsent:nil. |
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
197 |
addrAndTime notNil ifTrue:[ |
1909
c76efba26558
Methods to get all addresses for a given hostname (multihomed hosts)
Stefan Vogel <sv@exept.de>
parents:
1883
diff
changeset
|
198 |
addressList := addrAndTime key. |
1877
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
199 |
time := addrAndTime value. |
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
200 |
((Timestamp now) secondDeltaFrom:time) > self cacheInvalidationTimeInterval ifFalse:[ |
1909
c76efba26558
Methods to get all addresses for a given hostname (multihomed hosts)
Stefan Vogel <sv@exept.de>
parents:
1883
diff
changeset
|
201 |
^ addressList. |
1877
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
202 |
] |
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
203 |
]. |
1273
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
204 |
]. |
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
205 |
^ nil |
1877
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
206 |
|
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
207 |
"Modified: / 26-04-2007 / 11:21:37 / cg" |
1273
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
208 |
! |
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
209 |
|
1909
c76efba26558
Methods to get all addresses for a given hostname (multihomed hosts)
Stefan Vogel <sv@exept.de>
parents:
1883
diff
changeset
|
210 |
addressCacheAt:aName put:anAddressList |
1877
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
211 |
(addrCache isNil or:[addrCache size > self addressCacheSize]) ifTrue:[ |
1273
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
212 |
addrCache := Dictionary new. |
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
213 |
]. |
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
214 |
|
1909
c76efba26558
Methods to get all addresses for a given hostname (multihomed hosts)
Stefan Vogel <sv@exept.de>
parents:
1883
diff
changeset
|
215 |
addrCache at:aName put:(anAddressList -> Timestamp now). |
1877
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
216 |
|
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
217 |
"Modified: / 26-04-2007 / 11:23:26 / cg" |
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
218 |
! |
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
219 |
|
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
220 |
addressCacheSize |
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
221 |
^ AddressCacheSize ? 50 |
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
222 |
|
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
223 |
"Created: / 26-04-2007 / 11:22:40 / cg" |
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
224 |
! |
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
225 |
|
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
226 |
addressCacheSize:aNumber |
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
227 |
AddressCacheSize := aNumber |
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
228 |
|
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
229 |
"Created: / 26-04-2007 / 11:24:05 / cg" |
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
230 |
! |
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
231 |
|
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
232 |
cacheInvalidationTimeInterval |
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
233 |
^ CacheInvalidationTimeInterval ? 30 |
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
234 |
|
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
235 |
"Created: / 26-04-2007 / 11:21:31 / cg" |
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
236 |
! |
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
237 |
|
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
238 |
cacheInvalidationTimeInterval:seconds |
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
239 |
CacheInvalidationTimeInterval := seconds |
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
240 |
|
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
241 |
"Created: / 26-04-2007 / 11:29:28 / cg" |
1273
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
242 |
! |
1261 | 243 |
|
244 |
flushAddressCache |
|
1273
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
245 |
addrCache := nil |
1261 | 246 |
|
247 |
" |
|
248 |
self flushAddressCache |
|
249 |
" |
|
1273
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
250 |
! |
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
251 |
|
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
252 |
flushNameCache |
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
253 |
nameCache := Dictionary new. |
1877
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
254 |
|
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
255 |
" |
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
256 |
self flushNameCache |
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
257 |
" |
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
258 |
|
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
259 |
"Modified: / 26-04-2007 / 11:25:32 / cg" |
1273
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
260 |
! |
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
261 |
|
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
262 |
nameCacheAt:aHostAddress |
1877
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
263 |
|nameAndTime name time| |
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
264 |
|
1273
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
265 |
nameCache notNil ifTrue:[ |
1877
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
266 |
nameAndTime := nameCache at:aHostAddress ifAbsent:nil. |
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
267 |
nameAndTime notNil ifTrue:[ |
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
268 |
name := nameAndTime key. |
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
269 |
time := nameAndTime value. |
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
270 |
((Timestamp now) secondDeltaFrom:time) > self cacheInvalidationTimeInterval ifFalse:[ |
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
271 |
^ name. |
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
272 |
] |
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
273 |
]. |
1273
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
274 |
]. |
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
275 |
^ nil |
1877
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
276 |
|
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
277 |
"Modified: / 26-04-2007 / 11:25:11 / cg" |
1273
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
278 |
! |
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
279 |
|
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
280 |
nameCacheAt:aHostAddress put:aName |
1877
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
281 |
(nameCache isNil or:[nameCache size > self nameCacheSize]) ifTrue:[ |
1273
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
282 |
nameCache := Dictionary new. |
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
283 |
]. |
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
284 |
|
1877
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
285 |
nameCache at:aHostAddress put:(aName -> Timestamp now). |
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
286 |
|
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
287 |
"Modified: / 26-04-2007 / 11:23:35 / cg" |
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
288 |
! |
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
289 |
|
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
290 |
nameCacheSize |
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
291 |
^ NameCacheSize ? 50 |
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
292 |
|
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
293 |
"Created: / 26-04-2007 / 11:22:44 / cg" |
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
294 |
! |
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
295 |
|
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
296 |
nameCacheSize:aNumber |
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
297 |
NameCacheSize := aNumber |
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
298 |
|
d143433fd007
cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
299 |
"Created: / 26-04-2007 / 11:23:49 / cg" |
1261 | 300 |
! ! |
301 |
||
1559
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1452
diff
changeset
|
302 |
!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
|
303 |
|
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1452
diff
changeset
|
304 |
hostAddressFromString:aString |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1452
diff
changeset
|
305 |
"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
|
306 |
|
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1452
diff
changeset
|
307 |
|components bytes| |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1452
diff
changeset
|
308 |
|
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1452
diff
changeset
|
309 |
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
|
310 |
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
|
311 |
^ 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
|
312 |
]. |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1452
diff
changeset
|
313 |
|
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1452
diff
changeset
|
314 |
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
|
315 |
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
|
316 |
]. |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1452
diff
changeset
|
317 |
|
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1452
diff
changeset
|
318 |
^ bytes asByteArray. |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1452
diff
changeset
|
319 |
|
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1452
diff
changeset
|
320 |
|
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1452
diff
changeset
|
321 |
" |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1452
diff
changeset
|
322 |
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
|
323 |
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
|
324 |
" |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1452
diff
changeset
|
325 |
! ! |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1452
diff
changeset
|
326 |
|
1164 | 327 |
!IPSocketAddress class methodsFor:'queries'! |
816 | 328 |
|
3052
e690209a5c52
changes #domainSymbol to #domain fpr comaptibility with Socket
Stefan Vogel <sv@exept.de>
parents:
3049
diff
changeset
|
329 |
domain |
1226
0114bd044aa9
vw compatible domainSymbols (afXXX)
Claus Gittinger <cg@exept.de>
parents:
1164
diff
changeset
|
330 |
^ #'AF_INET' |
0114bd044aa9
vw compatible domainSymbols (afXXX)
Claus Gittinger <cg@exept.de>
parents:
1164
diff
changeset
|
331 |
! |
0114bd044aa9
vw compatible domainSymbols (afXXX)
Claus Gittinger <cg@exept.de>
parents:
1164
diff
changeset
|
332 |
|
3044 | 333 |
hostAddressLen |
334 |
"answer the number of bytes of the host address" |
|
335 |
||
336 |
^ 4 |
|
337 |
! |
|
338 |
||
1226
0114bd044aa9
vw compatible domainSymbols (afXXX)
Claus Gittinger <cg@exept.de>
parents:
1164
diff
changeset
|
339 |
obsoleteDomainSymbol |
1164 | 340 |
^ #inet |
341 |
! |
|
342 |
||
1226
0114bd044aa9
vw compatible domainSymbols (afXXX)
Claus Gittinger <cg@exept.de>
parents:
1164
diff
changeset
|
343 |
vwDomainSymbol |
0114bd044aa9
vw compatible domainSymbols (afXXX)
Claus Gittinger <cg@exept.de>
parents:
1164
diff
changeset
|
344 |
^ #afInet |
100 | 345 |
! ! |
346 |
||
347 |
!IPSocketAddress methodsFor:'accessing'! |
|
348 |
||
818 | 349 |
hostAddress |
1164 | 350 |
^ (ByteArray new:4) replaceFrom:1 to:4 with:self startingAt:5 |
816 | 351 |
! |
352 |
||
1164 | 353 |
hostAddress:aByteArray |
354 |
^ self replaceFrom:5 to:8 with:aByteArray startingAt:1 |
|
818 | 355 |
! |
356 |
||
357 |
port |
|
1164 | 358 |
^ self unsignedShortAt:3 bigEndian:true |
818 | 359 |
! |
360 |
||
361 |
port:aPortNr |
|
1164 | 362 |
self unsignedShortAt:3 put:aPortNr bigEndian:true |
363 |
! ! |
|
364 |
||
365 |
!IPSocketAddress methodsFor:'obsolete'! |
|
366 |
||
367 |
address |
|
1452 | 368 |
<resource: #obsolete> |
369 |
||
1164 | 370 |
^ self hostAddress |
100 | 371 |
! ! |
372 |
||
770 | 373 |
!IPSocketAddress methodsFor:'printing & storing'! |
374 |
||
1333 | 375 |
printAddressOn:aStream |
376 |
|i1 i2| |
|
100 | 377 |
|
1233 | 378 |
i1 := self adrBytesStart. |
379 |
i2 := i1 + self numAdrBytes - 1. |
|
380 |
i1 to:i2 do:[:i | |
|
381 |
i ~~ i1 ifTrue:[ |
|
382 |
aStream nextPut:$. |
|
383 |
]. |
|
384 |
(self at:i) printOn:aStream |
|
1164 | 385 |
]. |
488 | 386 |
! ! |
387 |
||
1233 | 388 |
!IPSocketAddress methodsFor:'private'! |
389 |
||
390 |
adrBytesStart |
|
391 |
^ 5 |
|
392 |
! |
|
393 |
||
394 |
numAdrBytes |
|
395 |
^ 4 |
|
396 |
! ! |
|
397 |
||
398 |
!IPSocketAddress methodsFor:'queries'! |
|
399 |
||
400 |
hostName |
|
1273
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
401 |
|addr name| |
1233 | 402 |
|
1273
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
403 |
addr := self hostAddress. |
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
404 |
|
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
405 |
name := self class nameCacheAt:addr. |
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
406 |
name notNil ifTrue:[^ name]. |
1233 | 407 |
|
408 |
name := super hostName. |
|
409 |
name notNil ifTrue:[ |
|
1273
03afdf3f895e
addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
410 |
self class nameCacheAt:addr put:name. |
1233 | 411 |
]. |
412 |
^ name |
|
1337 | 413 |
! |
414 |
||
2567 | 415 |
netmaskSize |
416 |
"If this is an address mask: answer the number of mask bits in the address mask" |
|
417 |
||
418 |
|sz bI lowBit lowBitHere hostAddress| |
|
419 |
||
420 |
hostAddress := self hostAddress. |
|
421 |
||
422 |
lowBit := 0. |
|
423 |
bI := 1. |
|
424 |
sz := hostAddress size. |
|
425 |
[ |
|
426 |
lowBitHere := (hostAddress basicAt:bI) lowBit. |
|
427 |
lowBitHere ~= 0 ifTrue:[ |
|
428 |
lowBit := lowBit + (9 - lowBitHere). |
|
429 |
]. |
|
430 |
bI := bI + 1. |
|
431 |
] doWhile:[lowBitHere == 1 and:[bI < sz]]. |
|
432 |
||
433 |
^ lowBit |
|
434 |
||
435 |
" |
|
436 |
(IPSocketAddress addressString:'255.255.0.0') netmaskSize |
|
437 |
(IPSocketAddress addressString:'255.255.128.0') netmaskSize |
|
438 |
(IPv6SocketAddress addressString:'FFFF:FFFF:FFFF:FFFF::') netmaskSize |
|
439 |
(IPv6SocketAddress addressString:'FFFF:FFFF:FFFF:FFF0::') netmaskSize |
|
440 |
(IPv6SocketAddress addressString:'F0FF:FFFF:FFFF:FFF0::') netmaskSize |
|
441 |
" |
|
442 |
! |
|
443 |
||
1337 | 444 |
networkAddress |
2567 | 445 |
"THINK TWICE before using this!! |
446 |
This is deprecated, it doesn't make sense any longer since subnetting and netmasks |
|
447 |
have been introduced. |
|
448 |
||
449 |
Extract and return the network part from the host address." |
|
450 |
<resource: #obsolete> |
|
1337 | 451 |
|
452 |
|highAddrByte| |
|
453 |
||
454 |
highAddrByte := self at: 5. |
|
455 |
(highAddrByte bitAnd: 16r80) == 0 ifTrue: [^ByteArray with: highAddrByte]. |
|
456 |
(highAddrByte bitAnd: 16rC0) == 16r80 ifTrue: [^ByteArray with: highAddrByte with: (self at: 6)]. |
|
457 |
(highAddrByte bitAnd: 16rC0) == 16rC0 ifTrue: [^ByteArray with: highAddrByte with: (self at: 6) with: (self at: 7)]. |
|
458 |
^ self error: 'unknown network class' |
|
459 |
||
460 |
" |
|
461 |
(IPSocketAddress hostName:'exept.eu.org') networkAddress |
|
462 |
(IPSocketAddress hostName:'exept.exept.de') networkAddress |
|
463 |
(IPSocketAddress hostName:'ibm.com') networkAddress |
|
464 |
(IPSocketAddress hostName:'cnn.com') networkAddress |
|
465 |
" |
|
466 |
! |
|
467 |
||
468 |
networkClass |
|
2567 | 469 |
"THINK TWICE before using this!! |
470 |
This is deprecated, it doesn't make sense any longer since subnetting and netmasks |
|
471 |
have been introduced. |
|
472 |
||
473 |
Extract and return the network class (as a symbol) from the host address. |
|
1337 | 474 |
Returns one of #classA #classB #classC." |
2567 | 475 |
<resource: #obsolete> |
1337 | 476 |
|
477 |
|highAddrByte| |
|
478 |
||
479 |
highAddrByte := self at: 5. |
|
480 |
(highAddrByte bitAnd: 16r80) == 0 ifTrue: [^#classA]. |
|
481 |
(highAddrByte bitAnd: 16rC0) == 16r80 ifTrue: [^#classB]. |
|
482 |
(highAddrByte bitAnd: 16rC0) == 16rC0 ifTrue: [^#classC]. |
|
483 |
^ self error: 'unknown network class' |
|
484 |
||
485 |
" |
|
486 |
(IPSocketAddress hostName:'exept.eu.org') networkClass |
|
487 |
" |
|
1937 | 488 |
! |
489 |
||
490 |
portOrName |
|
491 |
^ self port |
|
1233 | 492 |
! ! |
493 |
||
1366
e01d0f6c102a
New method #isLocal returning true for local addresses
Stefan Vogel <sv@exept.de>
parents:
1337
diff
changeset
|
494 |
!IPSocketAddress methodsFor:'testing'! |
e01d0f6c102a
New method #isLocal returning true for local addresses
Stefan Vogel <sv@exept.de>
parents:
1337
diff
changeset
|
495 |
|
3049 | 496 |
isBroadcast |
497 |
"answer true, if this is a broadcast address" |
|
498 |
||
499 |
^ (self at:5) == 255 |
|
500 |
and:[self sameContentsFrom:6 to:8 as:#[255 255 255] startingAt:1] |
|
501 |
||
502 |
" |
|
503 |
(self hostAddress:self broadcastAddress) isBroadcast |
|
504 |
" |
|
505 |
! |
|
506 |
||
507 |
isIPSocketAddress |
|
508 |
^ true |
|
509 |
! |
|
510 |
||
511 |
isIPv4SocketAddress |
|
512 |
^ self class == IPSocketAddress |
|
513 |
! |
|
514 |
||
1366
e01d0f6c102a
New method #isLocal returning true for local addresses
Stefan Vogel <sv@exept.de>
parents:
1337
diff
changeset
|
515 |
isLocal |
e01d0f6c102a
New method #isLocal returning true for local addresses
Stefan Vogel <sv@exept.de>
parents:
1337
diff
changeset
|
516 |
"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
|
517 |
|
3049 | 518 |
^ (self at:5) == 127 |
519 |
||
520 |
" |
|
521 |
self localHost isLocal |
|
522 |
" |
|
523 |
! |
|
524 |
||
525 |
isMulticast |
|
526 |
"answer true, if this address is a multicast address 224.0.0.0/4 or Class D" |
|
527 |
||
528 |
^ (self at:5) between:224 and:239 |
|
3044 | 529 |
! |
530 |
||
531 |
isMyAddress |
|
532 |
"answer true, if the address refers to my own host" |
|
533 |
||
534 |
self isLocal ifTrue:[^ true]. |
|
535 |
||
3049 | 536 |
"/ For now - work only for ipv4... |
537 |
^ OperatingSystem getNetworkAddresses contains:[:each| |
|
538 |
self sameHostAddress:each |
|
3044 | 539 |
]. |
3049 | 540 |
|
541 |
"/ later, when getNetworkAddressInfo is implemented in Win32OperatingSystem |
|
542 |
"/ OperatingSystem getNetworkAddressInfo do:[:eachIfAddrInfoSet| |
|
543 |
"/ eachIfAddrInfoSet do:[:eachIfAddrInfo| |
|
544 |
"/ |address| |
|
545 |
"/ address := eachIfAddrInfo at:#address ifAbsent:nil. |
|
546 |
"/ address notNil ifTrue:[ |
|
547 |
"/ (self sameHostAddress:address) ifTrue:[^ true]. |
|
548 |
"/ ] |
|
549 |
"/ ]. |
|
550 |
"/ ]. |
|
551 |
"/ ^ false |
|
3044 | 552 |
|
553 |
" |
|
554 |
(IPSocketAddress hostAddress:#[193 141 12 193] port:80) isMyAddress. |
|
555 |
(IPSocketAddress hostAddress:#[172 23 1 88] port:80) isMyAddress. |
|
3049 | 556 |
(IPSocketAddress hostAddress:#[192 168 23 29] port:80) isMyAddress. |
3044 | 557 |
" |
1366
e01d0f6c102a
New method #isLocal returning true for local addresses
Stefan Vogel <sv@exept.de>
parents:
1337
diff
changeset
|
558 |
! ! |
e01d0f6c102a
New method #isLocal returning true for local addresses
Stefan Vogel <sv@exept.de>
parents:
1337
diff
changeset
|
559 |
|
488 | 560 |
!IPSocketAddress class methodsFor:'documentation'! |
100 | 561 |
|
488 | 562 |
version |
3052
e690209a5c52
changes #domainSymbol to #domain fpr comaptibility with Socket
Stefan Vogel <sv@exept.de>
parents:
3049
diff
changeset
|
563 |
^ '$Header: /cvs/stx/stx/libbasic2/IPSocketAddress.st,v 1.38 2013-07-11 15:02:07 stefan Exp $' |
2567 | 564 |
! |
565 |
||
566 |
version_CVS |
|
3052
e690209a5c52
changes #domainSymbol to #domain fpr comaptibility with Socket
Stefan Vogel <sv@exept.de>
parents:
3049
diff
changeset
|
567 |
^ '$Header: /cvs/stx/stx/libbasic2/IPSocketAddress.st,v 1.38 2013-07-11 15:02:07 stefan Exp $' |
100 | 568 |
! ! |
3044 | 569 |