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