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