@@ -217,54 +217,6 @@ public static int CompareIpValues(IPAddress ip1, IPAddress ip2)
217217 return 0 ;
218218 }
219219
220- /// <summary>
221- /// Compares to strings that may contain subnet masks by their format and value.
222- /// </summary>
223- public static int CompareSubnetMasks ( string subnetMask1 , string subnetMask2 )
224- {
225- if ( subnetMask1 . StartsWith ( @"\" ) ) subnetMask1 = subnetMask1 . Substring ( 1 ) ;
226- if ( subnetMask2 . StartsWith ( @"\" ) ) subnetMask2 = subnetMask2 . Substring ( 1 ) ;
227-
228- if ( subnetMask1 != subnetMask2 )
229- {
230- // first without subnet masks
231- if ( subnetMask1 == "" ) return - 1 ;
232- if ( subnetMask2 == "" ) return 1 ;
233-
234- // then cidr
235- int subnet1CIDR ;
236- int subnet2CIDR ;
237- bool subnet1IsInt = int . TryParse ( subnetMask1 , out subnet1CIDR ) ;
238- bool subnet2IsInt = int . TryParse ( subnetMask2 , out subnet2CIDR ) ;
239- if ( subnet1IsInt && subnet2IsInt )
240- {
241- if ( subnet1CIDR < subnet2CIDR ) return - 1 ;
242- if ( subnet1CIDR > subnet2CIDR ) return 1 ;
243- }
244- if ( subnet1IsInt ) return - 1 ;
245- if ( subnet2IsInt ) return 1 ;
246-
247-
248- IPAddress ? subnet1IP ;
249- IPAddress ? subnet2IP ;
250- bool subnet1IsIp = IPAddress . TryParse ( subnetMask1 , out subnet1IP ) ;
251- bool subnet2IsIp = IPAddress . TryParse ( subnetMask2 , out subnet2IP ) ;
252- if ( subnet1IP != null && subnet2IP != null && subnet1IsIp && subnet2IsIp )
253- {
254- // if both in ip format order by value
255- int compareIpValuesResult = CompareIpValues ( subnet1IP , subnet2IP ) ;
256- if ( compareIpValuesResult != 0 ) return compareIpValuesResult ;
257- }
258-
259- // if one is ip format it should come before the unhandled case
260- if ( subnet1IsIp ) return - 1 ;
261- if ( subnet2IsIp ) return 1 ;
262- }
263-
264- // if nothing fits just treat as they were the same
265- return 0 ;
266- }
267-
268220 /// <summary>
269221 /// Compares two IPAdress objects by their family (IPv4 or IPv6).
270222 /// </summary>
0 commit comments