My own address checking
authorStefan Vogel <sv@exept.de>
Wed, 10 Jul 2013 10:22:44 +0200
changeset 3044 14e5f27a8a78
parent 3043 8b7ec7116ae3
child 3045 7663a852fa0b
My own address checking
IPSocketAddress.st
--- a/IPSocketAddress.st	Tue Jul 09 16:22:38 2013 +0200
+++ b/IPSocketAddress.st	Wed Jul 10 10:22:44 2013 +0200
@@ -180,9 +180,11 @@
 !
 
 thisHost
+    <resource: #obsolete>
     "return the bytes of IN_ADDR_ANY, the address matching any local address"
 
-    ^ #[0 0 0 0]
+    self obsoleteMethodWarning.
+    ^ self anyAddress
 ! !
 
 !IPSocketAddress class methodsFor:'caching'!
@@ -329,6 +331,12 @@
     ^ #'AF_INET'
 !
 
+hostAddressLen
+    "answer the number of bytes of the host address"
+
+    ^ 4
+!
+
 obsoleteDomainSymbol
     ^ #inet
 !
@@ -490,14 +498,37 @@
     "answer true, if this address adresses a peer on the same host"
 
     ^ self hostAddress first == 127
+!
+
+isMyAddress
+    "answer true, if the address refers to my own host"
+
+    self isLocal ifTrue:[^ true].
+
+    OperatingSystem getNetworkAddressInfo do:[:eachIfAddrInfoSet|
+        eachIfAddrInfoSet do:[:eachIfAddrInfo|
+            |address|
+            address := eachIfAddrInfo at:#address ifAbsent:nil.
+            address notNil ifTrue:[
+                (self sameHostAddress:address) ifTrue:[^ true].
+            ]
+        ].
+    ].
+    ^ false
+
+    "
+        (IPSocketAddress hostAddress:#[193 141 12 193] port:80) isMyAddress.
+        (IPSocketAddress hostAddress:#[172 23 1 88] port:80) isMyAddress.
+    "
 ! !
 
 !IPSocketAddress class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic2/IPSocketAddress.st,v 1.35 2011-05-12 11:54:27 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic2/IPSocketAddress.st,v 1.36 2013-07-10 08:22:44 stefan Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic2/IPSocketAddress.st,v 1.35 2011-05-12 11:54:27 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic2/IPSocketAddress.st,v 1.36 2013-07-10 08:22:44 stefan Exp $'
 ! !
+