author | Stefan Vogel <sv@exept.de> |
Thu, 11 Jul 2013 13:37:57 +0200 | |
changeset 3050 | b60ffb4b201a |
parent 3045 | 7663a852fa0b |
child 3053 | b5b13e505486 |
permissions | -rw-r--r-- |
815 | 1 |
" |
2 |
COPYRIGHT (c) 1999 by eXept Software AG |
|
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 |
" |
|
1162
c8ba14f81f13
Prepare new socketb implementation
Stefan Vogel <sv@exept.de>
parents:
818
diff
changeset
|
12 |
"{ Package: 'stx:libbasic2' }" |
c8ba14f81f13
Prepare new socketb implementation
Stefan Vogel <sv@exept.de>
parents:
818
diff
changeset
|
13 |
|
818 | 14 |
IPSocketAddress variableByteSubclass:#IPv6SocketAddress |
815 | 15 |
instanceVariableNames:'' |
16 |
classVariableNames:'' |
|
17 |
poolDictionaries:'' |
|
1167 | 18 |
category:'OS-Sockets' |
815 | 19 |
! |
20 |
||
21 |
!IPv6SocketAddress class methodsFor:'documentation'! |
|
22 |
||
23 |
copyright |
|
24 |
" |
|
25 |
COPYRIGHT (c) 1999 by eXept Software AG |
|
26 |
All Rights Reserved |
|
27 |
||
28 |
This software is furnished under a license and may be used |
|
29 |
only in accordance with the terms of that license and with the |
|
30 |
inclusion of the above copyright notice. This software may not |
|
31 |
be provided or otherwise made available to, or used by, any |
|
32 |
other person. No title to or ownership of the software is |
|
33 |
hereby transferred. |
|
34 |
" |
|
35 |
||
36 |
||
37 |
! |
|
38 |
||
39 |
documentation |
|
40 |
" |
|
41 |
Instances of IPv6SocketAddress represent v6 IP socket addresses. |
|
42 |
These consist of a 16byte hostId and a port number. |
|
43 |
||
1162
c8ba14f81f13
Prepare new socketb implementation
Stefan Vogel <sv@exept.de>
parents:
818
diff
changeset
|
44 |
Contains |
c8ba14f81f13
Prepare new socketb implementation
Stefan Vogel <sv@exept.de>
parents:
818
diff
changeset
|
45 |
2 byte domain AF_INET6 |
c8ba14f81f13
Prepare new socketb implementation
Stefan Vogel <sv@exept.de>
parents:
818
diff
changeset
|
46 |
2 byte port |
c8ba14f81f13
Prepare new socketb implementation
Stefan Vogel <sv@exept.de>
parents:
818
diff
changeset
|
47 |
4 byte flowInfo |
c8ba14f81f13
Prepare new socketb implementation
Stefan Vogel <sv@exept.de>
parents:
818
diff
changeset
|
48 |
16 byte address |
c8ba14f81f13
Prepare new socketb implementation
Stefan Vogel <sv@exept.de>
parents:
818
diff
changeset
|
49 |
4 byte scope |
815 | 50 |
|
51 |
[author:] |
|
52 |
Claus Gittinger (cg@exept) |
|
53 |
||
54 |
[see also:] |
|
55 |
||
56 |
[instance variables:] |
|
57 |
||
58 |
[class variables:] |
|
59 |
" |
|
60 |
! ! |
|
61 |
||
1281 | 62 |
!IPv6SocketAddress class methodsFor:'addressing'! |
63 |
||
64 |
anyAddress |
|
65 |
"return the anonymous addresses bytes" |
|
66 |
||
67 |
^ #[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] |
|
1366
e01d0f6c102a
New method #isLocal returning true for local addresses
Stefan Vogel <sv@exept.de>
parents:
1281
diff
changeset
|
68 |
! |
e01d0f6c102a
New method #isLocal returning true for local addresses
Stefan Vogel <sv@exept.de>
parents:
1281
diff
changeset
|
69 |
|
3045 | 70 |
broadcastAddress |
71 |
"return the addresses bytes of a broadcast address |
|
3050 | 72 |
(this is the all-nodes link-local address ff02::1. |
3045 | 73 |
Broadcast is not normally used in IPv6" |
74 |
||
3050 | 75 |
^ #[16rff 16r02 0 0 0 0 0 0 0 0 0 0 0 0 0 16r01] |
3045 | 76 |
! |
77 |
||
1366
e01d0f6c102a
New method #isLocal returning true for local addresses
Stefan Vogel <sv@exept.de>
parents:
1281
diff
changeset
|
78 |
local |
e01d0f6c102a
New method #isLocal returning true for local addresses
Stefan Vogel <sv@exept.de>
parents:
1281
diff
changeset
|
79 |
"return the addresses bytes addressing the local host" |
e01d0f6c102a
New method #isLocal returning true for local addresses
Stefan Vogel <sv@exept.de>
parents:
1281
diff
changeset
|
80 |
|
e01d0f6c102a
New method #isLocal returning true for local addresses
Stefan Vogel <sv@exept.de>
parents:
1281
diff
changeset
|
81 |
^ #[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1] |
1281 | 82 |
! ! |
83 |
||
1559
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
84 |
!IPv6SocketAddress class methodsFor:'conversion'! |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
85 |
|
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
86 |
hostAddressFromString:aString |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
87 |
"convert an address given in a dot notation like 1:2:3:4:5:6:7:8 or ::1 or even ::" |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
88 |
|
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
89 |
|components words bytes prevWord bytesToGenerate i| |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
90 |
|
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
91 |
components := aString asCollectionOfSubstringsSeparatedBy:$:. |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
92 |
components size > 8 ifTrue:[ |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
93 |
^ NameLookupError raiseRequestWith:aString |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
94 |
errorString:' - bad address string'. |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
95 |
]. |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
96 |
|
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
97 |
(components last occurrencesOf:$.) == 3 ifTrue:[ |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
98 |
"IPV4 address embedded" |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
99 |
bytes := IPSocketAddress hostAddressFromString:components removeLast. |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
100 |
components add:(((bytes at:1) bitShift:8) bitOr:(bytes at:2)). |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
101 |
components add:(((bytes at:3) bitShift:8) bitOr:(bytes at:4)) . |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
102 |
]. |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
103 |
words := components |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
104 |
collect:[:eachComponent | |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
105 |
eachComponent size == 0 ifTrue:[ |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
106 |
eachComponent isInteger ifTrue:[eachComponent] ifFalse:[nil]. |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
107 |
] ifFalse:[ |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
108 |
Integer |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
109 |
readFromString:eachComponent |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
110 |
radix:16 |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
111 |
onError:[ |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
112 |
^ NameLookupError raiseRequestWith:aString |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
113 |
errorString:' - bad address string' |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
114 |
]. |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
115 |
]. |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
116 |
]. |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
117 |
|
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
118 |
bytes := ByteArray new:16. |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
119 |
bytesToGenerate := 2 * (8 - words size). |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
120 |
i := 1. |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
121 |
words do:[:eachWord| |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
122 |
eachWord == nil ifTrue:[ |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
123 |
i ~~ 1 ifTrue:[ |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
124 |
i := i + bytesToGenerate. |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
125 |
bytesToGenerate := 0. |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
126 |
]. |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
127 |
] ifFalse:[ |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
128 |
bytes at:i put:(eachWord digitByteAt:2). |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
129 |
bytes at:i+1 put:(eachWord digitByteAt:1). |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
130 |
]. |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
131 |
i := i + 2. |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
132 |
prevWord := eachWord. |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
133 |
]. |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
134 |
|
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
135 |
^ bytes. |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
136 |
|
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
137 |
" |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
138 |
IPv6SocketAddress hostAddressFromString:'::' |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
139 |
IPv6SocketAddress hostAddressFromString:'::1' |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
140 |
IPv6SocketAddress hostAddressFromString:':1:2' |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
141 |
IPv6SocketAddress hostAddressFromString:'1::2' |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
142 |
IPv6SocketAddress hostAddressFromString:'1:2:3:4:5:6:7:8' |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
143 |
IPv6SocketAddress hostAddressFromString:'1234:5678:9abc:def1:2345:6789:abcd:ef12' |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
144 |
IPv6SocketAddress hostAddressFromString:'a:b:c:d:e:f:7:8' |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
145 |
IPv6SocketAddress hostAddressFromString:'1::2:3:4' |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
146 |
IPv6SocketAddress hostAddressFromString:'1:2:3::4' |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
147 |
IPv6SocketAddress hostAddressFromString:'::1.2.3.4' |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
148 |
" |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
149 |
! ! |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
150 |
|
1162
c8ba14f81f13
Prepare new socketb implementation
Stefan Vogel <sv@exept.de>
parents:
818
diff
changeset
|
151 |
!IPv6SocketAddress class methodsFor:'queries'! |
818 | 152 |
|
1162
c8ba14f81f13
Prepare new socketb implementation
Stefan Vogel <sv@exept.de>
parents:
818
diff
changeset
|
153 |
domainSymbol |
818 | 154 |
|
1226
0114bd044aa9
vw compatible domainSymbols (afXXX)
Claus Gittinger <cg@exept.de>
parents:
1167
diff
changeset
|
155 |
^ #'AF_INET6' |
0114bd044aa9
vw compatible domainSymbols (afXXX)
Claus Gittinger <cg@exept.de>
parents:
1167
diff
changeset
|
156 |
! |
0114bd044aa9
vw compatible domainSymbols (afXXX)
Claus Gittinger <cg@exept.de>
parents:
1167
diff
changeset
|
157 |
|
3045 | 158 |
hostAddressLen |
159 |
"answer the number of bytes of the host address" |
|
160 |
||
3050 | 161 |
^ 16 |
3045 | 162 |
! |
163 |
||
1226
0114bd044aa9
vw compatible domainSymbols (afXXX)
Claus Gittinger <cg@exept.de>
parents:
1167
diff
changeset
|
164 |
obsoleteDomainSymbol |
1162
c8ba14f81f13
Prepare new socketb implementation
Stefan Vogel <sv@exept.de>
parents:
818
diff
changeset
|
165 |
^ #inet6 |
815 | 166 |
! ! |
167 |
||
1231 | 168 |
!IPv6SocketAddress methodsFor:'accessing'! |
169 |
||
2568 | 170 |
flowInfo |
171 |
"/ struct sockaddr_in6 { |
|
172 |
"/ 0 unsigned short int sin6_family; /* AF_INET6 */ |
|
173 |
"/ 2 __u16 sin6_port; /* Transport layer port # */ |
|
174 |
"/ 4 __u32 sin6_flowinfo; /* IPv6 flow information */ |
|
175 |
"/ 8 struct in6_addr sin6_addr; /* IPv6 address */ |
|
176 |
"/ 24 __u32 sin6_scope_id; /* scope id (new in RFC2553) */ |
|
177 |
"/ 28 }; |
|
178 |
^ self unsignedLongAt:5 bigEndian:false. |
|
179 |
! |
|
180 |
||
1231 | 181 |
hostAddress |
182 |
"/ struct sockaddr_in6 { |
|
2568 | 183 |
"/ 0 unsigned short int sin6_family; /* AF_INET6 */ |
184 |
"/ 2 __u16 sin6_port; /* Transport layer port # */ |
|
185 |
"/ 4 __u32 sin6_flowinfo; /* IPv6 flow information */ |
|
186 |
"/ 8 struct in6_addr sin6_addr; /* IPv6 address */ |
|
187 |
"/ 24 __u32 sin6_scope_id; /* scope id (new in RFC2553) */ |
|
188 |
"/ 28 }; |
|
1559
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
189 |
^ (ByteArray new:16) replaceFrom:1 to:16 with:self startingAt:9 |
1231 | 190 |
! |
191 |
||
192 |
hostAddress:aByteArray |
|
193 |
^ self replaceFrom:9 to:9+16-1 with:aByteArray startingAt:1 |
|
2568 | 194 |
! |
195 |
||
196 |
scopeId |
|
197 |
"/ struct sockaddr_in6 { |
|
198 |
"/ 0 unsigned short int sin6_family; /* AF_INET6 */ |
|
199 |
"/ 2 __u16 sin6_port; /* Transport layer port # */ |
|
200 |
"/ 4 __u32 sin6_flowinfo; /* IPv6 flow information */ |
|
201 |
"/ 8 struct in6_addr sin6_addr; /* IPv6 address */ |
|
202 |
"/ 24 __u32 sin6_scope_id; /* scope id (new in RFC2553) */ |
|
203 |
"/ 28 }; |
|
204 |
^ self unsignedLongAt:25 bigEndian:false. |
|
1231 | 205 |
! ! |
206 |
||
1559
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
207 |
!IPv6SocketAddress methodsFor:'printing & storing'! |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
208 |
|
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
209 |
printAddressOn:aStream |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
210 |
|i1 i2 colons| |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
211 |
|
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
212 |
colons := 0. |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
213 |
i1 := self adrBytesStart. |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
214 |
i2 := i1 + self numAdrBytes - 1. |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
215 |
i1 to:i2 by:2 do:[:i | |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
216 |
|word| |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
217 |
|
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
218 |
word := self wordAt:i MSB:true. |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
219 |
word == 0 ifTrue:[ |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
220 |
(colons <= 1 and:[i ~~ (i2-1)]) ifTrue:[ |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
221 |
colons := colons + 1. |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
222 |
aStream nextPut:$: |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
223 |
] |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
224 |
] ifFalse:[ |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
225 |
word printOn:aStream base:16. |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
226 |
i ~~ (i2-1) ifTrue:[ |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
227 |
aStream nextPut:$:. |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
228 |
colons >= 2 ifTrue:[ |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
229 |
colons := -20. "no more $: may be omitted" |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
230 |
] ifFalse:[ |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
231 |
colons positive ifTrue:[colons := 1]. |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
232 |
] |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
233 |
]. |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
234 |
]. |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
235 |
]. |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
236 |
|
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
237 |
" |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
238 |
String streamContents:[:s | self localHost printAddressOn:s] |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
239 |
String streamContents:[:s |(self hostAddress:#[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]) printAddressOn:s] |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
240 |
String streamContents:[:s |(self hostAddress:#[1 2 3 4 5 6 7 8 0 0 0 0 0 0 0 0]) printAddressOn:s] |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
241 |
String streamContents:[:s |(self hostAddress:#[0 0 0 0 0 0 0 0 1 2 3 4 5 6 7 8]) printAddressOn:s] |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
242 |
String streamContents:[:s |(self hostAddress:#[0 0 0 0 1 2 3 4 5 6 7 8 0 0 0 0]) printAddressOn:s] |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
243 |
String streamContents:[:s |(self hostAddress:#[16r1a 16r1b 0 0 0 0 0 0 0 0 0 0 0 0 0 0]) printAddressOn:s] |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
244 |
" |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
245 |
! ! |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
246 |
|
1231 | 247 |
!IPv6SocketAddress methodsFor:'private'! |
248 |
||
249 |
adrBytesStart |
|
250 |
^ 9 |
|
251 |
! |
|
252 |
||
253 |
numAdrBytes |
|
254 |
^ 16 |
|
255 |
! ! |
|
256 |
||
2568 | 257 |
!IPv6SocketAddress methodsFor:'queries'! |
258 |
||
259 |
networkAddress |
|
260 |
<resource: #obsolete> |
|
261 |
^ self shouldNotImplement |
|
262 |
! |
|
263 |
||
264 |
networkClass |
|
265 |
"IPV6 doesn't know about network classes" |
|
266 |
<resource: #obsolete> |
|
267 |
||
268 |
^ self shouldNotImplement |
|
269 |
! ! |
|
270 |
||
1366
e01d0f6c102a
New method #isLocal returning true for local addresses
Stefan Vogel <sv@exept.de>
parents:
1281
diff
changeset
|
271 |
!IPv6SocketAddress methodsFor:'testing'! |
e01d0f6c102a
New method #isLocal returning true for local addresses
Stefan Vogel <sv@exept.de>
parents:
1281
diff
changeset
|
272 |
|
3050 | 273 |
isBroadcast |
274 |
"answer true, if this is a broadcast address: |
|
275 |
all node-local nodes: ff01::1 |
|
276 |
all link-local nodes: ff02::1" |
|
277 |
||
278 |
^ (self at:9) == 16rff |
|
279 |
and:[((self at:10) bitAnd:16r03) ~~ 0 |
|
280 |
and:[self sameContentsFrom:11 to:24 as:#[0 0 0 0 0 0 0 0 0 0 0 0 0 1] startingAt:1]] |
|
281 |
||
282 |
" |
|
283 |
(self addressString:'ff01::1') isBroadcast |
|
284 |
(self addressString:'ff02::1') isBroadcast |
|
285 |
(self addressString:'ff01::55') isBroadcast |
|
286 |
" |
|
287 |
! |
|
288 |
||
289 |
isGlobalUnicast |
|
290 |
"answer true, if this address is a global unicast address |
|
291 |
in the range 2000::/3" |
|
292 |
||
293 |
^ (self at:9) between:16r20 and:16r3f |
|
294 |
! |
|
295 |
||
296 |
isIPv6SocketAddress |
|
297 |
^ true |
|
298 |
! |
|
299 |
||
2568 | 300 |
isLinkLocalUnicast |
301 |
"answer true, if this address is a link local unicast address fe80::/10" |
|
302 |
||
303 |
^ (self at:9) == 16rfe and:[((self at:10) bitAnd:16rc0) == 16r80] |
|
304 |
! |
|
305 |
||
1366
e01d0f6c102a
New method #isLocal returning true for local addresses
Stefan Vogel <sv@exept.de>
parents:
1281
diff
changeset
|
306 |
isLocal |
3050 | 307 |
"answer true, if this address adresses a peer on the same host: ::1/128" |
1366
e01d0f6c102a
New method #isLocal returning true for local addresses
Stefan Vogel <sv@exept.de>
parents:
1281
diff
changeset
|
308 |
|
2568 | 309 |
^ (self at:9) == 0 and:[self hostAddress = self class local] |
3050 | 310 |
|
311 |
" |
|
312 |
self localHost isLocal |
|
313 |
" |
|
2568 | 314 |
! |
315 |
||
316 |
isMulticast |
|
3050 | 317 |
"answer true, if this address is a multicast address ff::/8" |
2568 | 318 |
|
319 |
^ (self at:9) == 16rff |
|
3050 | 320 |
! |
321 |
||
322 |
isUniqueLocalUnicast |
|
323 |
"answer true, if this address is a unique local unicast (e.g. private) address |
|
324 |
in the range fc::/8 or fd::/8" |
|
325 |
||
326 |
^ (self at:9) == 16rfc or:[(self at:9) == 16rfd] |
|
1366
e01d0f6c102a
New method #isLocal returning true for local addresses
Stefan Vogel <sv@exept.de>
parents:
1281
diff
changeset
|
327 |
! ! |
e01d0f6c102a
New method #isLocal returning true for local addresses
Stefan Vogel <sv@exept.de>
parents:
1281
diff
changeset
|
328 |
|
815 | 329 |
!IPv6SocketAddress class methodsFor:'documentation'! |
330 |
||
331 |
version |
|
3050 | 332 |
^ '$Header: /cvs/stx/stx/libbasic2/IPv6SocketAddress.st,v 1.16 2013-07-11 11:37:57 stefan Exp $' |
2568 | 333 |
! |
334 |
||
335 |
version_CVS |
|
3050 | 336 |
^ '$Header: /cvs/stx/stx/libbasic2/IPv6SocketAddress.st,v 1.16 2013-07-11 11:37:57 stefan Exp $' |
815 | 337 |
! ! |
3045 | 338 |