IPSocketAddress.st
author mawalch
Thu, 07 Jul 2016 20:22:03 +0200
changeset 3994 22466af8bcbc
parent 3986 e51bb438c6a6
child 4100 808dd4ff3b12
permissions -rw-r--r--
#OTHER by mawalch Spelling fixes.
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
"
1023
12bc2a0f60b5 + bytesToName:
Claus Gittinger <cg@exept.de>
parents: 818
diff changeset
    12
"{ Package: 'stx:libbasic2' }"
12bc2a0f60b5 + bytesToName:
Claus Gittinger <cg@exept.de>
parents: 818
diff changeset
    13
3508
b1824372124b class: IPSocketAddress
Stefan Vogel <sv@exept.de>
parents: 3228
diff changeset
    14
"{ NameSpace: Smalltalk }"
b1824372124b class: IPSocketAddress
Stefan Vogel <sv@exept.de>
parents: 3228
diff changeset
    15
818
2f8331ad12d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
    16
SocketAddress variableByteSubclass:#IPSocketAddress
1164
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
    17
	instanceVariableNames:''
1877
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
    18
	classVariableNames:'CacheInvalidationTimeInterval AddressCacheSize NameCacheSize'
488
b0c17a5ff8ea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 113
diff changeset
    19
	poolDictionaries:''
816
489e7876ab3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 799
diff changeset
    20
	category:'OS-Sockets'
100
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
!
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
1273
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
    23
IPSocketAddress class instanceVariableNames:'addrCache nameCache'
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
"
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
    26
 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
    27
"
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
    28
!
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
    29
100
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
!IPSocketAddress class methodsFor:'documentation'!
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
copyright
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
"
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
 COPYRIGHT (c) 1995 by Claus Gittinger
1164
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
    35
	      All Rights Reserved
100
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
 This software is furnished under a license and may be used
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    38
 only in accordance with the terms of that license and with the
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
 inclusion of the above copyright notice.   This software may not
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
 be provided or otherwise made available to, or used by, any
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
 other person.  No title to or ownership of the software is
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
 hereby transferred.
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
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    46
documentation
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    47
"
111
92392ae9a0f0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 100
diff changeset
    48
    Instances of IPSocketAddress represent tcp/ip-domain socket addresses.
92392ae9a0f0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 100
diff changeset
    49
    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
    50
1877
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
    51
    Notice that for performance, name and address translations are cached here
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
    52
    for some time, in order to speed up heavy lookup such as when operating a webserver or similar
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
    53
    application which does many address-to-hostname translations.
100
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    54
1877
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
    55
    For systems, when the name translation is fast (unix), you may want to disable it,
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
    56
    as it prevents new addresses to be detected for some time (for example, if the own address
3994
22466af8bcbc #OTHER by mawalch
mawalch
parents: 3986
diff changeset
    57
    changes due to a new dhcp address being acquired).
1877
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
    58
    You can also change the cacheing-interval time 
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
    59
    (see caching protocol, flush*Cache, cachingIntervalTime, *CacheSize).
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
    60
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
    61
    [author:]
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
    62
        Claus Gittinger
100
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    63
"
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    64
! !
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    65
1233
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    66
!IPSocketAddress class methodsFor:'instance creation'!
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    67
1559
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1452
diff changeset
    68
addressString:aString
3508
b1824372124b class: IPSocketAddress
Stefan Vogel <sv@exept.de>
parents: 3228
diff changeset
    69
    "convert an address given in a dot notation like 123.456.78.9.
b1824372124b class: IPSocketAddress
Stefan Vogel <sv@exept.de>
parents: 3228
diff changeset
    70
     handle IPv6SocketAddresses too."
1559
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1452
diff changeset
    71
3508
b1824372124b class: IPSocketAddress
Stefan Vogel <sv@exept.de>
parents: 3228
diff changeset
    72
    (self == IPSocketAddress and:[aString includesAny:'[:']) ifTrue:[
b1824372124b class: IPSocketAddress
Stefan Vogel <sv@exept.de>
parents: 3228
diff changeset
    73
        ^ IPv6SocketAddress hostAddress:(IPv6SocketAddress hostAddressFromString:aString).
b1824372124b class: IPSocketAddress
Stefan Vogel <sv@exept.de>
parents: 3228
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
    ^ 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
    76
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1452
diff changeset
    77
    "
1585
32eba58e5498 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1559
diff changeset
    78
     IPSocketAddress addressString:'1.2.3.4'
3508
b1824372124b class: IPSocketAddress
Stefan Vogel <sv@exept.de>
parents: 3228
diff changeset
    79
     IPSocketAddress addressString:'2001:4dd0:ffa3::1'
b1824372124b class: IPSocketAddress
Stefan Vogel <sv@exept.de>
parents: 3228
diff changeset
    80
     IPSocketAddress addressString:'[2001:4dd0:ffa3::1]'
1559
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
!
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1452
diff changeset
    83
1909
c76efba26558 Methods to get all addresses for a given hostname (multihomed hosts)
Stefan Vogel <sv@exept.de>
parents: 1883
diff changeset
    84
allForHostName:name serviceName:portNrOrName type:socketTypeSymbol
c76efba26558 Methods to get all addresses for a given hostname (multihomed hosts)
Stefan Vogel <sv@exept.de>
parents: 1883
diff changeset
    85
    "get a collection of new instance given a hostname, port or service and type.
c76efba26558 Methods to get all addresses for a given hostname (multihomed hosts)
Stefan Vogel <sv@exept.de>
parents: 1883
diff changeset
    86
     Multi-homed hosts return more than one entry
1262
d3daddd36a99 no longer callBack into sockets getHostName/getAddress code.
Claus Gittinger <cg@exept.de>
parents: 1261
diff changeset
    87
     Redefined to cache the result of the name-lookup."
1233
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    88
1909
c76efba26558 Methods to get all addresses for a given hostname (multihomed hosts)
Stefan Vogel <sv@exept.de>
parents: 1883
diff changeset
    89
    |addressList|
1233
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    90
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    91
    portNrOrName isString ifTrue:[
1909
c76efba26558 Methods to get all addresses for a given hostname (multihomed hosts)
Stefan Vogel <sv@exept.de>
parents: 1883
diff changeset
    92
        ^ super allForHostName:name serviceName:portNrOrName type:socketTypeSymbol
1233
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    93
    ].
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    94
1909
c76efba26558 Methods to get all addresses for a given hostname (multihomed hosts)
Stefan Vogel <sv@exept.de>
parents: 1883
diff changeset
    95
    addressList := self addressCacheAt:name.
c76efba26558 Methods to get all addresses for a given hostname (multihomed hosts)
Stefan Vogel <sv@exept.de>
parents: 1883
diff changeset
    96
    addressList notNil ifTrue:[
2172
72f7e3be5d17 *** empty log message ***
sr
parents: 1937
diff changeset
    97
        addressList := addressList 
72f7e3be5d17 *** empty log message ***
sr
parents: 1937
diff changeset
    98
                            collect:[:eachSocketAddress| |sa|
72f7e3be5d17 *** empty log message ***
sr
parents: 1937
diff changeset
    99
                                sa := eachSocketAddress copy.
72f7e3be5d17 *** empty log message ***
sr
parents: 1937
diff changeset
   100
                                sa port:(portNrOrName ? 0).
72f7e3be5d17 *** empty log message ***
sr
parents: 1937
diff changeset
   101
                                sa
72f7e3be5d17 *** empty log message ***
sr
parents: 1937
diff changeset
   102
                            ].
1233
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   103
    ] ifFalse:[
1909
c76efba26558 Methods to get all addresses for a given hostname (multihomed hosts)
Stefan Vogel <sv@exept.de>
parents: 1883
diff changeset
   104
        addressList := super allForHostName:name serviceName:portNrOrName type:socketTypeSymbol.
3582
05524be1015d class: IPSocketAddress
Claus Gittinger <cg@exept.de>
parents: 3522
diff changeset
   105
        addressList notNil ifTrue:[
05524be1015d class: IPSocketAddress
Claus Gittinger <cg@exept.de>
parents: 3522
diff changeset
   106
            self addressCacheAt:name put:(addressList deepCopy).
05524be1015d class: IPSocketAddress
Claus Gittinger <cg@exept.de>
parents: 3522
diff changeset
   107
        ].
1233
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   108
    ].
1909
c76efba26558 Methods to get all addresses for a given hostname (multihomed hosts)
Stefan Vogel <sv@exept.de>
parents: 1883
diff changeset
   109
    ^ addressList
1233
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   110
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   111
    "
3136
f46a935ba037 class: IPSocketAddress
Stefan Vogel <sv@exept.de>
parents: 3070
diff changeset
   112
     IPSocketAddress allForHostName:nil serviceName:10 type:#stream  
1909
c76efba26558 Methods to get all addresses for a given hostname (multihomed hosts)
Stefan Vogel <sv@exept.de>
parents: 1883
diff changeset
   113
     SocketAddress allForHostName:'localhost' serviceName:10 type:#stream  
c76efba26558 Methods to get all addresses for a given hostname (multihomed hosts)
Stefan Vogel <sv@exept.de>
parents: 1883
diff changeset
   114
     IPSocketAddress allForHostName:'localhost' serviceName:'echo' type:#datagram 
c76efba26558 Methods to get all addresses for a given hostname (multihomed hosts)
Stefan Vogel <sv@exept.de>
parents: 1883
diff changeset
   115
     IPSocketAddress allForHostName:'www.google.com' serviceName:80 type:nil       
1233
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   116
    "
2172
72f7e3be5d17 *** empty log message ***
sr
parents: 1937
diff changeset
   117
72f7e3be5d17 *** empty log message ***
sr
parents: 1937
diff changeset
   118
    "Modified: / 17-06-2009 / 15:21:00 / sr"
1559
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1452
diff changeset
   119
!
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
localHost
1883
2b2f137130ae +localHostAddress
Claus Gittinger <cg@exept.de>
parents: 1877
diff changeset
   122
    "get a new instance representing the local-host address as seen internally"
1559
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1452
diff changeset
   123
3070
58c5d590c68e class: IPSocketAddress
Claus Gittinger <cg@exept.de>
parents: 3057
diff changeset
   124
    ^ self hostAddress:self local
1877
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   125
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   126
    "
1909
c76efba26558 Methods to get all addresses for a given hostname (multihomed hosts)
Stefan Vogel <sv@exept.de>
parents: 1883
diff changeset
   127
     self localHost
1877
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   128
     self localHost hostName
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   129
    "
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   130
1883
2b2f137130ae +localHostAddress
Claus Gittinger <cg@exept.de>
parents: 1877
diff changeset
   131
    "Modified: / 04-06-2007 / 21:34:22 / cg"
2b2f137130ae +localHostAddress
Claus Gittinger <cg@exept.de>
parents: 1877
diff changeset
   132
!
2b2f137130ae +localHostAddress
Claus Gittinger <cg@exept.de>
parents: 1877
diff changeset
   133
2b2f137130ae +localHostAddress
Claus Gittinger <cg@exept.de>
parents: 1877
diff changeset
   134
localHostAddress
1909
c76efba26558 Methods to get all addresses for a given hostname (multihomed hosts)
Stefan Vogel <sv@exept.de>
parents: 1883
diff changeset
   135
    "NO NO NEVER!!
c76efba26558 Methods to get all addresses for a given hostname (multihomed hosts)
Stefan Vogel <sv@exept.de>
parents: 1883
diff changeset
   136
     Do not use this, because:
c76efba26558 Methods to get all addresses for a given hostname (multihomed hosts)
Stefan Vogel <sv@exept.de>
parents: 1883
diff changeset
   137
     1. It does not work on hosts that get their IP address via dhcp (at least on unix/linux)
c76efba26558 Methods to get all addresses for a given hostname (multihomed hosts)
Stefan Vogel <sv@exept.de>
parents: 1883
diff changeset
   138
     2. Usually OperatingSystem>>#getHostName does not return a fully qualified domain name
c76efba26558 Methods to get all addresses for a given hostname (multihomed hosts)
Stefan Vogel <sv@exept.de>
parents: 1883
diff changeset
   139
     3. This does not work well on multi-homed hosts"
1883
2b2f137130ae +localHostAddress
Claus Gittinger <cg@exept.de>
parents: 1877
diff changeset
   140
1909
c76efba26558 Methods to get all addresses for a given hostname (multihomed hosts)
Stefan Vogel <sv@exept.de>
parents: 1883
diff changeset
   141
    <resource: #obsolete>
c76efba26558 Methods to get all addresses for a given hostname (multihomed hosts)
Stefan Vogel <sv@exept.de>
parents: 1883
diff changeset
   142
c76efba26558 Methods to get all addresses for a given hostname (multihomed hosts)
Stefan Vogel <sv@exept.de>
parents: 1883
diff changeset
   143
    self obsoleteMethodWarning:'Do not use this method'.
c76efba26558 Methods to get all addresses for a given hostname (multihomed hosts)
Stefan Vogel <sv@exept.de>
parents: 1883
diff changeset
   144
    ^ self hostName:(OperatingSystem getHostName).
1883
2b2f137130ae +localHostAddress
Claus Gittinger <cg@exept.de>
parents: 1877
diff changeset
   145
2b2f137130ae +localHostAddress
Claus Gittinger <cg@exept.de>
parents: 1877
diff changeset
   146
    "
1909
c76efba26558 Methods to get all addresses for a given hostname (multihomed hosts)
Stefan Vogel <sv@exept.de>
parents: 1883
diff changeset
   147
      self localHostAddress
1883
2b2f137130ae +localHostAddress
Claus Gittinger <cg@exept.de>
parents: 1877
diff changeset
   148
    "
2b2f137130ae +localHostAddress
Claus Gittinger <cg@exept.de>
parents: 1877
diff changeset
   149
1909
c76efba26558 Methods to get all addresses for a given hostname (multihomed hosts)
Stefan Vogel <sv@exept.de>
parents: 1883
diff changeset
   150
1883
2b2f137130ae +localHostAddress
Claus Gittinger <cg@exept.de>
parents: 1877
diff changeset
   151
    "Modified: / 04-06-2007 / 21:17:25 / cg"
1233
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   152
! !
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   153
1164
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   154
!IPSocketAddress class methodsFor:'addressing'!
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   155
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   156
anyAddress
1281
6df4f8f211e3 fixed anyHost
Claus Gittinger <cg@exept.de>
parents: 1273
diff changeset
   157
    "return the anonymous addresses bytes"
1164
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   158
1281
6df4f8f211e3 fixed anyHost
Claus Gittinger <cg@exept.de>
parents: 1273
diff changeset
   159
    ^ #[0 0 0 0]
1164
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   160
!
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   161
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   162
anyPort
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   163
    "return the anon port number"
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
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   166
!
100
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   167
1281
6df4f8f211e3 fixed anyHost
Claus Gittinger <cg@exept.de>
parents: 1273
diff changeset
   168
broadcastAddress
6df4f8f211e3 fixed anyHost
Claus Gittinger <cg@exept.de>
parents: 1273
diff changeset
   169
    "return the broadcast address"
6df4f8f211e3 fixed anyHost
Claus Gittinger <cg@exept.de>
parents: 1273
diff changeset
   170
6df4f8f211e3 fixed anyHost
Claus Gittinger <cg@exept.de>
parents: 1273
diff changeset
   171
    ^ #[255 255 255 255]
6df4f8f211e3 fixed anyHost
Claus Gittinger <cg@exept.de>
parents: 1273
diff changeset
   172
!
6df4f8f211e3 fixed anyHost
Claus Gittinger <cg@exept.de>
parents: 1273
diff changeset
   173
1164
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   174
firstUnreservedPort
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   175
    "return the first unreserved port number"
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   176
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   177
    ^ 1024
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   178
!
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   179
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   180
local
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   181
    "return IN_ADDR_ANY, the address matching any local address"
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   182
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   183
    ^ #[127 0 0 1]
100
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   184
!
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   185
1164
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   186
maxPort
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   187
    "return the maximum port number"
100
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   188
1164
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   189
    ^ 16rffff
816
489e7876ab3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 799
diff changeset
   190
!
489e7876ab3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 799
diff changeset
   191
1164
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   192
thisHost
3044
14e5f27a8a78 My own address checking
Stefan Vogel <sv@exept.de>
parents: 2567
diff changeset
   193
    <resource: #obsolete>
1226
0114bd044aa9 vw compatible domainSymbols (afXXX)
Claus Gittinger <cg@exept.de>
parents: 1164
diff changeset
   194
    "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
   195
3044
14e5f27a8a78 My own address checking
Stefan Vogel <sv@exept.de>
parents: 2567
diff changeset
   196
    self obsoleteMethodWarning.
14e5f27a8a78 My own address checking
Stefan Vogel <sv@exept.de>
parents: 2567
diff changeset
   197
    ^ self anyAddress
1164
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   198
! !
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   199
1273
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
   200
!IPSocketAddress class methodsFor:'caching'!
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
   201
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
   202
addressCacheAt:aHostName
1909
c76efba26558 Methods to get all addresses for a given hostname (multihomed hosts)
Stefan Vogel <sv@exept.de>
parents: 1883
diff changeset
   203
    |addrAndTime addressList time|
1877
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   204
1273
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
   205
    addrCache notNil ifTrue:[
1877
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   206
        addrAndTime := addrCache at:aHostName ifAbsent:nil.
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   207
        addrAndTime notNil ifTrue:[
1909
c76efba26558 Methods to get all addresses for a given hostname (multihomed hosts)
Stefan Vogel <sv@exept.de>
parents: 1883
diff changeset
   208
            addressList := addrAndTime key.
1877
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   209
            time := addrAndTime value.
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   210
            ((Timestamp now) secondDeltaFrom:time) > self cacheInvalidationTimeInterval ifFalse:[
1909
c76efba26558 Methods to get all addresses for a given hostname (multihomed hosts)
Stefan Vogel <sv@exept.de>
parents: 1883
diff changeset
   211
                ^ addressList.
1877
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   212
            ]
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   213
        ].
1273
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
   214
    ].
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
   215
    ^ nil
1877
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   216
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   217
    "Modified: / 26-04-2007 / 11:21:37 / cg"
1273
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
   218
!
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
   219
1909
c76efba26558 Methods to get all addresses for a given hostname (multihomed hosts)
Stefan Vogel <sv@exept.de>
parents: 1883
diff changeset
   220
addressCacheAt:aName put:anAddressList
1877
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   221
    (addrCache isNil or:[addrCache size > self addressCacheSize]) ifTrue:[
1273
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
   222
        addrCache := Dictionary new.
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
   223
    ].
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
   224
    
1909
c76efba26558 Methods to get all addresses for a given hostname (multihomed hosts)
Stefan Vogel <sv@exept.de>
parents: 1883
diff changeset
   225
    addrCache at:aName put:(anAddressList -> Timestamp now).
1877
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   226
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   227
    "Modified: / 26-04-2007 / 11:23:26 / cg"
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   228
!
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   229
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   230
addressCacheSize
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   231
    ^ AddressCacheSize ? 50
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   232
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   233
    "Created: / 26-04-2007 / 11:22:40 / cg"
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   234
!
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   235
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   236
addressCacheSize:aNumber
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   237
    AddressCacheSize := aNumber
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   238
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   239
    "Created: / 26-04-2007 / 11:24:05 / cg"
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   240
!
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   241
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   242
cacheInvalidationTimeInterval
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   243
    ^ CacheInvalidationTimeInterval ? 30
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   244
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   245
    "Created: / 26-04-2007 / 11:21:31 / cg"
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   246
!
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   247
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   248
cacheInvalidationTimeInterval:seconds
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   249
    CacheInvalidationTimeInterval := seconds
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   250
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   251
    "Created: / 26-04-2007 / 11:29:28 / cg"
1273
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
   252
!
1261
ce4c9f258766 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1259
diff changeset
   253
ce4c9f258766 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1259
diff changeset
   254
flushAddressCache
1273
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
   255
    addrCache := nil
1261
ce4c9f258766 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1259
diff changeset
   256
ce4c9f258766 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1259
diff changeset
   257
    "
ce4c9f258766 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1259
diff changeset
   258
     self flushAddressCache
ce4c9f258766 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1259
diff changeset
   259
    "
1273
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
   260
!
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
   261
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
   262
flushNameCache
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
   263
    nameCache := Dictionary new.
1877
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   264
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   265
    "
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   266
     self flushNameCache
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   267
    "
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   268
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   269
    "Modified: / 26-04-2007 / 11:25:32 / cg"
1273
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
   270
!
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
   271
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
   272
nameCacheAt:aHostAddress
1877
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   273
    |nameAndTime name time|
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   274
1273
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
   275
    nameCache notNil ifTrue:[
1877
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   276
        nameAndTime := nameCache at:aHostAddress ifAbsent:nil.
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   277
        nameAndTime notNil ifTrue:[
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   278
            name := nameAndTime key.
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   279
            time := nameAndTime value.
3228
00bf7f052ee1 class: IPSocketAddress
Claus Gittinger <cg@exept.de>
parents: 3136
diff changeset
   280
            (Timestamp now secondDeltaFrom:time) > self cacheInvalidationTimeInterval ifFalse:[
1877
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   281
                ^ name.
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   282
            ]
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   283
        ].
1273
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
   284
    ].
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
   285
    ^ nil
1877
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   286
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   287
    "Modified: / 26-04-2007 / 11:25:11 / cg"
1273
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
   288
!
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
   289
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
   290
nameCacheAt:aHostAddress put:aName
1877
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   291
    (nameCache isNil or:[nameCache size > self nameCacheSize]) ifTrue:[
1273
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
   292
        nameCache := Dictionary new.
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
   293
    ].
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
   294
    
1877
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   295
    nameCache at:aHostAddress put:(aName -> Timestamp now).
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   296
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   297
    "Modified: / 26-04-2007 / 11:23:35 / cg"
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   298
!
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   299
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   300
nameCacheSize
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   301
    ^ NameCacheSize ? 50
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   302
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   303
    "Created: / 26-04-2007 / 11:22:44 / cg"
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   304
!
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   305
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   306
nameCacheSize:aNumber
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   307
    NameCacheSize := aNumber
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   308
d143433fd007 cache: decay after some time to allow for dhcp-changing addresses
Claus Gittinger <cg@exept.de>
parents: 1585
diff changeset
   309
    "Created: / 26-04-2007 / 11:23:49 / cg"
1261
ce4c9f258766 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1259
diff changeset
   310
! !
ce4c9f258766 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1259
diff changeset
   311
1559
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1452
diff changeset
   312
!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
   313
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1452
diff changeset
   314
hostAddressFromString:aString
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1452
diff changeset
   315
    "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
   316
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1452
diff changeset
   317
    |components bytes|
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1452
diff changeset
   318
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1452
diff changeset
   319
    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
   320
    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
   321
        ^ 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
   322
    ].
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1452
diff changeset
   323
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1452
diff changeset
   324
    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
   325
        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
   326
    ].
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1452
diff changeset
   327
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1452
diff changeset
   328
    ^ bytes asByteArray.
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1452
diff changeset
   329
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1452
diff changeset
   330
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1452
diff changeset
   331
    "
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1452
diff changeset
   332
        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
   333
        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
   334
    "
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1452
diff changeset
   335
! !
609a0707ab22 New: #addressString: to create an instance from a numeric string representation like
Stefan Vogel <sv@exept.de>
parents: 1452
diff changeset
   336
1164
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   337
!IPSocketAddress class methodsFor:'queries'!
816
489e7876ab3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 799
diff changeset
   338
3052
e690209a5c52 changes #domainSymbol to #domain fpr comaptibility with Socket
Stefan Vogel <sv@exept.de>
parents: 3049
diff changeset
   339
domain
1226
0114bd044aa9 vw compatible domainSymbols (afXXX)
Claus Gittinger <cg@exept.de>
parents: 1164
diff changeset
   340
    ^ #'AF_INET'
0114bd044aa9 vw compatible domainSymbols (afXXX)
Claus Gittinger <cg@exept.de>
parents: 1164
diff changeset
   341
!
0114bd044aa9 vw compatible domainSymbols (afXXX)
Claus Gittinger <cg@exept.de>
parents: 1164
diff changeset
   342
3044
14e5f27a8a78 My own address checking
Stefan Vogel <sv@exept.de>
parents: 2567
diff changeset
   343
hostAddressLen
14e5f27a8a78 My own address checking
Stefan Vogel <sv@exept.de>
parents: 2567
diff changeset
   344
    "answer the number of bytes of the host address"
14e5f27a8a78 My own address checking
Stefan Vogel <sv@exept.de>
parents: 2567
diff changeset
   345
14e5f27a8a78 My own address checking
Stefan Vogel <sv@exept.de>
parents: 2567
diff changeset
   346
    ^ 4
14e5f27a8a78 My own address checking
Stefan Vogel <sv@exept.de>
parents: 2567
diff changeset
   347
!
14e5f27a8a78 My own address checking
Stefan Vogel <sv@exept.de>
parents: 2567
diff changeset
   348
1226
0114bd044aa9 vw compatible domainSymbols (afXXX)
Claus Gittinger <cg@exept.de>
parents: 1164
diff changeset
   349
obsoleteDomainSymbol
1164
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   350
    ^ #inet
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   351
!
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   352
1226
0114bd044aa9 vw compatible domainSymbols (afXXX)
Claus Gittinger <cg@exept.de>
parents: 1164
diff changeset
   353
vwDomainSymbol
0114bd044aa9 vw compatible domainSymbols (afXXX)
Claus Gittinger <cg@exept.de>
parents: 1164
diff changeset
   354
    ^ #afInet
100
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   355
! !
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   356
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   357
!IPSocketAddress methodsFor:'accessing'!
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   358
818
2f8331ad12d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
   359
hostAddress
1164
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   360
    ^ (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
   361
!
489e7876ab3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 799
diff changeset
   362
1164
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   363
hostAddress:aByteArray
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   364
    ^ self replaceFrom:5 to:8 with:aByteArray startingAt:1
818
2f8331ad12d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
   365
!
2f8331ad12d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
   366
2f8331ad12d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
   367
port
3772
ea7a85e2bb8f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3582
diff changeset
   368
    ^ self unsignedInt16At:3 MSB:true
818
2f8331ad12d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
   369
!
2f8331ad12d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
   370
2f8331ad12d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
   371
port:aPortNr
3772
ea7a85e2bb8f #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3582
diff changeset
   372
    self unsignedInt16At:3 put:aPortNr MSB:true
1164
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   373
! !
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   374
3510
51b43eca349f class: IPSocketAddress
Stefan Vogel <sv@exept.de>
parents: 3508
diff changeset
   375
!IPSocketAddress methodsFor:'comparing'!
51b43eca349f class: IPSocketAddress
Stefan Vogel <sv@exept.de>
parents: 3508
diff changeset
   376
3518
aedfc3d7d38f class: IPSocketAddress
Stefan Vogel <sv@exept.de>
parents: 3510
diff changeset
   377
sameHostAddress:aSocketAddress
3510
51b43eca349f class: IPSocketAddress
Stefan Vogel <sv@exept.de>
parents: 3508
diff changeset
   378
    "answer true, if myself and aSocketAddress have the same host address
51b43eca349f class: IPSocketAddress
Stefan Vogel <sv@exept.de>
parents: 3508
diff changeset
   379
     (but possibly different ports)."
51b43eca349f class: IPSocketAddress
Stefan Vogel <sv@exept.de>
parents: 3508
diff changeset
   380
51b43eca349f class: IPSocketAddress
Stefan Vogel <sv@exept.de>
parents: 3508
diff changeset
   381
    ^ aSocketAddress class == self class 
51b43eca349f class: IPSocketAddress
Stefan Vogel <sv@exept.de>
parents: 3508
diff changeset
   382
        and:[self sameContentsFrom:5 to:9 as:aSocketAddress startingAt:5]
51b43eca349f class: IPSocketAddress
Stefan Vogel <sv@exept.de>
parents: 3508
diff changeset
   383
! !
51b43eca349f class: IPSocketAddress
Stefan Vogel <sv@exept.de>
parents: 3508
diff changeset
   384
3057
ac2356ba61ca IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3052
diff changeset
   385
!IPSocketAddress methodsFor:'converting'!
ac2356ba61ca IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3052
diff changeset
   386
ac2356ba61ca IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3052
diff changeset
   387
asIPv4SocketAddress
ac2356ba61ca IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3052
diff changeset
   388
    ^ self
ac2356ba61ca IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3052
diff changeset
   389
!
ac2356ba61ca IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3052
diff changeset
   390
ac2356ba61ca IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3052
diff changeset
   391
asIPv6SocketAddress
ac2356ba61ca IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3052
diff changeset
   392
    "convert a IPv4 address to a mapped IPv6SocketAddress"
ac2356ba61ca IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3052
diff changeset
   393
ac2356ba61ca IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3052
diff changeset
   394
    |ipv6|
ac2356ba61ca IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3052
diff changeset
   395
ac2356ba61ca IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3052
diff changeset
   396
    ipv6 := IPv6SocketAddress new.
ac2356ba61ca IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3052
diff changeset
   397
    ipv6
ac2356ba61ca IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3052
diff changeset
   398
        port:self port;
ac2356ba61ca IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3052
diff changeset
   399
        at:19 put:16rff;
ac2356ba61ca IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3052
diff changeset
   400
        at:20 put:16rff.
ac2356ba61ca IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3052
diff changeset
   401
ac2356ba61ca IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3052
diff changeset
   402
    ipv6 replaceFrom:21 to:24 with:self startingAt:5.
ac2356ba61ca IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3052
diff changeset
   403
ac2356ba61ca IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3052
diff changeset
   404
    ^ ipv6.
ac2356ba61ca IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3052
diff changeset
   405
ac2356ba61ca IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3052
diff changeset
   406
    "
ac2356ba61ca IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3052
diff changeset
   407
        (self localHost port:80) asIPv6SocketAddress
ac2356ba61ca IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3052
diff changeset
   408
        (self localHost port:80) asIPv6SocketAddress asIPv4SocketAddress
ac2356ba61ca IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3052
diff changeset
   409
    "
ac2356ba61ca IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3052
diff changeset
   410
! !
ac2356ba61ca IPv6/IPv4 conversion
Stefan Vogel <sv@exept.de>
parents: 3052
diff changeset
   411
1164
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   412
!IPSocketAddress methodsFor:'obsolete'!
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   413
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   414
address
1452
4456e3f3ddb4 Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 1366
diff changeset
   415
    <resource: #obsolete>
4456e3f3ddb4 Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 1366
diff changeset
   416
1164
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   417
    ^ self hostAddress
100
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   418
! !
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   419
770
32ad77c9ed74 added #printOn:
Claus Gittinger <cg@exept.de>
parents: 514
diff changeset
   420
!IPSocketAddress methodsFor:'printing & storing'!
32ad77c9ed74 added #printOn:
Claus Gittinger <cg@exept.de>
parents: 514
diff changeset
   421
1333
d9ebcc42524c printing refactored
penk
parents: 1281
diff changeset
   422
printAddressOn:aStream
d9ebcc42524c printing refactored
penk
parents: 1281
diff changeset
   423
    |i1 i2|
100
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   424
1233
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   425
    i1 := self adrBytesStart.
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   426
    i2 := i1 + self numAdrBytes - 1.
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   427
    i1 to:i2 do:[:i | 
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   428
        i ~~ i1 ifTrue:[
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   429
            aStream nextPut:$.
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   430
        ].
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   431
        (self at:i) printOn:aStream
1164
41a2750af1fa New socket support
Stefan Vogel <sv@exept.de>
parents: 1026
diff changeset
   432
    ].
488
b0c17a5ff8ea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 113
diff changeset
   433
! !
b0c17a5ff8ea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 113
diff changeset
   434
1233
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   435
!IPSocketAddress methodsFor:'private'!
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   436
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   437
adrBytesStart
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   438
    ^ 5
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   439
!
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   440
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   441
numAdrBytes
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   442
    ^ 4
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   443
! !
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   444
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   445
!IPSocketAddress methodsFor:'queries'!
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   446
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   447
hostName
1273
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
   448
    |addr name|
1233
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   449
1273
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
   450
    addr := self hostAddress.
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
   451
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
   452
    name := self class nameCacheAt:addr.
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
   453
    name notNil ifTrue:[^ name].
1233
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   454
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   455
    name := super hostName.
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   456
    name notNil ifTrue:[
1273
03afdf3f895e addrCache and nameCache must be separate for
Claus Gittinger <cg@exept.de>
parents: 1262
diff changeset
   457
        self class nameCacheAt:addr put:name.
1233
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   458
    ].
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   459
    ^ name
1337
a6372d6797c7 network queries
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
   460
!
a6372d6797c7 network queries
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
   461
2567
Stefan Vogel <sv@exept.de>
parents: 2172
diff changeset
   462
netmaskSize
Stefan Vogel <sv@exept.de>
parents: 2172
diff changeset
   463
    "If this is an address mask: answer the number of mask bits in the address mask"
Stefan Vogel <sv@exept.de>
parents: 2172
diff changeset
   464
Stefan Vogel <sv@exept.de>
parents: 2172
diff changeset
   465
    |sz bI lowBit lowBitHere hostAddress|
Stefan Vogel <sv@exept.de>
parents: 2172
diff changeset
   466
Stefan Vogel <sv@exept.de>
parents: 2172
diff changeset
   467
    hostAddress := self hostAddress.
Stefan Vogel <sv@exept.de>
parents: 2172
diff changeset
   468
Stefan Vogel <sv@exept.de>
parents: 2172
diff changeset
   469
    lowBit := 0.
Stefan Vogel <sv@exept.de>
parents: 2172
diff changeset
   470
    bI := 1.
Stefan Vogel <sv@exept.de>
parents: 2172
diff changeset
   471
    sz := hostAddress size.
Stefan Vogel <sv@exept.de>
parents: 2172
diff changeset
   472
    [
Stefan Vogel <sv@exept.de>
parents: 2172
diff changeset
   473
        lowBitHere := (hostAddress basicAt:bI) lowBit.
Stefan Vogel <sv@exept.de>
parents: 2172
diff changeset
   474
        lowBitHere ~= 0 ifTrue:[
Stefan Vogel <sv@exept.de>
parents: 2172
diff changeset
   475
            lowBit := lowBit + (9 - lowBitHere).
Stefan Vogel <sv@exept.de>
parents: 2172
diff changeset
   476
        ].
Stefan Vogel <sv@exept.de>
parents: 2172
diff changeset
   477
        bI := bI + 1.
Stefan Vogel <sv@exept.de>
parents: 2172
diff changeset
   478
    ] doWhile:[lowBitHere == 1 and:[bI < sz]].
Stefan Vogel <sv@exept.de>
parents: 2172
diff changeset
   479
Stefan Vogel <sv@exept.de>
parents: 2172
diff changeset
   480
    ^ lowBit
Stefan Vogel <sv@exept.de>
parents: 2172
diff changeset
   481
Stefan Vogel <sv@exept.de>
parents: 2172
diff changeset
   482
    "
Stefan Vogel <sv@exept.de>
parents: 2172
diff changeset
   483
      (IPSocketAddress addressString:'255.255.0.0') netmaskSize
Stefan Vogel <sv@exept.de>
parents: 2172
diff changeset
   484
      (IPSocketAddress addressString:'255.255.128.0') netmaskSize
Stefan Vogel <sv@exept.de>
parents: 2172
diff changeset
   485
      (IPv6SocketAddress addressString:'FFFF:FFFF:FFFF:FFFF::') netmaskSize
Stefan Vogel <sv@exept.de>
parents: 2172
diff changeset
   486
      (IPv6SocketAddress addressString:'FFFF:FFFF:FFFF:FFF0::') netmaskSize
Stefan Vogel <sv@exept.de>
parents: 2172
diff changeset
   487
      (IPv6SocketAddress addressString:'F0FF:FFFF:FFFF:FFF0::') netmaskSize
Stefan Vogel <sv@exept.de>
parents: 2172
diff changeset
   488
    "
Stefan Vogel <sv@exept.de>
parents: 2172
diff changeset
   489
!
Stefan Vogel <sv@exept.de>
parents: 2172
diff changeset
   490
1337
a6372d6797c7 network queries
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
   491
networkAddress
2567
Stefan Vogel <sv@exept.de>
parents: 2172
diff changeset
   492
    "THINK TWICE before using this!! 
3510
51b43eca349f class: IPSocketAddress
Stefan Vogel <sv@exept.de>
parents: 3508
diff changeset
   493
     This is deprecated, it doesn't make sense any longer since CIDR, subnetting and netmasks
2567
Stefan Vogel <sv@exept.de>
parents: 2172
diff changeset
   494
     have been introduced.
Stefan Vogel <sv@exept.de>
parents: 2172
diff changeset
   495
Stefan Vogel <sv@exept.de>
parents: 2172
diff changeset
   496
     Extract and return the network part from the host address."
Stefan Vogel <sv@exept.de>
parents: 2172
diff changeset
   497
    <resource: #obsolete>
1337
a6372d6797c7 network queries
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
   498
a6372d6797c7 network queries
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
   499
    |highAddrByte|
a6372d6797c7 network queries
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
   500
a6372d6797c7 network queries
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
   501
    highAddrByte := self at: 5.
a6372d6797c7 network queries
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
   502
    (highAddrByte bitAnd: 16r80) == 0 ifTrue: [^ByteArray with: highAddrByte].
a6372d6797c7 network queries
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
   503
    (highAddrByte bitAnd: 16rC0) == 16r80 ifTrue: [^ByteArray with: highAddrByte with: (self at: 6)].
a6372d6797c7 network queries
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
   504
    (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
   505
    ^ self error: 'unknown network class'
a6372d6797c7 network queries
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
   506
a6372d6797c7 network queries
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
   507
    "
a6372d6797c7 network queries
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
   508
     (IPSocketAddress hostName:'exept.eu.org') networkAddress     
a6372d6797c7 network queries
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
   509
     (IPSocketAddress hostName:'exept.exept.de') networkAddress    
a6372d6797c7 network queries
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
   510
     (IPSocketAddress hostName:'ibm.com') networkAddress          
a6372d6797c7 network queries
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
   511
     (IPSocketAddress hostName:'cnn.com') networkAddress          
a6372d6797c7 network queries
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
   512
    "
a6372d6797c7 network queries
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
   513
!
a6372d6797c7 network queries
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
   514
a6372d6797c7 network queries
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
   515
networkClass
2567
Stefan Vogel <sv@exept.de>
parents: 2172
diff changeset
   516
    "THINK TWICE before using this!! 
Stefan Vogel <sv@exept.de>
parents: 2172
diff changeset
   517
     This is deprecated, it doesn't make sense any longer since subnetting and netmasks
Stefan Vogel <sv@exept.de>
parents: 2172
diff changeset
   518
     have been introduced.
Stefan Vogel <sv@exept.de>
parents: 2172
diff changeset
   519
Stefan Vogel <sv@exept.de>
parents: 2172
diff changeset
   520
     Extract and return the network class (as a symbol) from the host address.
1337
a6372d6797c7 network queries
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
   521
     Returns one of #classA #classB #classC."
2567
Stefan Vogel <sv@exept.de>
parents: 2172
diff changeset
   522
    <resource: #obsolete>
1337
a6372d6797c7 network queries
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
   523
a6372d6797c7 network queries
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
   524
    |highAddrByte|
a6372d6797c7 network queries
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
   525
a6372d6797c7 network queries
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
   526
    highAddrByte := self at: 5.
a6372d6797c7 network queries
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
   527
    (highAddrByte bitAnd: 16r80) == 0 ifTrue: [^#classA].
a6372d6797c7 network queries
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
   528
    (highAddrByte bitAnd: 16rC0) == 16r80 ifTrue: [^#classB].
a6372d6797c7 network queries
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
   529
    (highAddrByte bitAnd: 16rC0) == 16rC0 ifTrue: [^#classC].
a6372d6797c7 network queries
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
   530
    ^ self error: 'unknown network class'
a6372d6797c7 network queries
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
   531
a6372d6797c7 network queries
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
   532
    "
a6372d6797c7 network queries
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
   533
     (IPSocketAddress hostName:'exept.eu.org') networkClass
a6372d6797c7 network queries
Claus Gittinger <cg@exept.de>
parents: 1333
diff changeset
   534
    "
1937
09fb98759b4a Clean up:
Stefan Vogel <sv@exept.de>
parents: 1909
diff changeset
   535
!
09fb98759b4a Clean up:
Stefan Vogel <sv@exept.de>
parents: 1909
diff changeset
   536
09fb98759b4a Clean up:
Stefan Vogel <sv@exept.de>
parents: 1909
diff changeset
   537
portOrName
09fb98759b4a Clean up:
Stefan Vogel <sv@exept.de>
parents: 1909
diff changeset
   538
    ^ self port
1233
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   539
! !
999feaf57b80 cache host translations
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
   540
1366
e01d0f6c102a New method #isLocal returning true for local addresses
Stefan Vogel <sv@exept.de>
parents: 1337
diff changeset
   541
!IPSocketAddress methodsFor:'testing'!
e01d0f6c102a New method #isLocal returning true for local addresses
Stefan Vogel <sv@exept.de>
parents: 1337
diff changeset
   542
3049
3f7eeb76695e More address type testing
Stefan Vogel <sv@exept.de>
parents: 3044
diff changeset
   543
isBroadcast
3f7eeb76695e More address type testing
Stefan Vogel <sv@exept.de>
parents: 3044
diff changeset
   544
    "answer true, if this is a broadcast address"
3f7eeb76695e More address type testing
Stefan Vogel <sv@exept.de>
parents: 3044
diff changeset
   545
3f7eeb76695e More address type testing
Stefan Vogel <sv@exept.de>
parents: 3044
diff changeset
   546
    ^ (self at:5) == 255
3f7eeb76695e More address type testing
Stefan Vogel <sv@exept.de>
parents: 3044
diff changeset
   547
        and:[self sameContentsFrom:6 to:8 as:#[255 255 255] startingAt:1]
3f7eeb76695e More address type testing
Stefan Vogel <sv@exept.de>
parents: 3044
diff changeset
   548
3f7eeb76695e More address type testing
Stefan Vogel <sv@exept.de>
parents: 3044
diff changeset
   549
    "
3f7eeb76695e More address type testing
Stefan Vogel <sv@exept.de>
parents: 3044
diff changeset
   550
        (self hostAddress:self broadcastAddress) isBroadcast
3f7eeb76695e More address type testing
Stefan Vogel <sv@exept.de>
parents: 3044
diff changeset
   551
    "
3f7eeb76695e More address type testing
Stefan Vogel <sv@exept.de>
parents: 3044
diff changeset
   552
!
3f7eeb76695e More address type testing
Stefan Vogel <sv@exept.de>
parents: 3044
diff changeset
   553
3f7eeb76695e More address type testing
Stefan Vogel <sv@exept.de>
parents: 3044
diff changeset
   554
isIPSocketAddress
3f7eeb76695e More address type testing
Stefan Vogel <sv@exept.de>
parents: 3044
diff changeset
   555
    ^ true
3f7eeb76695e More address type testing
Stefan Vogel <sv@exept.de>
parents: 3044
diff changeset
   556
!
3f7eeb76695e More address type testing
Stefan Vogel <sv@exept.de>
parents: 3044
diff changeset
   557
3f7eeb76695e More address type testing
Stefan Vogel <sv@exept.de>
parents: 3044
diff changeset
   558
isIPv4SocketAddress
3f7eeb76695e More address type testing
Stefan Vogel <sv@exept.de>
parents: 3044
diff changeset
   559
    ^ self class == IPSocketAddress
3f7eeb76695e More address type testing
Stefan Vogel <sv@exept.de>
parents: 3044
diff changeset
   560
!
3f7eeb76695e More address type testing
Stefan Vogel <sv@exept.de>
parents: 3044
diff changeset
   561
1366
e01d0f6c102a New method #isLocal returning true for local addresses
Stefan Vogel <sv@exept.de>
parents: 1337
diff changeset
   562
isLocal
3986
e51bb438c6a6 #OTHER by mawalch
mawalch
parents: 3772
diff changeset
   563
    "answer true, if this address addresses a peer on the same host"
1366
e01d0f6c102a New method #isLocal returning true for local addresses
Stefan Vogel <sv@exept.de>
parents: 1337
diff changeset
   564
3049
3f7eeb76695e More address type testing
Stefan Vogel <sv@exept.de>
parents: 3044
diff changeset
   565
    ^ (self at:5) == 127
3f7eeb76695e More address type testing
Stefan Vogel <sv@exept.de>
parents: 3044
diff changeset
   566
3f7eeb76695e More address type testing
Stefan Vogel <sv@exept.de>
parents: 3044
diff changeset
   567
    "
3f7eeb76695e More address type testing
Stefan Vogel <sv@exept.de>
parents: 3044
diff changeset
   568
        self localHost isLocal
3f7eeb76695e More address type testing
Stefan Vogel <sv@exept.de>
parents: 3044
diff changeset
   569
    "
3f7eeb76695e More address type testing
Stefan Vogel <sv@exept.de>
parents: 3044
diff changeset
   570
!
3f7eeb76695e More address type testing
Stefan Vogel <sv@exept.de>
parents: 3044
diff changeset
   571
3f7eeb76695e More address type testing
Stefan Vogel <sv@exept.de>
parents: 3044
diff changeset
   572
isMulticast
3f7eeb76695e More address type testing
Stefan Vogel <sv@exept.de>
parents: 3044
diff changeset
   573
    "answer true, if this address is a multicast address 224.0.0.0/4 or Class D"
3f7eeb76695e More address type testing
Stefan Vogel <sv@exept.de>
parents: 3044
diff changeset
   574
3f7eeb76695e More address type testing
Stefan Vogel <sv@exept.de>
parents: 3044
diff changeset
   575
    ^ (self at:5) between:224 and:239  
3044
14e5f27a8a78 My own address checking
Stefan Vogel <sv@exept.de>
parents: 2567
diff changeset
   576
!
14e5f27a8a78 My own address checking
Stefan Vogel <sv@exept.de>
parents: 2567
diff changeset
   577
14e5f27a8a78 My own address checking
Stefan Vogel <sv@exept.de>
parents: 2567
diff changeset
   578
isMyAddress
14e5f27a8a78 My own address checking
Stefan Vogel <sv@exept.de>
parents: 2567
diff changeset
   579
    "answer true, if the address refers to my own host"
14e5f27a8a78 My own address checking
Stefan Vogel <sv@exept.de>
parents: 2567
diff changeset
   580
14e5f27a8a78 My own address checking
Stefan Vogel <sv@exept.de>
parents: 2567
diff changeset
   581
    self isLocal ifTrue:[^ true].
14e5f27a8a78 My own address checking
Stefan Vogel <sv@exept.de>
parents: 2567
diff changeset
   582
3518
aedfc3d7d38f class: IPSocketAddress
Stefan Vogel <sv@exept.de>
parents: 3510
diff changeset
   583
    OperatingSystem isLinuxLike ifTrue:[
aedfc3d7d38f class: IPSocketAddress
Stefan Vogel <sv@exept.de>
parents: 3510
diff changeset
   584
        "/ make this general later, when getNetworkAddressInfo is implemented in Win32OperatingSystem
aedfc3d7d38f class: IPSocketAddress
Stefan Vogel <sv@exept.de>
parents: 3510
diff changeset
   585
        OperatingSystem getNetworkAddressInfo do:[:eachIfAddrInfoSet|
aedfc3d7d38f class: IPSocketAddress
Stefan Vogel <sv@exept.de>
parents: 3510
diff changeset
   586
            eachIfAddrInfoSet do:[:eachIfAddrInfo|
aedfc3d7d38f class: IPSocketAddress
Stefan Vogel <sv@exept.de>
parents: 3510
diff changeset
   587
                |address|
aedfc3d7d38f class: IPSocketAddress
Stefan Vogel <sv@exept.de>
parents: 3510
diff changeset
   588
                address := eachIfAddrInfo at:#address ifAbsent:nil.
aedfc3d7d38f class: IPSocketAddress
Stefan Vogel <sv@exept.de>
parents: 3510
diff changeset
   589
                address notNil ifTrue:[
aedfc3d7d38f class: IPSocketAddress
Stefan Vogel <sv@exept.de>
parents: 3510
diff changeset
   590
                    (self sameHostAddress:address) ifTrue:[^ true].
aedfc3d7d38f class: IPSocketAddress
Stefan Vogel <sv@exept.de>
parents: 3510
diff changeset
   591
                ]
aedfc3d7d38f class: IPSocketAddress
Stefan Vogel <sv@exept.de>
parents: 3510
diff changeset
   592
            ].
3044
14e5f27a8a78 My own address checking
Stefan Vogel <sv@exept.de>
parents: 2567
diff changeset
   593
        ].
3518
aedfc3d7d38f class: IPSocketAddress
Stefan Vogel <sv@exept.de>
parents: 3510
diff changeset
   594
        ^ false
aedfc3d7d38f class: IPSocketAddress
Stefan Vogel <sv@exept.de>
parents: 3510
diff changeset
   595
    ] ifFalse:[
aedfc3d7d38f class: IPSocketAddress
Stefan Vogel <sv@exept.de>
parents: 3510
diff changeset
   596
        "/ For now - works only for ipv4...
aedfc3d7d38f class: IPSocketAddress
Stefan Vogel <sv@exept.de>
parents: 3510
diff changeset
   597
        ^ OperatingSystem getNetworkAddresses contains:[:each| 
aedfc3d7d38f class: IPSocketAddress
Stefan Vogel <sv@exept.de>
parents: 3510
diff changeset
   598
                self sameHostAddress:each
aedfc3d7d38f class: IPSocketAddress
Stefan Vogel <sv@exept.de>
parents: 3510
diff changeset
   599
            ].
aedfc3d7d38f class: IPSocketAddress
Stefan Vogel <sv@exept.de>
parents: 3510
diff changeset
   600
    ].
3044
14e5f27a8a78 My own address checking
Stefan Vogel <sv@exept.de>
parents: 2567
diff changeset
   601
14e5f27a8a78 My own address checking
Stefan Vogel <sv@exept.de>
parents: 2567
diff changeset
   602
    "
14e5f27a8a78 My own address checking
Stefan Vogel <sv@exept.de>
parents: 2567
diff changeset
   603
        (IPSocketAddress hostAddress:#[172 23 1 88] port:80) isMyAddress.
3049
3f7eeb76695e More address type testing
Stefan Vogel <sv@exept.de>
parents: 3044
diff changeset
   604
        (IPSocketAddress hostAddress:#[192 168 23 29] port:80) isMyAddress.
3518
aedfc3d7d38f class: IPSocketAddress
Stefan Vogel <sv@exept.de>
parents: 3510
diff changeset
   605
        (IPv6SocketAddress addressString:'2003:6A:682B:4500:A288:B4FF:FEC6:1514') isMyAddress.
aedfc3d7d38f class: IPSocketAddress
Stefan Vogel <sv@exept.de>
parents: 3510
diff changeset
   606
        (IPv6SocketAddress addressString:'2001:6A:682B:4500:A288:B4FF:FEC6:1514') isMyAddress.
3044
14e5f27a8a78 My own address checking
Stefan Vogel <sv@exept.de>
parents: 2567
diff changeset
   607
    "
1366
e01d0f6c102a New method #isLocal returning true for local addresses
Stefan Vogel <sv@exept.de>
parents: 1337
diff changeset
   608
! !
e01d0f6c102a New method #isLocal returning true for local addresses
Stefan Vogel <sv@exept.de>
parents: 1337
diff changeset
   609
488
b0c17a5ff8ea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 113
diff changeset
   610
!IPSocketAddress class methodsFor:'documentation'!
100
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   611
488
b0c17a5ff8ea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 113
diff changeset
   612
version
3582
05524be1015d class: IPSocketAddress
Claus Gittinger <cg@exept.de>
parents: 3522
diff changeset
   613
    ^ '$Header$'
2567
Stefan Vogel <sv@exept.de>
parents: 2172
diff changeset
   614
!
Stefan Vogel <sv@exept.de>
parents: 2172
diff changeset
   615
Stefan Vogel <sv@exept.de>
parents: 2172
diff changeset
   616
version_CVS
3582
05524be1015d class: IPSocketAddress
Claus Gittinger <cg@exept.de>
parents: 3522
diff changeset
   617
    ^ '$Header$'
100
058d9257c30d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   618
! !
3044
14e5f27a8a78 My own address checking
Stefan Vogel <sv@exept.de>
parents: 2567
diff changeset
   619