UniRec  2.9.3
Macros | Functions | Variables
macaddr.h File Reference

Structure to store MAC address and associated functions. More...

#include <stdint.h>
#include <stdio.h>
#include <inttypes.h>
#include <string.h>
#include "inline.h"

Go to the source code of this file.

Macros

#define MAC_STR_LEN   18
 
#define PRIx8   "x"
 
#define SCNx8   "hhx"
 
#define MAC_ADD_FORMAT_SCN   "%02" SCNx8 ":%02" SCNx8 ":%02" SCNx8 ":%02" SCNx8 ":%02" SCNx8 ":%02" SCNx8 ""
 
#define MAC_ADD_FORMAT_PRI   "%02" PRIx8 ":%02" PRIx8 ":%02" PRIx8 ":%02" PRIx8 ":%02" PRIx8 ":%02" PRIx8 ""
 

Functions

struct __attribute__ ((packed)) mac_addr_s
 
INLINE mac_addr_t mac_from_bytes (uint8_t *array)
 
INLINE int mac_from_str (const char *str, mac_addr_t *addr)
 
INLINE int mac_cmp (const mac_addr_t *addr1, const mac_addr_t *addr2)
 
INLINE void mac_to_str (const mac_addr_t *addr, char *str)
 
INLINE void mac_to_bytes (const mac_addr_t *addr, uint8_t *array)
 

Variables

 mac_addr_t
 

Detailed Description

Structure to store MAC address and associated functions.

Author
Jiri Havranek havra.nosp@m.ji6@.nosp@m.fit.c.nosp@m.vut..nosp@m.cz
Date
2017

Definition in file macaddr.h.

Macro Definition Documentation

◆ MAC_ADD_FORMAT_PRI

#define MAC_ADD_FORMAT_PRI   "%02" PRIx8 ":%02" PRIx8 ":%02" PRIx8 ":%02" PRIx8 ":%02" PRIx8 ":%02" PRIx8 ""

Definition at line 68 of file macaddr.h.

◆ MAC_ADD_FORMAT_SCN

#define MAC_ADD_FORMAT_SCN   "%02" SCNx8 ":%02" SCNx8 ":%02" SCNx8 ":%02" SCNx8 ":%02" SCNx8 ":%02" SCNx8 ""

Definition at line 67 of file macaddr.h.

◆ MAC_STR_LEN

#define MAC_STR_LEN   18

Definition at line 57 of file macaddr.h.

◆ PRIx8

#define PRIx8   "x"

Definition at line 60 of file macaddr.h.

◆ SCNx8

#define SCNx8   "hhx"

Definition at line 64 of file macaddr.h.

Function Documentation

◆ __attribute__()

struct __attribute__ ( (packed)  )

Structure containing MAC address bytes.

Definition at line 73 of file macaddr.h.

◆ mac_cmp()

INLINE int mac_cmp ( const mac_addr_t addr1,
const mac_addr_t addr2 
)

Compare two MAC addresses.

Parameters
[in]addr1MAC address as mac_addr_t
[in]addr2MAC address as mac_addr_t
Returns
Positive number (>0) if addr1 > addr2, negative number (<0) if addr1 < addr2, and zero (=0) if addr1 == addr2.

Definition at line 118 of file macaddr.h.

◆ mac_from_bytes()

INLINE mac_addr_t mac_from_bytes ( uint8_t *  array)

Convert 6B array into mac_addr_t.

Parameters
[in]array6B array containing MAC address bytes.
Returns
MAC address stored as mac_addr_t.

Definition at line 83 of file macaddr.h.

◆ mac_from_str()

INLINE int mac_from_str ( const char *  str,
mac_addr_t addr 
)

Convert string into mac_addr_t.

Parameters
[in]strString for conversion.
[out]addrPointer to memory where to store MAC address.
Returns
1 on success, 0 on error i.e. string is not a valid MAC address.

Definition at line 99 of file macaddr.h.

◆ mac_to_bytes()

INLINE void mac_to_bytes ( const mac_addr_t addr,
uint8_t *  array 
)

Convert mac_addr_t into bytes array.

Parameters
[in]addrPointer to MAC address.
[out]arrayPointer to memory where to store MAC address bytes. It must be of at least 6B size.

Definition at line 144 of file macaddr.h.

◆ mac_to_str()

INLINE void mac_to_str ( const mac_addr_t addr,
char *  str 
)

Convert mac_addr_t into string.

Parameters
[in]addrPointer to MAC address.
[out]strPointer to memory where to store converted MAC address. It must be of at least MAC_STR_LEN size.

Definition at line 129 of file macaddr.h.

Variable Documentation

◆ mac_addr_t

mac_addr_t

Definition at line 75 of file macaddr.h.