IPSocketAddress.st
author Stefan Vogel <sv@exept.de>
Tue, 28 Jun 2005 15:10:49 +0200
changeset 1559 609a0707ab22
parent 1452 4456e3f3ddb4
child 1585 32eba58e5498
permissions -rw-r--r--
New: #addressString: to create an instance from a numeric string representation like '1.2.3.4' or '::1'.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
100
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     1
"
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     2
 COPYRIGHT (c) 1995 by Claus Gittinger
1164
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
     3
	      All Rights Reserved
100
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     5
 This software is furnished under a license and may be used
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
 hereby transferred.
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
"
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    12
1023
12bc2a0f60b5 + bytesToName:
Claus Gittinger <cg@exept.de>
parents: 818
diff changeset
    13
"{ Package: 'stx:libbasic2' }"
12bc2a0f60b5 + bytesToName:
Claus Gittinger <cg@exept.de>
parents: 818
diff changeset
    14
818
2f8331ad12d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
    15
SocketAddress variableByteSubclass:#IPSocketAddress
1164
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
    16
	instanceVariableNames:''
1273
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
    17
	classVariableNames:''
488
b0c17a5ff8ea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 113
diff changeset
    18
	poolDictionaries:''
816
489e7876ab3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 799
diff changeset
    19
	category:'OS-Sockets'
100
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
!
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
1273
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
    22
IPSocketAddress class instanceVariableNames:'addrCache nameCache'
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
    23
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
    24
"
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
    25
 No other class instance variables are inherited by this class.
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
    26
"
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
    27
!
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
    28
100
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    29
!IPSocketAddress class methodsFor:'documentation'!
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
copyright
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
"
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
 COPYRIGHT (c) 1995 by Claus Gittinger
1164
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
    34
	      All Rights Reserved
100
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
 This software is furnished under a license and may be used
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
 only in accordance with the terms of that license and with the
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    38
 inclusion of the above copyright notice.   This software may not
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
 be provided or otherwise made available to, or used by, any
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
 other person.  No title to or ownership of the software is
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
 hereby transferred.
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
"
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    43
!
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    44
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    45
documentation
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    46
"
111
92392ae9a0f0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 100
diff changeset
    47
    Instances of IPSocketAddress represent tcp/ip-domain socket addresses.
92392ae9a0f0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 100
diff changeset
    48
    These consist of an ip address (4 bytes) and a port number.
92392ae9a0f0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 100
diff changeset
    49
100
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    50
    ST-80 compatibility class.
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    51
    This may be required when existing code has to be ported to ST/X;
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    52
    however, it may not be complete and more protocol may be added in the future.
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    53
    The code here was created when public domain code (Manchester) had to
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    54
    be ported to ST/X and missing classes/methods were encountered, and code added
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    55
    by reasoning 'what the original class could probably do there'.
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    56
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    57
    This is an additional goody class; therefore:
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    58
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    59
    THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTOR ``AS IS'' AND
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    60
    ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    61
    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    62
    ARE DISCLAIMED.  IN NO EVENT SHALL THE CONTRIBUTOR BE LIABLE
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    63
    FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    64
    DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    65
    OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    66
    HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    67
    LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    68
    OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    69
    SUCH DAMAGE.
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    70
"
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    71
! !
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    72
1233
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    73
!IPSocketAddress class methodsFor:'instance creation'!
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    74
1559
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1452
diff changeset
    75
addressString:aString
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1452
diff changeset
    76
    "convert an address given in a dot notation like 123.456.78.9"
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1452
diff changeset
    77
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1452
diff changeset
    78
    ^ self hostAddress:(self hostAddressFromString:aString).
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1452
diff changeset
    79
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1452
diff changeset
    80
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1452
diff changeset
    81
    "
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1452
diff changeset
    82
        IPSocketAddress addressString:'1.2.3.4'
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1452
diff changeset
    83
    "
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1452
diff changeset
    84
!
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1452
diff changeset
    85
1233
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    86
hostName:name serviceName:portNrOrName type:socketTypeSymbol
1262
d3daddd36a99 no longer callBack into sockets getHostName/getAddress code.
Claus Gittinger <cg@exept.de>
parents: 1261
diff changeset
    87
    "get a new instance given a hostname, port or service and type.
d3daddd36a99 no longer callBack into sockets getHostName/getAddress code.
Claus Gittinger <cg@exept.de>
parents: 1261
diff changeset
    88
     Redefined to cache the result of the name-lookup."
1233
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    89
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    90
    |addrBytes sa|
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    91
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    92
    portNrOrName isString ifTrue:[
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    93
        ^ super hostName:name serviceName:portNrOrName type:socketTypeSymbol
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    94
    ].
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    95
1273
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
    96
    addrBytes := self addressCacheAt:name.
1233
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    97
    addrBytes notNil ifTrue:[
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    98
        sa := self hostAddress:addrBytes.
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    99
        portNrOrName notNil ifTrue:[
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   100
            sa port:portNrOrName.
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   101
        ].
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   102
    ] ifFalse:[
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   103
        sa := super hostName:name serviceName:portNrOrName type:socketTypeSymbol.
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   104
1273
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
   105
        self addressCacheAt:name put:(sa hostAddress).
1233
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   106
    ].
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   107
    ^ sa
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   108
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   109
    "
1333
d9ebcc42524c printing refactored
penk
parents: 1281
diff changeset
   110
     SocketAddress hostName:'localhost' serviceName:10 type:#stream  
1233
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   111
     IPSocketAddress hostName:'localhost' serviceName:'echo' type:#datagram 
1333
d9ebcc42524c printing refactored
penk
parents: 1281
diff changeset
   112
     IPSocketAddress hostName:'localhost' serviceName:'echo' type:nil       
d9ebcc42524c printing refactored
penk
parents: 1281
diff changeset
   113
     IPSocketAddress hostName:'localhost'        
1559
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1452
diff changeset
   114
     IPv6SocketAddress hostName:'localhost'        
1233
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   115
    "
1559
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1452
diff changeset
   116
!
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1452
diff changeset
   117
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1452
diff changeset
   118
localHost
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1452
diff changeset
   119
    "get a new instance representing the local-host address"
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1452
diff changeset
   120
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1452
diff changeset
   121
    ^ self hostAddress:(self local) port:self anyPort
1233
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   122
! !
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   123
1164
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   124
!IPSocketAddress class methodsFor:'addressing'!
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   125
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   126
anyAddress
1281
6df4f8f211e3 fixed anyHost
Claus Gittinger <cg@exept.de>
parents: 1273
diff changeset
   127
    "return the anonymous addresses bytes"
1164
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   128
1281
6df4f8f211e3 fixed anyHost
Claus Gittinger <cg@exept.de>
parents: 1273
diff changeset
   129
    ^ #[0 0 0 0]
1164
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   130
!
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   131
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   132
anyPort
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   133
    "return the anon port number"
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   134
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   135
    ^ 0
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   136
!
100
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   137
1281
6df4f8f211e3 fixed anyHost
Claus Gittinger <cg@exept.de>
parents: 1273
diff changeset
   138
broadcastAddress
6df4f8f211e3 fixed anyHost
Claus Gittinger <cg@exept.de>
parents: 1273
diff changeset
   139
    "return the broadcast address"
6df4f8f211e3 fixed anyHost
Claus Gittinger <cg@exept.de>
parents: 1273
diff changeset
   140
6df4f8f211e3 fixed anyHost
Claus Gittinger <cg@exept.de>
parents: 1273
diff changeset
   141
    ^ #[255 255 255 255]
6df4f8f211e3 fixed anyHost
Claus Gittinger <cg@exept.de>
parents: 1273
diff changeset
   142
!
6df4f8f211e3 fixed anyHost
Claus Gittinger <cg@exept.de>
parents: 1273
diff changeset
   143
1164
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   144
firstUnreservedPort
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   145
    "return the first unreserved port number"
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   146
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   147
    ^ 1024
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   148
!
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   149
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   150
local
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   151
    "return IN_ADDR_ANY, the address matching any local address"
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   152
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   153
    ^ #[127 0 0 1]
100
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   154
!
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   155
1164
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   156
maxPort
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   157
    "return the maximum port number"
100
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   158
1164
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   159
    ^ 16rffff
816
489e7876ab3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 799
diff changeset
   160
!
489e7876ab3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 799
diff changeset
   161
1164
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   162
thisHost
1226
0114bd044aa9 vw compatible domainSymbols (afXXX)
Claus Gittinger <cg@exept.de>
parents: 1164
diff changeset
   163
    "return the bytes of IN_ADDR_ANY, the address matching any local address"
1164
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   164
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   165
    ^ #[0 0 0 0]
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   166
! !
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   167
1273
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
   168
!IPSocketAddress class methodsFor:'caching'!
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
   169
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
   170
addressCacheAt:aHostName
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
   171
    addrCache notNil ifTrue:[
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
   172
        ^ addrCache at:aHostName ifAbsent:nil.
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
   173
    ].
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
   174
    ^ nil
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
   175
!
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
   176
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
   177
addressCacheAt:aName put:aHostAddress
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
   178
    (addrCache isNil or:[addrCache size > 30]) ifTrue:[
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
   179
        addrCache := Dictionary new.
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
   180
    ].
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
   181
    
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
   182
    addrCache at:aName put:aHostAddress.
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
   183
!
1261
ce4c9f258766 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1259
diff changeset
   184
ce4c9f258766 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1259
diff changeset
   185
flushAddressCache
1273
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
   186
    addrCache := nil
1261
ce4c9f258766 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1259
diff changeset
   187
ce4c9f258766 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1259
diff changeset
   188
    "
ce4c9f258766 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1259
diff changeset
   189
     self flushAddressCache
ce4c9f258766 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1259
diff changeset
   190
    "
1273
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
   191
!
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
   192
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
   193
flushNameCache
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
   194
    nameCache := Dictionary new.
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
   195
!
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
   196
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
   197
nameCacheAt:aHostAddress
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
   198
    nameCache notNil ifTrue:[
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
   199
        ^ nameCache at:aHostAddress ifAbsent:nil.
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
   200
    ].
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
   201
    ^ nil
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
   202
!
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
   203
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
   204
nameCacheAt:aHostAddress put:aName
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
   205
    (nameCache isNil or:[nameCache size > 30]) ifTrue:[
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
   206
        nameCache := Dictionary new.
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
   207
    ].
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
   208
    
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
   209
    nameCache at:aHostAddress put:aName.
1261
ce4c9f258766 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1259
diff changeset
   210
! !
ce4c9f258766 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1259
diff changeset
   211
1559
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1452
diff changeset
   212
!IPSocketAddress class methodsFor:'conversion'!
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1452
diff changeset
   213
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1452
diff changeset
   214
hostAddressFromString:aString
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1452
diff changeset
   215
    "convert an address given in a dot notation like 123.456.78.9"
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1452
diff changeset
   216
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1452
diff changeset
   217
    |components bytes|
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1452
diff changeset
   218
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1452
diff changeset
   219
    components := aString asCollectionOfSubstringsSeparatedBy:$..
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1452
diff changeset
   220
    components size ~~ 4 ifTrue:[
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1452
diff changeset
   221
        ^ NameLookupError raiseRequestWith:aString errorString:' - bad address string'.
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1452
diff changeset
   222
    ].
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1452
diff changeset
   223
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1452
diff changeset
   224
    bytes := components collect:[:eachComponent| 
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1452
diff changeset
   225
        Integer readFromString:eachComponent onError:[^ NameLookupError raiseRequestWith:aString errorString:' - bad address string'].
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1452
diff changeset
   226
    ].
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1452
diff changeset
   227
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1452
diff changeset
   228
    ^ bytes asByteArray.
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1452
diff changeset
   229
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1452
diff changeset
   230
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1452
diff changeset
   231
    "
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1452
diff changeset
   232
        IPSocketAddress hostAddressFromString:'1.2.3.4'
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1452
diff changeset
   233
        IPSocketAddress hostAddressFromString:'255.255.255.255'
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1452
diff changeset
   234
    "
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1452
diff changeset
   235
! !
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1452
diff changeset
   236
1164
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   237
!IPSocketAddress class methodsFor:'queries'!
816
489e7876ab3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 799
diff changeset
   238
1164
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   239
domainSymbol
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   240
1226
0114bd044aa9 vw compatible domainSymbols (afXXX)
Claus Gittinger <cg@exept.de>
parents: 1164
diff changeset
   241
    ^ #'AF_INET'
0114bd044aa9 vw compatible domainSymbols (afXXX)
Claus Gittinger <cg@exept.de>
parents: 1164
diff changeset
   242
!
0114bd044aa9 vw compatible domainSymbols (afXXX)
Claus Gittinger <cg@exept.de>
parents: 1164
diff changeset
   243
0114bd044aa9 vw compatible domainSymbols (afXXX)
Claus Gittinger <cg@exept.de>
parents: 1164
diff changeset
   244
obsoleteDomainSymbol
1164
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   245
    ^ #inet
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   246
!
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   247
1226
0114bd044aa9 vw compatible domainSymbols (afXXX)
Claus Gittinger <cg@exept.de>
parents: 1164
diff changeset
   248
vwDomainSymbol
0114bd044aa9 vw compatible domainSymbols (afXXX)
Claus Gittinger <cg@exept.de>
parents: 1164
diff changeset
   249
    ^ #afInet
100
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   250
! !
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   251
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   252
!IPSocketAddress methodsFor:'accessing'!
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   253
818
2f8331ad12d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
   254
hostAddress
1164
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   255
    ^ (ByteArray new:4) replaceFrom:1 to:4 with:self startingAt:5
816
489e7876ab3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 799
diff changeset
   256
!
489e7876ab3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 799
diff changeset
   257
1164
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   258
hostAddress:aByteArray
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   259
    ^ self replaceFrom:5 to:8 with:aByteArray startingAt:1
818
2f8331ad12d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
   260
!
2f8331ad12d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
   261
2f8331ad12d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
   262
port
1164
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   263
    ^ self unsignedShortAt:3 bigEndian:true
818
2f8331ad12d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
   264
!
2f8331ad12d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
   265
2f8331ad12d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
   266
port:aPortNr
1164
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   267
    self unsignedShortAt:3 put:aPortNr bigEndian:true
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   268
! !
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   269
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   270
!IPSocketAddress methodsFor:'obsolete'!
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   271
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   272
address
1452
4456e3f3ddb4 Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 1366
diff changeset
   273
    <resource: #obsolete>
4456e3f3ddb4 Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 1366
diff changeset
   274
1164
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   275
    ^ self hostAddress
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   276
!
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   277
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   278
portOrName
1452
4456e3f3ddb4 Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 1366
diff changeset
   279
    <resource: #obsolete>
4456e3f3ddb4 Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 1366
diff changeset
   280
1164
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   281
    ^ self port
100
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   282
! !
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   283
770
32ad77c9ed74 added #printOn:
Claus Gittinger <cg@exept.de>
parents: 514
diff changeset
   284
!IPSocketAddress methodsFor:'printing & storing'!
32ad77c9ed74 added #printOn:
Claus Gittinger <cg@exept.de>
parents: 514
diff changeset
   285
1333
d9ebcc42524c printing refactored
penk
parents: 1281
diff changeset
   286
printAddressOn:aStream
d9ebcc42524c printing refactored
penk
parents: 1281
diff changeset
   287
    |i1 i2|
100
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   288
1233
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   289
    i1 := self adrBytesStart.
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   290
    i2 := i1 + self numAdrBytes - 1.
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   291
    i1 to:i2 do:[:i | 
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   292
        i ~~ i1 ifTrue:[
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   293
            aStream nextPut:$.
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   294
        ].
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   295
        (self at:i) printOn:aStream
1164
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   296
    ].
488
b0c17a5ff8ea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 113
diff changeset
   297
! !
b0c17a5ff8ea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 113
diff changeset
   298
1233
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   299
!IPSocketAddress methodsFor:'private'!
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   300
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   301
adrBytesStart
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   302
    ^ 5
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   303
!
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   304
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   305
numAdrBytes
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   306
    ^ 4
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   307
! !
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   308
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   309
!IPSocketAddress methodsFor:'queries'!
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   310
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   311
hostName
1273
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
   312
    |addr name|
1233
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   313
1273
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
   314
    addr := self hostAddress.
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
   315
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
   316
    name := self class nameCacheAt:addr.
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
   317
    name notNil ifTrue:[^ name].
1233
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   318
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   319
    name := super hostName.
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   320
    name notNil ifTrue:[
1273
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
   321
        self class nameCacheAt:addr put:name.
1233
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   322
    ].
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   323
    ^ name
1337
a6372d6797c7 network queries
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
   324
!
a6372d6797c7 network queries
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
   325
a6372d6797c7 network queries
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
   326
networkAddress
a6372d6797c7 network queries
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
   327
    "Extract and return the network address from the host address."
a6372d6797c7 network queries
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
   328
a6372d6797c7 network queries
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
   329
    |highAddrByte|
a6372d6797c7 network queries
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
   330
a6372d6797c7 network queries
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
   331
    highAddrByte := self at: 5.
a6372d6797c7 network queries
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
   332
    (highAddrByte bitAnd: 16r80) == 0 ifTrue: [^ByteArray with: highAddrByte].
a6372d6797c7 network queries
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
   333
    (highAddrByte bitAnd: 16rC0) == 16r80 ifTrue: [^ByteArray with: highAddrByte with: (self at: 6)].
a6372d6797c7 network queries
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
   334
    (highAddrByte bitAnd: 16rC0) == 16rC0 ifTrue: [^ByteArray with: highAddrByte with: (self at: 6) with: (self at: 7)].
a6372d6797c7 network queries
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
   335
    ^ self error: 'unknown network class'
a6372d6797c7 network queries
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
   336
a6372d6797c7 network queries
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
   337
    "
a6372d6797c7 network queries
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
   338
     (IPSocketAddress hostName:'exept.eu.org') networkAddress     
a6372d6797c7 network queries
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
   339
     (IPSocketAddress hostName:'exept.exept.de') networkAddress    
a6372d6797c7 network queries
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
   340
     (IPSocketAddress hostName:'ibm.com') networkAddress          
a6372d6797c7 network queries
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
   341
     (IPSocketAddress hostName:'cnn.com') networkAddress          
a6372d6797c7 network queries
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
   342
    "
a6372d6797c7 network queries
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
   343
!
a6372d6797c7 network queries
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
   344
a6372d6797c7 network queries
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
   345
networkClass
a6372d6797c7 network queries
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
   346
    "Extract and return the network class (as a symbol) from the host address.
a6372d6797c7 network queries
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
   347
     Returns one of #classA #classB #classC."
a6372d6797c7 network queries
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
   348
a6372d6797c7 network queries
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
   349
    |highAddrByte|
a6372d6797c7 network queries
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
   350
a6372d6797c7 network queries
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
   351
    highAddrByte := self at: 5.
a6372d6797c7 network queries
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
   352
    (highAddrByte bitAnd: 16r80) == 0 ifTrue: [^#classA].
a6372d6797c7 network queries
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
   353
    (highAddrByte bitAnd: 16rC0) == 16r80 ifTrue: [^#classB].
a6372d6797c7 network queries
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
   354
    (highAddrByte bitAnd: 16rC0) == 16rC0 ifTrue: [^#classC].
a6372d6797c7 network queries
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
   355
    ^ self error: 'unknown network class'
a6372d6797c7 network queries
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
   356
a6372d6797c7 network queries
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
   357
    "
a6372d6797c7 network queries
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
   358
     (IPSocketAddress hostName:'exept.eu.org') networkClass
a6372d6797c7 network queries
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
   359
    "
1233
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   360
! !
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   361
1366
e01d0f6c102a New method #isLocal returning true for local addresses
Stefan Vogel <sv@exept.de>
parents: 1337
diff changeset
   362
!IPSocketAddress methodsFor:'testing'!
e01d0f6c102a New method #isLocal returning true for local addresses
Stefan Vogel <sv@exept.de>
parents: 1337
diff changeset
   363
e01d0f6c102a New method #isLocal returning true for local addresses
Stefan Vogel <sv@exept.de>
parents: 1337
diff changeset
   364
isLocal
e01d0f6c102a New method #isLocal returning true for local addresses
Stefan Vogel <sv@exept.de>
parents: 1337
diff changeset
   365
    "answer true, if this address adresses a peer on the same host"
e01d0f6c102a New method #isLocal returning true for local addresses
Stefan Vogel <sv@exept.de>
parents: 1337
diff changeset
   366
e01d0f6c102a New method #isLocal returning true for local addresses
Stefan Vogel <sv@exept.de>
parents: 1337
diff changeset
   367
    ^ self hostAddress first == 127
e01d0f6c102a New method #isLocal returning true for local addresses
Stefan Vogel <sv@exept.de>
parents: 1337
diff changeset
   368
! !
e01d0f6c102a New method #isLocal returning true for local addresses
Stefan Vogel <sv@exept.de>
parents: 1337
diff changeset
   369
488
b0c17a5ff8ea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 113
diff changeset
   370
!IPSocketAddress class methodsFor:'documentation'!
100
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   371
488
b0c17a5ff8ea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 113
diff changeset
   372
version
1559
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1452
diff changeset
   373
    ^ '$Header: /cvs/stx/stx/libbasic2/IPSocketAddress.st,v 1.28 2005-06-28 13:10:49 stefan Exp $'
100
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   374
! !