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