• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

lduchosal / ipnetwork / 960

15 May 2026 07:18AM UTC coverage: 0.0% (-94.1%) from 94.053%
960

Pull #411

appveyor

web-flow
Merge ef6b054ce into 4cec191ae
Pull Request #411: Bump MSTest.TestFramework from 4.2.2 to 4.2.3

0 of 2438 relevant lines covered (0.0%)

0.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/System.Net.IPNetwork/IPNetwork2ToIPAddress.cs
1
// <copyright file="IPNetwork2ToIPAddress.cs" company="IPNetwork">
2
// Copyright (c) IPNetwork. All rights reserved.
3
// </copyright>
4

5
namespace System.Net;
6

7
using System.Net.Sockets;
8
using System.Numerics;
9

10
/// <summary>
11
/// ToIPAddress.
12
/// </summary>
13
public sealed partial class IPNetwork2
14
{
15
    /// <summary>
16
    /// Transform a uint ipaddress into IPAddress object.
17
    /// </summary>
18
    /// <param name="ipaddress">A number representing an ip address to convert.</param>
19
    /// <param name="family">Either IPv4 or IPv6.</param>
20
    /// <returns>An IPAddress.</returns>
21
    public static IPAddress ToIPAddress(BigInteger ipaddress, AddressFamily family)
22
    {
×
23
        int width = family == AddressFamily.InterNetwork ? 4 : 16;
×
24
        byte[] bytes = ipaddress.ToByteArray();
×
25
        byte[] bytes2 = new byte[width];
×
26
        int copy = bytes.Length > width ? width : bytes.Length;
×
27
        Array.Copy(bytes, 0, bytes2, 0, copy);
×
28
        Array.Reverse(bytes2);
×
29

30
        byte[] sized = Resize(bytes2, family);
×
31
        var ip = new IPAddress(sized);
×
32
        return ip;
×
33
    }
×
34

35
    /// <summary>
36
    /// Resizes the given byte array to match the expected width for the specified address family (IPv4 or IPv6).
37
    /// Pads with zeros if the array is shorter than required.
38
    /// </summary>
39
    /// <param name="bytes">The byte array to resize.</param>
40
    /// <param name="family">The address family (IPv4 or IPv6).</param>
41
    /// <returns>A byte array resized to the appropriate length for the address family.</returns>
42
    internal static byte[] Resize(byte[] bytes, AddressFamily family)
43
    {
×
44
        if (family != AddressFamily.InterNetwork
×
45
            && family != AddressFamily.InterNetworkV6)
×
46
        {
×
47
            throw new ArgumentException("Invalid address family.", nameof(family));
×
48
        }
49

50
        int width = family == AddressFamily.InterNetwork ? 4 : 16;
×
51

52
        if (bytes.Length > width)
×
53
        {
×
54
            throw new ArgumentException("Byte array is too large for the address family.", nameof(bytes));
×
55
        }
56

57
        byte[] result = new byte[width];
×
58
        Array.Copy(bytes, 0, result, 0, bytes.Length);
×
59

60
        return result;
×
61
    }
×
62
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc