author | Stefan Vogel <sv@exept.de> |
Fri, 20 Mar 2020 13:01:09 +0100 | |
changeset 5469 | d78065ee4cff |
parent 4954 | 6a0f3ce56e46 |
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 |
|
3509 | 14 |
"{ NameSpace: Smalltalk }" |
15 |
||
818 | 16 |
IPSocketAddress variableByteSubclass:#IPv6SocketAddress |
815 | 17 |
instanceVariableNames:'' |
18 |
classVariableNames:'' |
|
19 |
poolDictionaries:'' |
|
1167 | 20 |
category:'OS-Sockets' |
815 | 21 |
! |
22 |
||
23 |
!IPv6SocketAddress class methodsFor:'documentation'! |
|
24 |
||
25 |
copyright |
|
26 |
" |
|
27 |
COPYRIGHT (c) 1999 by eXept Software AG |
|
28 |
All Rights Reserved |
|
29 |
||
30 |
This software is furnished under a license and may be used |
|
31 |
only in accordance with the terms of that license and with the |
|
32 |
inclusion of the above copyright notice. This software may not |
|
33 |
be provided or otherwise made available to, or used by, any |
|
34 |
other person. No title to or ownership of the software is |
|
35 |
hereby transferred. |
|
36 |
" |
|
37 |
||
38 |
||
39 |
! |
|
40 |
||
41 |
documentation |
|
42 |
" |
|
43 |
Instances of IPv6SocketAddress represent v6 IP socket addresses. |
|
44 |
These consist of a 16byte hostId and a port number. |
|
45 |
||
1162
c8ba14f81f13
Prepare new socketb implementation
Stefan Vogel <sv@exept.de>
parents:
818
diff
changeset
|
46 |
Contains |
c8ba14f81f13
Prepare new socketb implementation
Stefan Vogel <sv@exept.de>
parents:
818
diff
changeset
|
47 |
2 byte domain AF_INET6 |
c8ba14f81f13
Prepare new socketb implementation
Stefan Vogel <sv@exept.de>
parents:
818
diff
changeset
|
48 |
2 byte port |
c8ba14f81f13
Prepare new socketb implementation
Stefan Vogel <sv@exept.de>
parents:
818
diff
changeset
|
49 |
4 byte flowInfo |
c8ba14f81f13
Prepare new socketb implementation
Stefan Vogel <sv@exept.de>
parents:
818
diff
changeset
|
50 |
16 byte address |
c8ba14f81f13
Prepare new socketb implementation
Stefan Vogel <sv@exept.de>
parents:
818
diff
changeset
|
51 |
4 byte scope |
815 | 52 |
|
53 |
[author:] |
|
54 |
Claus Gittinger (cg@exept) |
|
55 |
||
56 |
[see also:] |
|
57 |
||
58 |
[instance variables:] |
|
59 |
||
60 |
[class variables:] |
|
61 |
" |
|
62 |
! ! |
|
63 |
||
1281 | 64 |
!IPv6SocketAddress class methodsFor:'addressing'! |
65 |
||
66 |
anyAddress |
|
67 |
"return the anonymous addresses bytes" |
|
68 |
||
69 |
^ #[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
|
70 |
! |
e01d0f6c102a
New method #isLocal returning true for local addresses
Stefan Vogel <sv@exept.de>
parents:
1281
diff
changeset
|
71 |
|
3045 | 72 |
broadcastAddress |
73 |
"return the addresses bytes of a broadcast address |
|
3050 | 74 |
(this is the all-nodes link-local address ff02::1. |
3045 | 75 |
Broadcast is not normally used in IPv6" |
76 |
||
3050 | 77 |
^ #[16rff 16r02 0 0 0 0 0 0 0 0 0 0 0 0 0 16r01] |
3045 | 78 |
! |
79 |
||
1366
e01d0f6c102a
New method #isLocal returning true for local addresses
Stefan Vogel <sv@exept.de>
parents:
1281
diff
changeset
|
80 |
local |
e01d0f6c102a
New method #isLocal returning true for local addresses
Stefan Vogel <sv@exept.de>
parents:
1281
diff
changeset
|
81 |
"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
|
82 |
|
e01d0f6c102a
New method #isLocal returning true for local addresses
Stefan Vogel <sv@exept.de>
parents:
1281
diff
changeset
|
83 |
^ #[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1] |
1281 | 84 |
! ! |
85 |
||
1559
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
86 |
!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
|
87 |
|
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
88 |
hostAddressFromString:aString |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
89 |
"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
|
90 |
|
4954 | 91 |
|components firstComponent lastComponent |
92 |
words bytes prevWord bytesToGenerate i| |
|
1559
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
93 |
|
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
94 |
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
|
95 |
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
|
96 |
^ 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
|
97 |
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
|
98 |
]. |
4954 | 99 |
(firstComponent := components first) notEmpty ifTrue:[ |
100 |
"allow addresses formated like: '[2001:4dd0:ffa3::1]'" |
|
101 |
firstComponent first = $[ ifTrue:[ |
|
102 |
components at:1 put:(firstComponent copyFrom:2). |
|
103 |
(lastComponent := components last) notEmpty ifTrue:[ |
|
104 |
lastComponent last = $] ifTrue:[ |
|
105 |
components at:components size put:(lastComponent copyButLast:1). |
|
106 |
]. |
|
107 |
]. |
|
3509 | 108 |
]. |
109 |
]. |
|
1559
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
110 |
(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
|
111 |
"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
|
112 |
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
|
113 |
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
|
114 |
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
|
115 |
]. |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
116 |
words := components |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
117 |
collect:[:eachComponent | |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
118 |
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
|
119 |
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
|
120 |
] ifFalse:[ |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
121 |
Integer |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
122 |
readFromString:eachComponent |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
123 |
radix:16 |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
124 |
onError:[ |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
125 |
^ 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
|
126 |
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
|
127 |
]. |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
128 |
]. |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
129 |
]. |
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 |
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
|
132 |
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
|
133 |
i := 1. |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
134 |
words do:[:eachWord| |
4284 | 135 |
eachWord isNil ifTrue:[ |
1559
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
136 |
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
|
137 |
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
|
138 |
bytesToGenerate := 0. |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
139 |
]. |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
140 |
] ifFalse:[ |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
141 |
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
|
142 |
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
|
143 |
]. |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
144 |
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
|
145 |
prevWord := eachWord. |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
146 |
]. |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
147 |
|
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
148 |
^ bytes. |
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 |
" |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
151 |
IPv6SocketAddress hostAddressFromString:'::' |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
152 |
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
|
153 |
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
|
154 |
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
|
155 |
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
|
156 |
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
|
157 |
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
|
158 |
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
|
159 |
IPv6SocketAddress hostAddressFromString:'1:2:3::4' |
3509 | 160 |
IPv6SocketAddress hostAddressFromString:'[1:2:3::4]' |
1559
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
161 |
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
|
162 |
" |
4954 | 163 |
|
164 |
"Modified: / 27-05-2019 / 14:09:49 / Claus Gittinger" |
|
1559
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
165 |
! ! |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
166 |
|
1162
c8ba14f81f13
Prepare new socketb implementation
Stefan Vogel <sv@exept.de>
parents:
818
diff
changeset
|
167 |
!IPv6SocketAddress class methodsFor:'queries'! |
818 | 168 |
|
3053
b5b13e505486
changes #domainSymbol to #domain fpr comaptibility with Socket
Stefan Vogel <sv@exept.de>
parents:
3050
diff
changeset
|
169 |
domain |
1226
0114bd044aa9
vw compatible domainSymbols (afXXX)
Claus Gittinger <cg@exept.de>
parents:
1167
diff
changeset
|
170 |
^ #'AF_INET6' |
0114bd044aa9
vw compatible domainSymbols (afXXX)
Claus Gittinger <cg@exept.de>
parents:
1167
diff
changeset
|
171 |
! |
0114bd044aa9
vw compatible domainSymbols (afXXX)
Claus Gittinger <cg@exept.de>
parents:
1167
diff
changeset
|
172 |
|
3045 | 173 |
hostAddressLen |
174 |
"answer the number of bytes of the host address" |
|
175 |
||
3050 | 176 |
^ 16 |
3045 | 177 |
! |
178 |
||
1226
0114bd044aa9
vw compatible domainSymbols (afXXX)
Claus Gittinger <cg@exept.de>
parents:
1167
diff
changeset
|
179 |
obsoleteDomainSymbol |
1162
c8ba14f81f13
Prepare new socketb implementation
Stefan Vogel <sv@exept.de>
parents:
818
diff
changeset
|
180 |
^ #inet6 |
3053
b5b13e505486
changes #domainSymbol to #domain fpr comaptibility with Socket
Stefan Vogel <sv@exept.de>
parents:
3050
diff
changeset
|
181 |
! |
b5b13e505486
changes #domainSymbol to #domain fpr comaptibility with Socket
Stefan Vogel <sv@exept.de>
parents:
3050
diff
changeset
|
182 |
|
b5b13e505486
changes #domainSymbol to #domain fpr comaptibility with Socket
Stefan Vogel <sv@exept.de>
parents:
3050
diff
changeset
|
183 |
vwDomainSymbol |
b5b13e505486
changes #domainSymbol to #domain fpr comaptibility with Socket
Stefan Vogel <sv@exept.de>
parents:
3050
diff
changeset
|
184 |
^ #afInet6 |
815 | 185 |
! ! |
186 |
||
1231 | 187 |
!IPv6SocketAddress methodsFor:'accessing'! |
188 |
||
2568 | 189 |
flowInfo |
190 |
"/ struct sockaddr_in6 { |
|
191 |
"/ 0 unsigned short int sin6_family; /* AF_INET6 */ |
|
192 |
"/ 2 __u16 sin6_port; /* Transport layer port # */ |
|
193 |
"/ 4 __u32 sin6_flowinfo; /* IPv6 flow information */ |
|
194 |
"/ 8 struct in6_addr sin6_addr; /* IPv6 address */ |
|
195 |
"/ 24 __u32 sin6_scope_id; /* scope id (new in RFC2553) */ |
|
196 |
"/ 28 }; |
|
3771 | 197 |
^ self unsignedInt32At:4+1 MSB:false. |
2568 | 198 |
! |
199 |
||
1231 | 200 |
hostAddress |
201 |
"/ struct sockaddr_in6 { |
|
2568 | 202 |
"/ 0 unsigned short int sin6_family; /* AF_INET6 */ |
203 |
"/ 2 __u16 sin6_port; /* Transport layer port # */ |
|
204 |
"/ 4 __u32 sin6_flowinfo; /* IPv6 flow information */ |
|
205 |
"/ 8 struct in6_addr sin6_addr; /* IPv6 address */ |
|
206 |
"/ 24 __u32 sin6_scope_id; /* scope id (new in RFC2553) */ |
|
207 |
"/ 28 }; |
|
1559
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
208 |
^ (ByteArray new:16) replaceFrom:1 to:16 with:self startingAt:9 |
1231 | 209 |
! |
210 |
||
211 |
hostAddress:aByteArray |
|
212 |
^ self replaceFrom:9 to:9+16-1 with:aByteArray startingAt:1 |
|
2568 | 213 |
! |
214 |
||
215 |
scopeId |
|
216 |
"/ struct sockaddr_in6 { |
|
217 |
"/ 0 unsigned short int sin6_family; /* AF_INET6 */ |
|
218 |
"/ 2 __u16 sin6_port; /* Transport layer port # */ |
|
219 |
"/ 4 __u32 sin6_flowinfo; /* IPv6 flow information */ |
|
220 |
"/ 8 struct in6_addr sin6_addr; /* IPv6 address */ |
|
221 |
"/ 24 __u32 sin6_scope_id; /* scope id (new in RFC2553) */ |
|
222 |
"/ 28 }; |
|
3771 | 223 |
^ self unsignedInt32At:24+1 MSB:false. |
1231 | 224 |
! ! |
225 |
||
3517 | 226 |
!IPv6SocketAddress methodsFor:'comparing'! |
227 |
||
3519 | 228 |
sameHostAddress:aSocketAddress |
3517 | 229 |
"answer true, if myself and aSocketAddress have the same host address |
230 |
(but possibly different ports)." |
|
231 |
||
232 |
"/ struct sockaddr_in6 { |
|
233 |
"/ 0 unsigned short int sin6_family; /* AF_INET6 */ |
|
234 |
"/ 2 __u16 sin6_port; /* Transport layer port # */ |
|
235 |
"/ 4 __u32 sin6_flowinfo; /* IPv6 flow information */ |
|
236 |
"/ 8 struct in6_addr sin6_addr; /* IPv6 address */ |
|
237 |
"/ 24 __u32 sin6_scope_id; /* scope id (new in RFC2553) */ |
|
238 |
"/ 28 }; |
|
239 |
||
240 |
^ aSocketAddress class == self class |
|
241 |
and:[self sameContentsFrom:9 to:25 as:aSocketAddress startingAt:9] |
|
242 |
! ! |
|
243 |
||
3058 | 244 |
!IPv6SocketAddress methodsFor:'converting'! |
245 |
||
246 |
asIPv4SocketAddress |
|
247 |
"convert a IPv4 addresse mapped to IPv6 into real IPv4 IPSocketAddress" |
|
248 |
||
249 |
self isMappedIPv4 ifFalse:[ |
|
250 |
ConversionError raiseErrorString:'Trying to convert a non-mappable IPv6 address'. |
|
251 |
]. |
|
252 |
||
253 |
^ IPSocketAddress hostAddress:(self copyFrom:21 to:24) port:self port. |
|
254 |
||
255 |
" |
|
256 |
(self addressString:'0:0:0:0:0:ffff::') asIPv4SocketAddress |
|
257 |
(IPSocketAddress localHost port:80) asIPv6SocketAddress asIPv4SocketAddress |
|
258 |
" |
|
259 |
! |
|
260 |
||
3511 | 261 |
asIPv4SocketAddressIfPossible |
262 |
"try to convert to an IPv4 socket address (works when a IPv6 adreess is a mapped IPv4 address). |
|
263 |
Answer myself, if the conversion is not possible." |
|
264 |
||
265 |
self isMappedIPv4 ifFalse:[ |
|
266 |
^ self. |
|
267 |
]. |
|
268 |
||
269 |
^ IPSocketAddress hostAddress:(self copyFrom:21 to:24) port:self port. |
|
270 |
||
271 |
" |
|
272 |
(self addressString:'0:0:0:0:0:ffff::') asIPv4SocketAddressIfPossible |
|
273 |
(IPSocketAddress localHost port:80) asIPv6SocketAddress asIPv4SocketAddressIfPossible |
|
274 |
" |
|
275 |
! |
|
276 |
||
3058 | 277 |
asIPv6SocketAddress |
278 |
^ self |
|
279 |
! ! |
|
280 |
||
1559
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
281 |
!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
|
282 |
|
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
283 |
printAddressOn:aStream |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
284 |
|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
|
285 |
|
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
286 |
colons := 0. |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
287 |
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
|
288 |
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
|
289 |
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
|
290 |
|word| |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
291 |
|
3754 | 292 |
word := self unsignedInt16At:i MSB:true. |
1559
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
293 |
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
|
294 |
(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
|
295 |
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
|
296 |
aStream nextPut:$: |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
297 |
] |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
298 |
] ifFalse:[ |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
299 |
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
|
300 |
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
|
301 |
aStream nextPut:$:. |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
302 |
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
|
303 |
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
|
304 |
] ifFalse:[ |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
305 |
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
|
306 |
] |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
307 |
]. |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
308 |
]. |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
309 |
]. |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
310 |
|
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
311 |
" |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
312 |
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
|
313 |
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
|
314 |
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
|
315 |
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
|
316 |
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
|
317 |
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
|
318 |
" |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
319 |
! ! |
609a0707ab22
New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents:
1366
diff
changeset
|
320 |
|
1231 | 321 |
!IPv6SocketAddress methodsFor:'private'! |
322 |
||
323 |
adrBytesStart |
|
324 |
^ 9 |
|
325 |
! |
|
326 |
||
327 |
numAdrBytes |
|
328 |
^ 16 |
|
329 |
! ! |
|
330 |
||
2568 | 331 |
!IPv6SocketAddress methodsFor:'queries'! |
332 |
||
333 |
networkAddress |
|
334 |
<resource: #obsolete> |
|
335 |
^ self shouldNotImplement |
|
336 |
! |
|
337 |
||
338 |
networkClass |
|
339 |
"IPV6 doesn't know about network classes" |
|
340 |
<resource: #obsolete> |
|
341 |
||
342 |
^ self shouldNotImplement |
|
343 |
! ! |
|
344 |
||
1366
e01d0f6c102a
New method #isLocal returning true for local addresses
Stefan Vogel <sv@exept.de>
parents:
1281
diff
changeset
|
345 |
!IPv6SocketAddress methodsFor:'testing'! |
e01d0f6c102a
New method #isLocal returning true for local addresses
Stefan Vogel <sv@exept.de>
parents:
1281
diff
changeset
|
346 |
|
3050 | 347 |
isBroadcast |
348 |
"answer true, if this is a broadcast address: |
|
349 |
all node-local nodes: ff01::1 |
|
350 |
all link-local nodes: ff02::1" |
|
351 |
||
352 |
^ (self at:9) == 16rff |
|
353 |
and:[((self at:10) bitAnd:16r03) ~~ 0 |
|
354 |
and:[self sameContentsFrom:11 to:24 as:#[0 0 0 0 0 0 0 0 0 0 0 0 0 1] startingAt:1]] |
|
355 |
||
356 |
" |
|
357 |
(self addressString:'ff01::1') isBroadcast |
|
358 |
(self addressString:'ff02::1') isBroadcast |
|
359 |
(self addressString:'ff01::55') isBroadcast |
|
360 |
" |
|
361 |
! |
|
362 |
||
363 |
isGlobalUnicast |
|
364 |
"answer true, if this address is a global unicast address |
|
365 |
in the range 2000::/3" |
|
366 |
||
367 |
^ (self at:9) between:16r20 and:16r3f |
|
368 |
! |
|
369 |
||
370 |
isIPv6SocketAddress |
|
371 |
^ true |
|
372 |
! |
|
373 |
||
2568 | 374 |
isLinkLocalUnicast |
375 |
"answer true, if this address is a link local unicast address fe80::/10" |
|
376 |
||
377 |
^ (self at:9) == 16rfe and:[((self at:10) bitAnd:16rc0) == 16r80] |
|
378 |
! |
|
379 |
||
1366
e01d0f6c102a
New method #isLocal returning true for local addresses
Stefan Vogel <sv@exept.de>
parents:
1281
diff
changeset
|
380 |
isLocal |
3984 | 381 |
"answer true, if this address addresses 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
|
382 |
|
2568 | 383 |
^ (self at:9) == 0 and:[self hostAddress = self class local] |
3050 | 384 |
|
385 |
" |
|
386 |
self localHost isLocal |
|
387 |
" |
|
2568 | 388 |
! |
389 |
||
3058 | 390 |
isMappedIPv4 |
391 |
"answer true, if this is a mapped IPv4 address" |
|
392 |
||
393 |
^ (self at:9) == 0 |
|
394 |
and:[self sameContentsFrom:9 to:20 as:#[0 0 0 0 0 0 0 0 0 0 16rff 16rff] startingAt:1] |
|
395 |
||
396 |
" |
|
397 |
(self addressString:'0:0:0:0:0:ffff::') isMappedIPv4 |
|
398 |
" |
|
399 |
! |
|
400 |
||
2568 | 401 |
isMulticast |
3050 | 402 |
"answer true, if this address is a multicast address ff::/8" |
2568 | 403 |
|
404 |
^ (self at:9) == 16rff |
|
3050 | 405 |
! |
406 |
||
407 |
isUniqueLocalUnicast |
|
408 |
"answer true, if this address is a unique local unicast (e.g. private) address |
|
409 |
in the range fc::/8 or fd::/8" |
|
410 |
||
411 |
^ (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
|
412 |
! ! |
e01d0f6c102a
New method #isLocal returning true for local addresses
Stefan Vogel <sv@exept.de>
parents:
1281
diff
changeset
|
413 |
|
815 | 414 |
!IPv6SocketAddress class methodsFor:'documentation'! |
415 |
||
416 |
version |
|
3754 | 417 |
^ '$Header$' |
2568 | 418 |
! |
419 |
||
420 |
version_CVS |
|
3754 | 421 |
^ '$Header$' |
815 | 422 |
! ! |
3045 | 423 |