added:
authorStefan Vogel <sv@exept.de>
Thu, 12 May 2011 13:54:27 +0200
changeset 2567 b2820eb56b6a
parent 2566 ef461edd1746
child 2568 4b0180395472
added: #netmaskSize changed: #networkAddress #networkClass
IPSocketAddress.st
--- a/IPSocketAddress.st	Wed May 11 17:32:16 2011 +0200
+++ b/IPSocketAddress.st	Thu May 12 13:54:27 2011 +0200
@@ -405,8 +405,42 @@
     ^ name
 !
 
+netmaskSize
+    "If this is an address mask: answer the number of mask bits in the address mask"
+
+    |sz bI lowBit lowBitHere hostAddress|
+
+    hostAddress := self hostAddress.
+
+    lowBit := 0.
+    bI := 1.
+    sz := hostAddress size.
+    [
+        lowBitHere := (hostAddress basicAt:bI) lowBit.
+        lowBitHere ~= 0 ifTrue:[
+            lowBit := lowBit + (9 - lowBitHere).
+        ].
+        bI := bI + 1.
+    ] doWhile:[lowBitHere == 1 and:[bI < sz]].
+
+    ^ lowBit
+
+    "
+      (IPSocketAddress addressString:'255.255.0.0') netmaskSize
+      (IPSocketAddress addressString:'255.255.128.0') netmaskSize
+      (IPv6SocketAddress addressString:'FFFF:FFFF:FFFF:FFFF::') netmaskSize
+      (IPv6SocketAddress addressString:'FFFF:FFFF:FFFF:FFF0::') netmaskSize
+      (IPv6SocketAddress addressString:'F0FF:FFFF:FFFF:FFF0::') netmaskSize
+    "
+!
+
 networkAddress
-    "Extract and return the network address from the host address."
+    "THINK TWICE before using this!! 
+     This is deprecated, it doesn't make sense any longer since subnetting and netmasks
+     have been introduced.
+
+     Extract and return the network part from the host address."
+    <resource: #obsolete>
 
     |highAddrByte|
 
@@ -425,8 +459,13 @@
 !
 
 networkClass
-    "Extract and return the network class (as a symbol) from the host address.
+    "THINK TWICE before using this!! 
+     This is deprecated, it doesn't make sense any longer since subnetting and netmasks
+     have been introduced.
+
+     Extract and return the network class (as a symbol) from the host address.
      Returns one of #classA #classB #classC."
+    <resource: #obsolete>
 
     |highAddrByte|
 
@@ -456,5 +495,9 @@
 !IPSocketAddress class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic2/IPSocketAddress.st,v 1.34 2009-06-17 16:26:18 sr Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic2/IPSocketAddress.st,v 1.35 2011-05-12 11:54:27 stefan Exp $'
+!
+
+version_CVS
+    ^ '$Header: /cvs/stx/stx/libbasic2/IPSocketAddress.st,v 1.35 2011-05-12 11:54:27 stefan Exp $'
 ! !