summaryrefslogtreecommitdiff
path: root/src/libnm-base/nm-base.c
blob: fa64372fd8ae2d453e99f3c8cbce6c48d3a096f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/* SPDX-License-Identifier: LGPL-2.1-or-later */

#include "libnm-glib-aux/nm-default-glib-i18n-lib.h"

#include "nm-base.h"

/*****************************************************************************/

NM_CACHED_QUARK_FCN("nm-crypto-error-quark", _nm_crypto_error_quark);

/*****************************************************************************/

char *
nm_dhcp_iaid_to_hexstr(guint32 iaid, char buf[static NM_DHCP_IAID_TO_HEXSTR_BUF_LEN])
{
    iaid = htobe32(iaid);
    return nm_utils_bin2hexstr_full(&iaid, sizeof(iaid), ':', FALSE, buf);
}

gboolean
nm_dhcp_iaid_from_hexstr(const char *str, guint32 *out_value)
{
    union {
        guint32 num;
        guint8  bin[sizeof(guint32)];
    } iaid;

    if (!nm_utils_hexstr2bin_full(str,
                                  TRUE,
                                  FALSE,
                                  FALSE,
                                  ":",
                                  sizeof(iaid),
                                  iaid.bin,
                                  sizeof(iaid),
                                  NULL))
        return FALSE;

    NM_SET_OUT(out_value, be32toh(iaid.num));
    return TRUE;
}