diff options
Diffstat (limited to 'src/libnm-base')
-rw-r--r-- | src/libnm-base/nm-base.c | 30 | ||||
-rw-r--r-- | src/libnm-base/nm-base.h | 8 |
2 files changed, 38 insertions, 0 deletions
diff --git a/src/libnm-base/nm-base.c b/src/libnm-base/nm-base.c index f81b285c4e..fa64372fd8 100644 --- a/src/libnm-base/nm-base.c +++ b/src/libnm-base/nm-base.c @@ -9,3 +9,33 @@ 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; +} diff --git a/src/libnm-base/nm-base.h b/src/libnm-base/nm-base.h index 74e8142f21..77d2ef0a16 100644 --- a/src/libnm-base/nm-base.h +++ b/src/libnm-base/nm-base.h @@ -423,4 +423,12 @@ typedef enum { NM_DNS_IP_CONFIG_TYPE_VPN, } NMDnsIPConfigType; +/*****************************************************************************/ + +#define NM_DHCP_IAID_TO_HEXSTR_BUF_LEN (3 * sizeof(guint32)) + +char *nm_dhcp_iaid_to_hexstr(guint32 iaid, char buf[static NM_DHCP_IAID_TO_HEXSTR_BUF_LEN]); + +gboolean nm_dhcp_iaid_from_hexstr(const char *str, guint32 *out_value); + #endif /* __NM_LIBNM_BASE_H__ */ |