IPv6SocketAddress.st
author Stefan Vogel <sv@exept.de>
Fri, 27 Feb 2015 22:09:28 +0100
changeset 3511 f23e77f37681
parent 3509 24cf2cef907c
child 3517 22ed6e899161
permissions -rw-r--r--
class: IPv6SocketAddress added: #asIPv4SocketAddressIfPossible #hasSameHostAddress:
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
    
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1366
diff changeset
    91
    |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
    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 := aString asCollectionOfSubstringsSeparatedBy:$:.
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1366
diff changeset
    94
    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
    95
        ^ 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
    96
            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
    97
    ].
3509
24cf2cef907c class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3058
diff changeset
    98
    "allow adresses formated like: '[2001:4dd0:ffa3::1]'"
24cf2cef907c class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3058
diff changeset
    99
    components first first = $[ ifTrue:[
24cf2cef907c class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3058
diff changeset
   100
        components at:1 put:(components first copyFrom:2).
24cf2cef907c class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3058
diff changeset
   101
        components last last = $] ifTrue:[
24cf2cef907c class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3058
diff changeset
   102
            components at:components size put:(components last copyButLast:1).
24cf2cef907c class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3058
diff changeset
   103
        ].
24cf2cef907c class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3058
diff changeset
   104
    ].
1559
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1366
diff changeset
   105
    (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
   106
        "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
   107
        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
   108
        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
   109
        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
   110
    ].
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1366
diff changeset
   111
    words := components 
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1366
diff changeset
   112
                collect:[:eachComponent | 
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1366
diff changeset
   113
                    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
   114
                        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
   115
                    ] ifFalse:[
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1366
diff changeset
   116
                        Integer 
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1366
diff changeset
   117
                            readFromString:eachComponent
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1366
diff changeset
   118
                            radix:16
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1366
diff changeset
   119
                            onError:[
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1366
diff changeset
   120
                                ^ 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
   121
                                    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
   122
                            ].
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1366
diff changeset
   123
                    ].
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
    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
   127
    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
   128
    i := 1.
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1366
diff changeset
   129
    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
   130
        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
   131
            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
   132
                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
   133
                bytesToGenerate := 0.
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1366
diff changeset
   134
            ].
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1366
diff changeset
   135
        ] ifFalse:[
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1366
diff changeset
   136
            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
   137
            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
   138
        ].
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1366
diff changeset
   139
        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
   140
        prevWord := eachWord.
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1366
diff changeset
   141
    ].
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1366
diff changeset
   142
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1366
diff changeset
   143
    ^ bytes.
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
    "
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1366
diff changeset
   146
        IPv6SocketAddress hostAddressFromString:'::'
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1366
diff changeset
   147
        IPv6SocketAddress hostAddressFromString:'::1'
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:':1:2'
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::2'
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: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
   151
        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
   152
        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
   153
        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
   154
        IPv6SocketAddress hostAddressFromString:'1:2:3::4'
3509
24cf2cef907c class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3058
diff changeset
   155
        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
   156
        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
   157
    "
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1366
diff changeset
   158
! !
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1366
diff changeset
   159
1162
c8ba14f81f13 Prepare new socketb implementation
Stefan Vogel <sv@exept.de>
parents: 818
diff changeset
   160
!IPv6SocketAddress class methodsFor:'queries'!
818
2f8331ad12d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 815
diff changeset
   161
3053
b5b13e505486 changes #domainSymbol to #domain fpr comaptibility with Socket
Stefan Vogel <sv@exept.de>
parents: 3050
diff changeset
   162
domain
1226
0114bd044aa9 vw compatible domainSymbols (afXXX)
Claus Gittinger <cg@exept.de>
parents: 1167
diff changeset
   163
    ^ #'AF_INET6'
0114bd044aa9 vw compatible domainSymbols (afXXX)
Claus Gittinger <cg@exept.de>
parents: 1167
diff changeset
   164
!
0114bd044aa9 vw compatible domainSymbols (afXXX)
Claus Gittinger <cg@exept.de>
parents: 1167
diff changeset
   165
3045
7663a852fa0b My own address checking
Stefan Vogel <sv@exept.de>
parents: 2568
diff changeset
   166
hostAddressLen
7663a852fa0b My own address checking
Stefan Vogel <sv@exept.de>
parents: 2568
diff changeset
   167
    "answer the number of bytes of the host address"
7663a852fa0b My own address checking
Stefan Vogel <sv@exept.de>
parents: 2568
diff changeset
   168
3050
b60ffb4b201a More address type testing
Stefan Vogel <sv@exept.de>
parents: 3045
diff changeset
   169
    ^ 16
3045
7663a852fa0b My own address checking
Stefan Vogel <sv@exept.de>
parents: 2568
diff changeset
   170
!
7663a852fa0b My own address checking
Stefan Vogel <sv@exept.de>
parents: 2568
diff changeset
   171
1226
0114bd044aa9 vw compatible domainSymbols (afXXX)
Claus Gittinger <cg@exept.de>
parents: 1167
diff changeset
   172
obsoleteDomainSymbol
1162
c8ba14f81f13 Prepare new socketb implementation
Stefan Vogel <sv@exept.de>
parents: 818
diff changeset
   173
    ^ #inet6
3053
b5b13e505486 changes #domainSymbol to #domain fpr comaptibility with Socket
Stefan Vogel <sv@exept.de>
parents: 3050
diff changeset
   174
!
b5b13e505486 changes #domainSymbol to #domain fpr comaptibility with Socket
Stefan Vogel <sv@exept.de>
parents: 3050
diff changeset
   175
b5b13e505486 changes #domainSymbol to #domain fpr comaptibility with Socket
Stefan Vogel <sv@exept.de>
parents: 3050
diff changeset
   176
vwDomainSymbol
b5b13e505486 changes #domainSymbol to #domain fpr comaptibility with Socket
Stefan Vogel <sv@exept.de>
parents: 3050
diff changeset
   177
    ^ #afInet6
815
cb36489446b2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   178
! !
cb36489446b2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   179
1231
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   180
!IPv6SocketAddress methodsFor:'accessing'!
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   181
2568
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   182
flowInfo
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   183
"/    struct sockaddr_in6 {
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   184
"/  0           unsigned short int      sin6_family;    /* AF_INET6 */
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   185
"/  2           __u16                   sin6_port;      /* Transport layer port # */
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   186
"/  4           __u32                   sin6_flowinfo;  /* IPv6 flow information */
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   187
"/  8           struct in6_addr         sin6_addr;      /* IPv6 address */
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   188
"/ 24            __u32                   sin6_scope_id;  /* scope id (new in RFC2553) */
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   189
"/ 28   };
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   190
    ^ self unsignedLongAt:5 bigEndian:false.
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   191
!
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   192
3511
f23e77f37681 class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3509
diff changeset
   193
hasSameHostAddress:aSocketAddress
f23e77f37681 class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3509
diff changeset
   194
    "answer true, if myself and aSocketAddress have the same host address
f23e77f37681 class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3509
diff changeset
   195
     (but possibly different ports)."
f23e77f37681 class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3509
diff changeset
   196
f23e77f37681 class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3509
diff changeset
   197
"/    struct sockaddr_in6 {
f23e77f37681 class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3509
diff changeset
   198
"/  0           unsigned short int      sin6_family;    /* AF_INET6 */
f23e77f37681 class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3509
diff changeset
   199
"/  2           __u16                   sin6_port;      /* Transport layer port # */
f23e77f37681 class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3509
diff changeset
   200
"/  4           __u32                   sin6_flowinfo;  /* IPv6 flow information */
f23e77f37681 class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3509
diff changeset
   201
"/  8           struct in6_addr         sin6_addr;      /* IPv6 address */
f23e77f37681 class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3509
diff changeset
   202
"/ 24            __u32                   sin6_scope_id;  /* scope id (new in RFC2553) */
f23e77f37681 class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3509
diff changeset
   203
"/ 28   };
f23e77f37681 class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3509
diff changeset
   204
f23e77f37681 class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3509
diff changeset
   205
    ^ aSocketAddress class == self class 
f23e77f37681 class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3509
diff changeset
   206
        and:[self sameContentsFrom:9 to:25 as:aSocketAddress startingAt:9]
f23e77f37681 class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3509
diff changeset
   207
!
f23e77f37681 class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3509
diff changeset
   208
1231
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   209
hostAddress
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   210
"/    struct sockaddr_in6 {
2568
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   211
"/  0           unsigned short int      sin6_family;    /* AF_INET6 */
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   212
"/  2           __u16                   sin6_port;      /* Transport layer port # */
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   213
"/  4           __u32                   sin6_flowinfo;  /* IPv6 flow information */
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   214
"/  8           struct in6_addr         sin6_addr;      /* IPv6 address */
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   215
"/ 24            __u32                   sin6_scope_id;  /* scope id (new in RFC2553) */
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   216
"/ 28   };
1559
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1366
diff changeset
   217
    ^ (ByteArray new:16) replaceFrom:1 to:16 with:self startingAt:9
1231
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   218
!
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   219
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   220
hostAddress:aByteArray
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   221
    ^ 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
   222
!
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   223
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   224
scopeId
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   225
"/    struct sockaddr_in6 {
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   226
"/  0           unsigned short int      sin6_family;    /* AF_INET6 */
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   227
"/  2           __u16                   sin6_port;      /* Transport layer port # */
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   228
"/  4           __u32                   sin6_flowinfo;  /* IPv6 flow information */
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   229
"/  8           struct in6_addr         sin6_addr;      /* IPv6 address */
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   230
"/ 24            __u32                   sin6_scope_id;  /* scope id (new in RFC2553) */
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   231
"/ 28   };
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   232
    ^ self unsignedLongAt:25 bigEndian:false.
1231
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   233
! !
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   234
3058
d7ca7f4c7d77 IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3053
diff changeset
   235
!IPv6SocketAddress methodsFor:'converting'!
d7ca7f4c7d77 IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3053
diff changeset
   236
d7ca7f4c7d77 IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3053
diff changeset
   237
asIPv4SocketAddress
d7ca7f4c7d77 IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3053
diff changeset
   238
    "convert a IPv4 addresse mapped to IPv6 into real IPv4 IPSocketAddress"
d7ca7f4c7d77 IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3053
diff changeset
   239
d7ca7f4c7d77 IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3053
diff changeset
   240
    self isMappedIPv4 ifFalse:[
d7ca7f4c7d77 IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3053
diff changeset
   241
        ConversionError raiseErrorString:'Trying to convert a non-mappable IPv6 address'.
d7ca7f4c7d77 IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3053
diff changeset
   242
    ].
d7ca7f4c7d77 IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3053
diff changeset
   243
d7ca7f4c7d77 IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3053
diff changeset
   244
    ^ IPSocketAddress hostAddress:(self copyFrom:21 to:24) port:self port.
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
    "
d7ca7f4c7d77 IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3053
diff changeset
   247
        (self addressString:'0:0:0:0:0:ffff::') asIPv4SocketAddress
d7ca7f4c7d77 IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3053
diff changeset
   248
        (IPSocketAddress localHost port:80) asIPv6SocketAddress asIPv4SocketAddress
d7ca7f4c7d77 IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3053
diff changeset
   249
    "
d7ca7f4c7d77 IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3053
diff changeset
   250
!
d7ca7f4c7d77 IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3053
diff changeset
   251
3511
f23e77f37681 class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3509
diff changeset
   252
asIPv4SocketAddressIfPossible
f23e77f37681 class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3509
diff changeset
   253
    "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
   254
     Answer myself, if the conversion is not possible."
f23e77f37681 class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3509
diff changeset
   255
f23e77f37681 class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3509
diff changeset
   256
    self isMappedIPv4 ifFalse:[
f23e77f37681 class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3509
diff changeset
   257
        ^ self.
f23e77f37681 class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3509
diff changeset
   258
    ].
f23e77f37681 class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3509
diff changeset
   259
f23e77f37681 class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3509
diff changeset
   260
    ^ IPSocketAddress hostAddress:(self copyFrom:21 to:24) port:self port.
f23e77f37681 class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3509
diff changeset
   261
f23e77f37681 class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3509
diff changeset
   262
    "
f23e77f37681 class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3509
diff changeset
   263
        (self addressString:'0:0:0:0:0:ffff::') asIPv4SocketAddressIfPossible
f23e77f37681 class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3509
diff changeset
   264
        (IPSocketAddress localHost port:80) asIPv6SocketAddress asIPv4SocketAddressIfPossible
f23e77f37681 class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3509
diff changeset
   265
    "
f23e77f37681 class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3509
diff changeset
   266
!
f23e77f37681 class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3509
diff changeset
   267
3058
d7ca7f4c7d77 IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3053
diff changeset
   268
asIPv6SocketAddress
d7ca7f4c7d77 IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3053
diff changeset
   269
    ^ self
d7ca7f4c7d77 IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3053
diff changeset
   270
! !
d7ca7f4c7d77 IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3053
diff changeset
   271
1559
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1366
diff changeset
   272
!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
   273
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1366
diff changeset
   274
printAddressOn:aStream
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1366
diff changeset
   275
    |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
   276
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1366
diff changeset
   277
    colons := 0.
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1366
diff changeset
   278
    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
   279
    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
   280
    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
   281
        |word|
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
        word := self wordAt:i MSB:true.
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1366
diff changeset
   284
        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
   285
            (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
   286
                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
   287
                aStream nextPut:$:
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1366
diff changeset
   288
            ]
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1366
diff changeset
   289
        ] ifFalse:[
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1366
diff changeset
   290
            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
   291
            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
   292
                aStream nextPut:$:.
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1366
diff changeset
   293
                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
   294
                    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
   295
                ] ifFalse:[
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1366
diff changeset
   296
                    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
   297
                ]
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1366
diff changeset
   298
            ].
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1366
diff changeset
   299
        ].
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1366
diff changeset
   300
    ].
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
       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
   304
       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
   305
       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
   306
       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
   307
       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
   308
       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
   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
1231
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   312
!IPv6SocketAddress methodsFor:'private'!
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   313
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   314
adrBytesStart
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   315
    ^ 9
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   316
!
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   317
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   318
numAdrBytes
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   319
    ^ 16
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   320
! !
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   321
2568
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   322
!IPv6SocketAddress methodsFor:'queries'!
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   323
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   324
networkAddress
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   325
    <resource: #obsolete>
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   326
    ^ self shouldNotImplement
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   327
!
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   328
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   329
networkClass
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   330
    "IPV6 doesn't know about network classes"
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   331
    <resource: #obsolete>
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
    ^ self shouldNotImplement
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   334
! !
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   335
1366
e01d0f6c102a New method #isLocal returning true for local addresses
Stefan Vogel <sv@exept.de>
parents: 1281
diff changeset
   336
!IPv6SocketAddress methodsFor:'testing'!
e01d0f6c102a New method #isLocal returning true for local addresses
Stefan Vogel <sv@exept.de>
parents: 1281
diff changeset
   337
3050
b60ffb4b201a More address type testing
Stefan Vogel <sv@exept.de>
parents: 3045
diff changeset
   338
isBroadcast
b60ffb4b201a More address type testing
Stefan Vogel <sv@exept.de>
parents: 3045
diff changeset
   339
    "answer true, if this is a broadcast address:
b60ffb4b201a More address type testing
Stefan Vogel <sv@exept.de>
parents: 3045
diff changeset
   340
        all node-local nodes: ff01::1
b60ffb4b201a More address type testing
Stefan Vogel <sv@exept.de>
parents: 3045
diff changeset
   341
        all link-local nodes: ff02::1"
b60ffb4b201a More address type testing
Stefan Vogel <sv@exept.de>
parents: 3045
diff changeset
   342
b60ffb4b201a More address type testing
Stefan Vogel <sv@exept.de>
parents: 3045
diff changeset
   343
    ^ (self at:9) == 16rff 
b60ffb4b201a More address type testing
Stefan Vogel <sv@exept.de>
parents: 3045
diff changeset
   344
        and:[((self at:10) bitAnd:16r03) ~~ 0
b60ffb4b201a More address type testing
Stefan Vogel <sv@exept.de>
parents: 3045
diff changeset
   345
        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
   346
b60ffb4b201a More address type testing
Stefan Vogel <sv@exept.de>
parents: 3045
diff changeset
   347
    "
b60ffb4b201a More address type testing
Stefan Vogel <sv@exept.de>
parents: 3045
diff changeset
   348
        (self addressString:'ff01::1') isBroadcast
b60ffb4b201a More address type testing
Stefan Vogel <sv@exept.de>
parents: 3045
diff changeset
   349
        (self addressString:'ff02::1') isBroadcast
b60ffb4b201a More address type testing
Stefan Vogel <sv@exept.de>
parents: 3045
diff changeset
   350
        (self addressString:'ff01::55') isBroadcast
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
!
b60ffb4b201a More address type testing
Stefan Vogel <sv@exept.de>
parents: 3045
diff changeset
   353
b60ffb4b201a More address type testing
Stefan Vogel <sv@exept.de>
parents: 3045
diff changeset
   354
isGlobalUnicast
b60ffb4b201a More address type testing
Stefan Vogel <sv@exept.de>
parents: 3045
diff changeset
   355
    "answer true, if this address is a global unicast address 
b60ffb4b201a More address type testing
Stefan Vogel <sv@exept.de>
parents: 3045
diff changeset
   356
     in the range 2000::/3"
b60ffb4b201a More address type testing
Stefan Vogel <sv@exept.de>
parents: 3045
diff changeset
   357
b60ffb4b201a More address type testing
Stefan Vogel <sv@exept.de>
parents: 3045
diff changeset
   358
    ^ (self at:9) between:16r20 and:16r3f
b60ffb4b201a More address type testing
Stefan Vogel <sv@exept.de>
parents: 3045
diff changeset
   359
!
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
isIPv6SocketAddress
b60ffb4b201a More address type testing
Stefan Vogel <sv@exept.de>
parents: 3045
diff changeset
   362
    ^ true
b60ffb4b201a More address type testing
Stefan Vogel <sv@exept.de>
parents: 3045
diff changeset
   363
!
b60ffb4b201a More address type testing
Stefan Vogel <sv@exept.de>
parents: 3045
diff changeset
   364
2568
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   365
isLinkLocalUnicast
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   366
    "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
   367
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   368
    ^ (self at:9) == 16rfe and:[((self at:10) bitAnd:16rc0) == 16r80]
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   369
!
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   370
1366
e01d0f6c102a New method #isLocal returning true for local addresses
Stefan Vogel <sv@exept.de>
parents: 1281
diff changeset
   371
isLocal
3050
b60ffb4b201a More address type testing
Stefan Vogel <sv@exept.de>
parents: 3045
diff changeset
   372
    "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
   373
2568
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   374
    ^ (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
   375
b60ffb4b201a More address type testing
Stefan Vogel <sv@exept.de>
parents: 3045
diff changeset
   376
    "
b60ffb4b201a More address type testing
Stefan Vogel <sv@exept.de>
parents: 3045
diff changeset
   377
        self localHost isLocal
b60ffb4b201a More address type testing
Stefan Vogel <sv@exept.de>
parents: 3045
diff changeset
   378
    "
2568
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   379
!
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   380
3058
d7ca7f4c7d77 IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3053
diff changeset
   381
isMappedIPv4
d7ca7f4c7d77 IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3053
diff changeset
   382
    "answer true, if this is a mapped IPv4 address"
d7ca7f4c7d77 IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3053
diff changeset
   383
d7ca7f4c7d77 IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3053
diff changeset
   384
    ^ (self at:9) == 0 
d7ca7f4c7d77 IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3053
diff changeset
   385
        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
   386
d7ca7f4c7d77 IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3053
diff changeset
   387
    "
d7ca7f4c7d77 IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3053
diff changeset
   388
        (self addressString:'0:0:0:0:0:ffff::') isMappedIPv4
d7ca7f4c7d77 IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3053
diff changeset
   389
    "
d7ca7f4c7d77 IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3053
diff changeset
   390
!
d7ca7f4c7d77 IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3053
diff changeset
   391
2568
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   392
isMulticast
3050
b60ffb4b201a More address type testing
Stefan Vogel <sv@exept.de>
parents: 3045
diff changeset
   393
    "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
   394
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   395
    ^ (self at:9) == 16rff 
3050
b60ffb4b201a More address type testing
Stefan Vogel <sv@exept.de>
parents: 3045
diff changeset
   396
!
b60ffb4b201a More address type testing
Stefan Vogel <sv@exept.de>
parents: 3045
diff changeset
   397
b60ffb4b201a More address type testing
Stefan Vogel <sv@exept.de>
parents: 3045
diff changeset
   398
isUniqueLocalUnicast
b60ffb4b201a More address type testing
Stefan Vogel <sv@exept.de>
parents: 3045
diff changeset
   399
    "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
   400
     in the range fc::/8 or fd::/8"
b60ffb4b201a More address type testing
Stefan Vogel <sv@exept.de>
parents: 3045
diff changeset
   401
b60ffb4b201a More address type testing
Stefan Vogel <sv@exept.de>
parents: 3045
diff changeset
   402
    ^ (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
   403
! !
e01d0f6c102a New method #isLocal returning true for local addresses
Stefan Vogel <sv@exept.de>
parents: 1281
diff changeset
   404
815
cb36489446b2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   405
!IPv6SocketAddress class methodsFor:'documentation'!
cb36489446b2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   406
cb36489446b2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   407
version
3511
f23e77f37681 class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3509
diff changeset
   408
    ^ '$Header: /cvs/stx/stx/libbasic2/IPv6SocketAddress.st,v 1.20 2015-02-27 21:09:28 stefan Exp $'
2568
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   409
!
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   410
4b0180395472 added:7 methods
Stefan Vogel <sv@exept.de>
parents: 1559
diff changeset
   411
version_CVS
3511
f23e77f37681 class: IPv6SocketAddress
Stefan Vogel <sv@exept.de>
parents: 3509
diff changeset
   412
    ^ '$Header: /cvs/stx/stx/libbasic2/IPv6SocketAddress.st,v 1.20 2015-02-27 21:09:28 stefan Exp $'
815
cb36489446b2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   413
! !
3045
7663a852fa0b My own address checking
Stefan Vogel <sv@exept.de>
parents: 2568
diff changeset
   414