IPv6SocketAddress.st
author Claus Gittinger <cg@exept.de>
Sat, 02 May 2020 21:40:13 +0200
changeset 5476 7355a4b11cb6
parent 4954 6a0f3ce56e46
permissions -rw-r--r--
#FEATURE by cg class: Socket class added: #newTCPclientToHost:port:domain:domainOrder:withTimeout: changed: #newTCPclientToHost:port:domain:withTimeout:
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
815
cb36489446b2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     1
"
cb36489446b2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     2
 COPYRIGHT (c) 1999 by eXept Software AG
cb36489446b2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     3
              All Rights Reserved
cb36489446b2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
cb36489446b2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     5
 This software is furnished under a license and may be used
cb36489446b2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
cb36489446b2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
cb36489446b2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
cb36489446b2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
cb36489446b2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
 hereby transferred.
cb36489446b2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    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
24cf2cef907c class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3058
diff changeset
    14
"{ NameSpace: Smalltalk }"
24cf2cef907c class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3058
diff changeset
    15
818
2f8331ad12d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 815
diff changeset
    16
IPSocketAddress variableByteSubclass:#IPv6SocketAddress
815
cb36489446b2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    17
	instanceVariableNames:''
cb36489446b2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
	classVariableNames:''
cb36489446b2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
	poolDictionaries:''
1167
56c172bc5cfe Category change
Stefan Vogel <sv@exept.de>
parents: 1165
diff changeset
    20
	category:'OS-Sockets'
815
cb36489446b2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
!
cb36489446b2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
cb36489446b2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
!IPv6SocketAddress class methodsFor:'documentation'!
cb36489446b2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
cb36489446b2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
copyright
cb36489446b2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
"
cb36489446b2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    27
 COPYRIGHT (c) 1999 by eXept Software AG
cb36489446b2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    28
              All Rights Reserved
cb36489446b2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    29
cb36489446b2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
 This software is furnished under a license and may be used
cb36489446b2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
 only in accordance with the terms of that license and with the
cb36489446b2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
 inclusion of the above copyright notice.   This software may not
cb36489446b2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
 be provided or otherwise made available to, or used by, any
cb36489446b2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
 other person.  No title to or ownership of the software is
cb36489446b2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
 hereby transferred.
cb36489446b2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
"
cb36489446b2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
cb36489446b2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    38
cb36489446b2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
!
cb36489446b2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
cb36489446b2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
documentation
cb36489446b2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
"
cb36489446b2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    43
    Instances of IPv6SocketAddress represent v6 IP socket addresses.
cb36489446b2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    44
    These consist of a 16byte hostId and a port number.
cb36489446b2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    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
cb36489446b2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    52
cb36489446b2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    53
    [author:]
cb36489446b2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    54
        Claus Gittinger (cg@exept)
cb36489446b2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    55
cb36489446b2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    56
    [see also:]
cb36489446b2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    57
cb36489446b2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    58
    [instance variables:]
cb36489446b2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    59
cb36489446b2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    60
    [class variables:]
cb36489446b2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    61
"
cb36489446b2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    62
! !
cb36489446b2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    63
1281
6df4f8f211e3 fixed anyHost
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
    64
!IPv6SocketAddress class methodsFor:'addressing'!
6df4f8f211e3 fixed anyHost
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
    65
6df4f8f211e3 fixed anyHost
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
    66
anyAddress
6df4f8f211e3 fixed anyHost
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
    67
    "return the anonymous addresses bytes"
6df4f8f211e3 fixed anyHost
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
    68
6df4f8f211e3 fixed anyHost
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
    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
7663a852fa0b My own address checking
Stefan Vogel <sv@exept.de>
parents: 2568
diff changeset
    72
broadcastAddress
7663a852fa0b My own address checking
Stefan Vogel <sv@exept.de>
parents: 2568
diff changeset
    73
    "return the addresses bytes of a broadcast address
3050
b60ffb4b201a More address type testing
Stefan Vogel <sv@exept.de>
parents: 3045
diff changeset
    74
     (this is the all-nodes link-local address ff02::1.
3045
7663a852fa0b My own address checking
Stefan Vogel <sv@exept.de>
parents: 2568
diff changeset
    75
     Broadcast is not normally used in IPv6"
7663a852fa0b My own address checking
Stefan Vogel <sv@exept.de>
parents: 2568
diff changeset
    76
3050
b60ffb4b201a More address type testing
Stefan Vogel <sv@exept.de>
parents: 3045
diff changeset
    77
    ^ #[16rff 16r02 0 0  0 0 0 0  0 0 0 0  0 0 0 16r01]
3045
7663a852fa0b My own address checking
Stefan Vogel <sv@exept.de>
parents: 2568
diff changeset
    78
!
7663a852fa0b My own address checking
Stefan Vogel <sv@exept.de>
parents: 2568
diff changeset
    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
6df4f8f211e3 fixed anyHost
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
    84
! !
6df4f8f211e3 fixed anyHost
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
    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
6a0f3ce56e46 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4284
diff changeset
    91
    |components firstComponent lastComponent
6a0f3ce56e46 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4284
diff changeset
    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
6a0f3ce56e46 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4284
diff changeset
    99
    (firstComponent := components first) notEmpty ifTrue:[
6a0f3ce56e46 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4284
diff changeset
   100
        "allow addresses formated like: '[2001:4dd0:ffa3::1]'"
6a0f3ce56e46 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4284
diff changeset
   101
        firstComponent first = $[ ifTrue:[
6a0f3ce56e46 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4284
diff changeset
   102
            components at:1 put:(firstComponent copyFrom:2).
6a0f3ce56e46 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4284
diff changeset
   103
            (lastComponent := components last) notEmpty ifTrue:[  
6a0f3ce56e46 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4284
diff changeset
   104
                lastComponent last = $] ifTrue:[
6a0f3ce56e46 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4284
diff changeset
   105
                    components at:components size put:(lastComponent copyButLast:1).
6a0f3ce56e46 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4284
diff changeset
   106
                ].
6a0f3ce56e46 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4284
diff changeset
   107
            ].
3509
24cf2cef907c class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3058
diff changeset
   108
        ].
24cf2cef907c class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3058
diff changeset
   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
ef2b270d5acd #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   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
24cf2cef907c class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3058
diff changeset
   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
6a0f3ce56e46 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4284
diff changeset
   163
6a0f3ce56e46 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4284
diff changeset
   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
2f8331ad12d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 815
diff changeset
   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
7663a852fa0b My own address checking
Stefan Vogel <sv@exept.de>
parents: 2568
diff changeset
   173
hostAddressLen
7663a852fa0b My own address checking
Stefan Vogel <sv@exept.de>
parents: 2568
diff changeset
   174
    "answer the number of bytes of the host address"
7663a852fa0b My own address checking
Stefan Vogel <sv@exept.de>
parents: 2568
diff changeset
   175
3050
b60ffb4b201a More address type testing
Stefan Vogel <sv@exept.de>
parents: 3045
diff changeset
   176
    ^ 16
3045
7663a852fa0b My own address checking
Stefan Vogel <sv@exept.de>
parents: 2568
diff changeset
   177
!
7663a852fa0b My own address checking
Stefan Vogel <sv@exept.de>
parents: 2568
diff changeset
   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
cb36489446b2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   185
! !
cb36489446b2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   186
1231
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   187
!IPv6SocketAddress methodsFor:'accessing'!
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   188
2568
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   189
flowInfo
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   190
"/    struct sockaddr_in6 {
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   191
"/  0           unsigned short int      sin6_family;    /* AF_INET6 */
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   192
"/  2           __u16                   sin6_port;      /* Transport layer port # */
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   193
"/  4           __u32                   sin6_flowinfo;  /* IPv6 flow information */
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   194
"/  8           struct in6_addr         sin6_addr;      /* IPv6 address */
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   195
"/ 24            __u32                   sin6_scope_id;  /* scope id (new in RFC2553) */
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   196
"/ 28   };
3771
bb14e511c3d1 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3754
diff changeset
   197
    ^ self unsignedInt32At:4+1 MSB:false.
2568
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   198
!
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   199
1231
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   200
hostAddress
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   201
"/    struct sockaddr_in6 {
2568
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   202
"/  0           unsigned short int      sin6_family;    /* AF_INET6 */
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   203
"/  2           __u16                   sin6_port;      /* Transport layer port # */
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   204
"/  4           __u32                   sin6_flowinfo;  /* IPv6 flow information */
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   205
"/  8           struct in6_addr         sin6_addr;      /* IPv6 address */
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   206
"/ 24            __u32                   sin6_scope_id;  /* scope id (new in RFC2553) */
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   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
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   209
!
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   210
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   211
hostAddress:aByteArray
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   212
    ^ self replaceFrom:9 to:9+16-1 with:aByteArray startingAt:1
2568
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   213
!
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   214
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   215
scopeId
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   216
"/    struct sockaddr_in6 {
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   217
"/  0           unsigned short int      sin6_family;    /* AF_INET6 */
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   218
"/  2           __u16                   sin6_port;      /* Transport layer port # */
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   219
"/  4           __u32                   sin6_flowinfo;  /* IPv6 flow information */
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   220
"/  8           struct in6_addr         sin6_addr;      /* IPv6 address */
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   221
"/ 24            __u32                   sin6_scope_id;  /* scope id (new in RFC2553) */
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   222
"/ 28   };
3771
bb14e511c3d1 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3754
diff changeset
   223
    ^ self unsignedInt32At:24+1 MSB:false.
1231
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   224
! !
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   225
3517
22ed6e899161 class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3511
diff changeset
   226
!IPv6SocketAddress methodsFor:'comparing'!
22ed6e899161 class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3511
diff changeset
   227
3519
4572c6de2712 class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3517
diff changeset
   228
sameHostAddress:aSocketAddress
3517
22ed6e899161 class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3511
diff changeset
   229
    "answer true, if myself and aSocketAddress have the same host address
22ed6e899161 class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3511
diff changeset
   230
     (but possibly different ports)."
22ed6e899161 class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3511
diff changeset
   231
22ed6e899161 class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3511
diff changeset
   232
"/    struct sockaddr_in6 {
22ed6e899161 class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3511
diff changeset
   233
"/  0           unsigned short int      sin6_family;    /* AF_INET6 */
22ed6e899161 class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3511
diff changeset
   234
"/  2           __u16                   sin6_port;      /* Transport layer port # */
22ed6e899161 class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3511
diff changeset
   235
"/  4           __u32                   sin6_flowinfo;  /* IPv6 flow information */
22ed6e899161 class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3511
diff changeset
   236
"/  8           struct in6_addr         sin6_addr;      /* IPv6 address */
22ed6e899161 class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3511
diff changeset
   237
"/ 24            __u32                   sin6_scope_id;  /* scope id (new in RFC2553) */
22ed6e899161 class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3511
diff changeset
   238
"/ 28   };
22ed6e899161 class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3511
diff changeset
   239
22ed6e899161 class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3511
diff changeset
   240
    ^ aSocketAddress class == self class 
22ed6e899161 class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3511
diff changeset
   241
        and:[self sameContentsFrom:9 to:25 as:aSocketAddress startingAt:9]
22ed6e899161 class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3511
diff changeset
   242
! !
22ed6e899161 class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3511
diff changeset
   243
3058
d7ca7f4c7d77 IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3053
diff changeset
   244
!IPv6SocketAddress methodsFor:'converting'!
d7ca7f4c7d77 IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3053
diff changeset
   245
d7ca7f4c7d77 IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3053
diff changeset
   246
asIPv4SocketAddress
d7ca7f4c7d77 IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3053
diff changeset
   247
    "convert a IPv4 addresse mapped to IPv6 into real IPv4 IPSocketAddress"
d7ca7f4c7d77 IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3053
diff changeset
   248
d7ca7f4c7d77 IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3053
diff changeset
   249
    self isMappedIPv4 ifFalse:[
d7ca7f4c7d77 IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3053
diff changeset
   250
        ConversionError raiseErrorString:'Trying to convert a non-mappable IPv6 address'.
d7ca7f4c7d77 IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3053
diff changeset
   251
    ].
d7ca7f4c7d77 IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3053
diff changeset
   252
d7ca7f4c7d77 IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3053
diff changeset
   253
    ^ IPSocketAddress hostAddress:(self copyFrom:21 to:24) port:self port.
d7ca7f4c7d77 IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3053
diff changeset
   254
d7ca7f4c7d77 IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3053
diff changeset
   255
    "
d7ca7f4c7d77 IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3053
diff changeset
   256
        (self addressString:'0:0:0:0:0:ffff::') asIPv4SocketAddress
d7ca7f4c7d77 IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3053
diff changeset
   257
        (IPSocketAddress localHost port:80) asIPv6SocketAddress asIPv4SocketAddress
d7ca7f4c7d77 IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3053
diff changeset
   258
    "
d7ca7f4c7d77 IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3053
diff changeset
   259
!
d7ca7f4c7d77 IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3053
diff changeset
   260
3511
f23e77f37681 class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3509
diff changeset
   261
asIPv4SocketAddressIfPossible
f23e77f37681 class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3509
diff changeset
   262
    "try to convert to an IPv4 socket address (works when a IPv6 adreess is a mapped IPv4 address). 
f23e77f37681 class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3509
diff changeset
   263
     Answer myself, if the conversion is not possible."
f23e77f37681 class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3509
diff changeset
   264
f23e77f37681 class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3509
diff changeset
   265
    self isMappedIPv4 ifFalse:[
f23e77f37681 class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3509
diff changeset
   266
        ^ self.
f23e77f37681 class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3509
diff changeset
   267
    ].
f23e77f37681 class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3509
diff changeset
   268
f23e77f37681 class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3509
diff changeset
   269
    ^ IPSocketAddress hostAddress:(self copyFrom:21 to:24) port:self port.
f23e77f37681 class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3509
diff changeset
   270
f23e77f37681 class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3509
diff changeset
   271
    "
f23e77f37681 class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3509
diff changeset
   272
        (self addressString:'0:0:0:0:0:ffff::') asIPv4SocketAddressIfPossible
f23e77f37681 class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3509
diff changeset
   273
        (IPSocketAddress localHost port:80) asIPv6SocketAddress asIPv4SocketAddressIfPossible
f23e77f37681 class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3509
diff changeset
   274
    "
f23e77f37681 class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3509
diff changeset
   275
!
f23e77f37681 class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3509
diff changeset
   276
3058
d7ca7f4c7d77 IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3053
diff changeset
   277
asIPv6SocketAddress
d7ca7f4c7d77 IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3053
diff changeset
   278
    ^ self
d7ca7f4c7d77 IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3053
diff changeset
   279
! !
d7ca7f4c7d77 IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3053
diff changeset
   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
94f21d3b2586 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3519
diff changeset
   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
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   321
!IPv6SocketAddress methodsFor:'private'!
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   322
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   323
adrBytesStart
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   324
    ^ 9
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   325
!
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   326
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   327
numAdrBytes
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   328
    ^ 16
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   329
! !
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   330
2568
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   331
!IPv6SocketAddress methodsFor:'queries'!
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   332
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   333
networkAddress
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   334
    <resource: #obsolete>
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   335
    ^ self shouldNotImplement
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   336
!
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   337
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   338
networkClass
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   339
    "IPV6 doesn't know about network classes"
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   340
    <resource: #obsolete>
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   341
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   342
    ^ self shouldNotImplement
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   343
! !
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   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
b60ffb4b201a More address type testing
Stefan Vogel <sv@exept.de>
parents: 3045
diff changeset
   347
isBroadcast
b60ffb4b201a More address type testing
Stefan Vogel <sv@exept.de>
parents: 3045
diff changeset
   348
    "answer true, if this is a broadcast address:
b60ffb4b201a More address type testing
Stefan Vogel <sv@exept.de>
parents: 3045
diff changeset
   349
        all node-local nodes: ff01::1
b60ffb4b201a More address type testing
Stefan Vogel <sv@exept.de>
parents: 3045
diff changeset
   350
        all link-local nodes: ff02::1"
b60ffb4b201a More address type testing
Stefan Vogel <sv@exept.de>
parents: 3045
diff changeset
   351
b60ffb4b201a More address type testing
Stefan Vogel <sv@exept.de>
parents: 3045
diff changeset
   352
    ^ (self at:9) == 16rff 
b60ffb4b201a More address type testing
Stefan Vogel <sv@exept.de>
parents: 3045
diff changeset
   353
        and:[((self at:10) bitAnd:16r03) ~~ 0
b60ffb4b201a More address type testing
Stefan Vogel <sv@exept.de>
parents: 3045
diff changeset
   354
        and:[self sameContentsFrom:11 to:24 as:#[0 0 0 0 0 0 0 0 0 0 0 0 0 1] startingAt:1]]
b60ffb4b201a More address type testing
Stefan Vogel <sv@exept.de>
parents: 3045
diff changeset
   355
b60ffb4b201a More address type testing
Stefan Vogel <sv@exept.de>
parents: 3045
diff changeset
   356
    "
b60ffb4b201a More address type testing
Stefan Vogel <sv@exept.de>
parents: 3045
diff changeset
   357
        (self addressString:'ff01::1') isBroadcast
b60ffb4b201a More address type testing
Stefan Vogel <sv@exept.de>
parents: 3045
diff changeset
   358
        (self addressString:'ff02::1') isBroadcast
b60ffb4b201a More address type testing
Stefan Vogel <sv@exept.de>
parents: 3045
diff changeset
   359
        (self addressString:'ff01::55') isBroadcast
b60ffb4b201a More address type testing
Stefan Vogel <sv@exept.de>
parents: 3045
diff changeset
   360
    "
b60ffb4b201a More address type testing
Stefan Vogel <sv@exept.de>
parents: 3045
diff changeset
   361
!
b60ffb4b201a More address type testing
Stefan Vogel <sv@exept.de>
parents: 3045
diff changeset
   362
b60ffb4b201a More address type testing
Stefan Vogel <sv@exept.de>
parents: 3045
diff changeset
   363
isGlobalUnicast
b60ffb4b201a More address type testing
Stefan Vogel <sv@exept.de>
parents: 3045
diff changeset
   364
    "answer true, if this address is a global unicast address 
b60ffb4b201a More address type testing
Stefan Vogel <sv@exept.de>
parents: 3045
diff changeset
   365
     in the range 2000::/3"
b60ffb4b201a More address type testing
Stefan Vogel <sv@exept.de>
parents: 3045
diff changeset
   366
b60ffb4b201a More address type testing
Stefan Vogel <sv@exept.de>
parents: 3045
diff changeset
   367
    ^ (self at:9) between:16r20 and:16r3f
b60ffb4b201a More address type testing
Stefan Vogel <sv@exept.de>
parents: 3045
diff changeset
   368
!
b60ffb4b201a More address type testing
Stefan Vogel <sv@exept.de>
parents: 3045
diff changeset
   369
b60ffb4b201a More address type testing
Stefan Vogel <sv@exept.de>
parents: 3045
diff changeset
   370
isIPv6SocketAddress
b60ffb4b201a More address type testing
Stefan Vogel <sv@exept.de>
parents: 3045
diff changeset
   371
    ^ true
b60ffb4b201a More address type testing
Stefan Vogel <sv@exept.de>
parents: 3045
diff changeset
   372
!
b60ffb4b201a More address type testing
Stefan Vogel <sv@exept.de>
parents: 3045
diff changeset
   373
2568
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   374
isLinkLocalUnicast
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   375
    "answer true, if this address is a link local unicast address fe80::/10"
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   376
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   377
    ^ (self at:9) == 16rfe and:[((self at:10) bitAnd:16rc0) == 16r80]
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   378
!
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   379
1366
e01d0f6c102a New method #isLocal returning true for local addresses
Stefan Vogel <sv@exept.de>
parents: 1281
diff changeset
   380
isLocal
3984
4816610d2f76 #OTHER by mawalch
mawalch
parents: 3771
diff changeset
   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
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   383
    ^ (self at:9) == 0 and:[self hostAddress = self class local]
3050
b60ffb4b201a More address type testing
Stefan Vogel <sv@exept.de>
parents: 3045
diff changeset
   384
b60ffb4b201a More address type testing
Stefan Vogel <sv@exept.de>
parents: 3045
diff changeset
   385
    "
b60ffb4b201a More address type testing
Stefan Vogel <sv@exept.de>
parents: 3045
diff changeset
   386
        self localHost isLocal
b60ffb4b201a More address type testing
Stefan Vogel <sv@exept.de>
parents: 3045
diff changeset
   387
    "
2568
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   388
!
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   389
3058
d7ca7f4c7d77 IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3053
diff changeset
   390
isMappedIPv4
d7ca7f4c7d77 IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3053
diff changeset
   391
    "answer true, if this is a mapped IPv4 address"
d7ca7f4c7d77 IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3053
diff changeset
   392
d7ca7f4c7d77 IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3053
diff changeset
   393
    ^ (self at:9) == 0 
d7ca7f4c7d77 IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3053
diff changeset
   394
        and:[self sameContentsFrom:9 to:20 as:#[0 0 0 0 0 0 0 0 0 0 16rff 16rff] startingAt:1]
d7ca7f4c7d77 IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3053
diff changeset
   395
d7ca7f4c7d77 IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3053
diff changeset
   396
    "
d7ca7f4c7d77 IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3053
diff changeset
   397
        (self addressString:'0:0:0:0:0:ffff::') isMappedIPv4
d7ca7f4c7d77 IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3053
diff changeset
   398
    "
d7ca7f4c7d77 IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3053
diff changeset
   399
!
d7ca7f4c7d77 IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3053
diff changeset
   400
2568
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   401
isMulticast
3050
b60ffb4b201a More address type testing
Stefan Vogel <sv@exept.de>
parents: 3045
diff changeset
   402
    "answer true, if this address is a multicast address ff::/8"
2568
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   403
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   404
    ^ (self at:9) == 16rff 
3050
b60ffb4b201a More address type testing
Stefan Vogel <sv@exept.de>
parents: 3045
diff changeset
   405
!
b60ffb4b201a More address type testing
Stefan Vogel <sv@exept.de>
parents: 3045
diff changeset
   406
b60ffb4b201a More address type testing
Stefan Vogel <sv@exept.de>
parents: 3045
diff changeset
   407
isUniqueLocalUnicast
b60ffb4b201a More address type testing
Stefan Vogel <sv@exept.de>
parents: 3045
diff changeset
   408
    "answer true, if this address is a unique local unicast (e.g. private) address 
b60ffb4b201a More address type testing
Stefan Vogel <sv@exept.de>
parents: 3045
diff changeset
   409
     in the range fc::/8 or fd::/8"
b60ffb4b201a More address type testing
Stefan Vogel <sv@exept.de>
parents: 3045
diff changeset
   410
b60ffb4b201a More address type testing
Stefan Vogel <sv@exept.de>
parents: 3045
diff changeset
   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
cb36489446b2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   414
!IPv6SocketAddress class methodsFor:'documentation'!
cb36489446b2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   415
cb36489446b2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   416
version
3754
94f21d3b2586 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3519
diff changeset
   417
    ^ '$Header$'
2568
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   418
!
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   419
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   420
version_CVS
3754
94f21d3b2586 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3519
diff changeset
   421
    ^ '$Header$'
815
cb36489446b2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   422
! !
3045
7663a852fa0b My own address checking
Stefan Vogel <sv@exept.de>
parents: 2568
diff changeset
   423