<commit_before>using System;
using System.Net;
using System.Net.Sockets;
using System.Text;

namespace StatsdClient
{
    public interface IStatsdUDP
    {
        void Send(string command);
    }

    public class StatsdUDP : IDisposable, IStatsdUDP
    {
        private int MaxUDPPacketSize { get; set; } // In bytes; default is MetricsConfig.DefaultStatsdMaxUDPPacketSize.
                                                   // Set to zero for no limit.
        public IPEndPoint IPEndpoint { get; private set; }
        private Socket UDPSocket { get; set; }
        private string Name { get; set; }
        private int Port { get; set; }
        private bool _disposed;

        public StatsdUDP(string name, int port, int maxUdpPacketSize = MetricsConfig.DefaultStatsdMaxUDPPacketSize)
        {
            Name = name;
            Port = port;
            MaxUDPPacketSize = maxUdpPacketSize;

            UDPSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);

            var ipAddress = GetIpv4Address(name);

            IPEndpoint = new IPEndPoint(ipAddress, Port);
        }

        private IPAddress GetIpv4Address(string name)
        {
            IPAddress ipAddress;
            var isValidIpAddress = IPAddress.TryParse(name, out ipAddress);

            if (!isValidIpAddress)
            {
                var addressList = Dns.GetHostEntry(Name).AddressList;

                var positionForIpv4 = addressList.Length - 1;

                ipAddress = addressList[positionForIpv4];
            }
            return ipAddress;
        }

        public void Send(string command)
        {
            Send(Encoding.ASCII.GetBytes(command));<commit_msg>Get IPv4 address in a safer way.<commit_after>using System;
using System.Net;
using System.Net.Sockets;
using System.Text;

namespace StatsdClient
{
    public interface IStatsdUDP
    {
        void Send(string command);
    }

    public class StatsdUDP : IDisposable, IStatsdUDP
    {
        private int MaxUDPPacketSize { get; set; } // In bytes; default is MetricsConfig.DefaultStatsdMaxUDPPacketSize.
                                                   // Set to zero for no limit.
        public IPEndPoint IPEndpoint { get; private set; }
        private Socket UDPSocket { get; set; }
        private string Name { get; set; }
        private int Port { get; set; }
        private bool _disposed;

        public StatsdUDP(string name, int port, int maxUdpPacketSize = MetricsConfig.DefaultStatsdMaxUDPPacketSize)
        {
            Name = name;
            Port = port;
            MaxUDPPacketSize = maxUdpPacketSize;

            UDPSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);

            var ipAddress = GetIpv4Address(name);

            IPEndpoint = new IPEndPoint(ipAddress, Port);
        }

        private IPAddress GetIpv4Address(string name)
        {
            IPAddress ipAddress;
            var isValidIpAddress = IPAddress.TryParse(name, out ipAddress);

            if (!isValidIpAddress)
            {
                ipAddress = GetIpFromHostname();
            }

            return ipAddress;
        }

        private IPAddress GetIpFromHostname()
        {
            var addressList = Dns.GetHostEntry(Name).AddressList;
            var ipv4Addresses = addressList.Where(x => x.AddressFamily != AddressFamily.InterNetworkV6);

            return ipv4Addresses.First();
        }
        public void Send(string command)
        {
            Send(Encoding.ASCII.GetBytes(command));
{'fraction_non_alphanumeric': 0.07276798208788134, 'fraction_numerical': 0.0030786453960257487, 'mean_word_length': 1.9659751037344397, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4125956', 'n_tokens_mistral': 998, 'n_tokens_neox': 959, 'n_words': 243}