<commit_before>/*
 * network.c: network helper APIs for libvirt
 *
 * Copyright (C) 2009-2010 Red Hat, Inc.
 *
 * See COPYING.LIB for the License of this software
 *
 * <NAME> <<EMAIL>>
 */

#include <config.h>
#include <arpa/inet.h>

#include "memory.h"
#include "network.h"

/*
 * Helpers to extract the IP arrays from the virSocketAddrPtr
 * That part is the less portable of the module
 */
typedef unsigned char virIPv4Addr[4];
typedef virIPv4Addr *virIPv4AddrPtr;
typedef unsigned short virIPv6Addr[8];
typedef virIPv6Addr *virIPv6AddrPtr;

static int getIPv4Addr(virSocketAddrPtr addr, virIPv4AddrPtr tab) {
    unsigned long val;
    int i;

    if ((addr == NULL) || (tab == NULL) || (addr->stor.ss_family != AF_INET))
        return(-1);

    val = ntohl(addr->inet4.sin_addr.s_addr);

    for (i = 0;i < 4;i++) {
        (*tab)[3 - i] = val & 0xFF;
        val >>= 8;
    }

    return(0);
}

static int getIPv6Addr(virSocketAddrPtr addr, virIPv6AddrPtr tab) {
    int i;

    if ((addr == NULL) || (tab == NULL) || (addr->stor.ss_family != AF_INET6))
        return(-1);

    for (i = 0;i < 8;i++) {
        (*tab)[i] = ntohs(addr->inet6.sin6_addr.s6_addr16[i]);
    }

    return(0);<commit_msg>build: avoid non-portable IPv6 struct member, for MacOS X<commit_after>/*
 * network.c: network helper APIs for libvirt
 *
 * Copyright (C) 2009-2010 Red Hat, Inc.
 *
 * See COPYING.LIB for the License of this software
 *
 * <NAME> <<EMAIL>>
 */

#include <config.h>
#include <arpa/inet.h>

#include "memory.h"
#include "network.h"

/*
 * Helpers to extract the IP arrays from the virSocketAddrPtr
 * That part is the less portable of the module
 */
typedef unsigned char virIPv4Addr[4];
typedef virIPv4Addr *virIPv4AddrPtr;
typedef unsigned short virIPv6Addr[8];
typedef virIPv6Addr *virIPv6AddrPtr;

static int getIPv4Addr(virSocketAddrPtr addr, virIPv4AddrPtr tab) {
    unsigned long val;
    int i;

    if ((addr == NULL) || (tab == NULL) || (addr->stor.ss_family != AF_INET))
        return(-1);

    val = ntohl(addr->inet4.sin_addr.s_addr);

    for (i = 0;i < 4;i++) {
        (*tab)[3 - i] = val & 0xFF;
        val >>= 8;
    }

    return(0);
}

static int getIPv6Addr(virSocketAddrPtr addr, virIPv6AddrPtr tab) {
    int i;

    if ((addr == NULL) || (tab == NULL) || (addr->stor.ss_family != AF_INET6))
        return(-1);

    for (i = 0;i < 8;i++) {
        (*tab)[i] = ((addr->inet6.sin6_addr.s6_addr[2 * i] << 8) |
                     addr->inet6.sin6_addr.s6_addr[2 * i + 1]);
    }

    return(0);
{'fraction_non_alphanumeric': 0.15320665083135393, 'fraction_numerical': 0.03246239113222486, 'mean_word_length': 3.011111111111111, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 26, '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': '188853', 'n_tokens_mistral': 1002, 'n_tokens_neox': 938, 'n_words': 248}