<commit_before>#include "rb_getifaddrs.h"

int get_if_family(struct ifaddrs *ifa){
	if(ifa && ifa->ifa_addr)
		return ifa->ifa_addr->sa_family;
	return 0;
}

VALUE rb_get_ifaddrs(void)
{
    struct ifaddrs *ifaddr, *ifa;
    char *str_inet_name = "inet_addr";
    char *str_netmask_name = "netmask";
    VALUE rb_if_hash;

    if (getifaddrs(&ifaddr) == -1)
    {
        rb_raise(rb_eSystemCallError, "Can't get info about interfaces");
    }
    rb_if_hash = rb_hash_new();
    for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next)
    {
        int family;

        family = get_if_family(ifa);
        if (family == AF_INET)
        {
            VALUE rb_if_data_hash;
            char host[NI_MAXHOST];
            char netmask[NI_MAXHOST];
            char *if_name;
            int s;

            if_name = ifa->ifa_name;
            s = getnameinfo(ifa->ifa_addr, sizeof(struct sockaddr_in),
                            host, NI_MAXHOST,
                            NULL, 0, NI_NUMERICHOST);
            if (s != 0)
            {
                rb_raise(rb_eSystemCallError, "Can't get IP from %s", if_name);
            }
            s = getnameinfo(ifa->ifa_netmask, sizeof(struct sockaddr_in),
                            netmask, NI_MAXHOST,
                            NULL, 0, NI_NUMERICHOST);<commit_msg>refactor<commit_after>#include "rb_getifaddrs.h"

int get_if_family(struct ifaddrs *ifa){
	if(ifa && ifa->ifa_addr)
		return ifa->ifa_addr->sa_family;
	return 0;
}

char * get_if_name(struct ifaddrs *ifa){
	return ifa->ifa_name;
}

VALUE rb_get_ifaddrs(void)
{
    struct ifaddrs *ifaddr, *ifa;
    char *str_inet_name = "inet_addr";
    char *str_netmask_name = "netmask";
    VALUE rb_if_hash;

    if (getifaddrs(&ifaddr) == -1)
    {
        rb_raise(rb_eSystemCallError, "Can't get info about interfaces");
    }
    rb_if_hash = rb_hash_new();
    for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next)
    {
        int family;

        family = get_if_family(ifa);
        if (family == AF_INET)
        {
            VALUE rb_if_data_hash;
            char host[NI_MAXHOST];
            char netmask[NI_MAXHOST];
            char *if_name;
            int s;

            if_name = get_if_name(ifa);

            s = getnameinfo(ifa->ifa_addr, sizeof(struct sockaddr_in),
                            host, NI_MAXHOST,
                            NULL, 0, NI_NUMERICHOST);
            if (s != 0)
            {
                rb_raise(rb_eSystemCallError, "Can't get IP from %s", if_name);
            }
            s = getnameinfo(ifa->ifa_netmask, sizeof(struct sockaddr_in),
                            netmask, NI_MAXHOST,
                            NULL, 0, NI_NUMERICHOST);
{'fraction_non_alphanumeric': 0.10745937961595273, 'fraction_numerical': 0.003692762186115214, 'mean_word_length': 1.8455882352941178, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2470300', 'n_tokens_mistral': 957, 'n_tokens_neox': 919, 'n_words': 187}