parse_mac.h File Reference

Generalized MAC address parser APIs. More...


Defines

#define MAC_PREFIX_DELIM   '/'
 Delimiter used for mac prefix.
#define MAC_MAX_PREFIX   (MAC_ETHER_ADDR_LEN * 8)
 Maximum MAC prefix.
#define PMF_PREFIX   (1<<0)
 Want prefix in MAC address.
#define PMF_UNICAST   (1<<1)
 Unicast addresses only.
#define PMF_MULTICAST   (1<<2)
 Multicast addresses only.
#define MAC_MCAST_BIT   0x1
#define MAC_IS_MCAST(addr)   (*(addr) & MAC_MCAST_BIT)
#define MAC_ADDRESS_BUF_SZ   21
 Given a string return the length of buffer needed to store this entry in its native format.

Functions

parse_retcode_t parse_mac_addr (const char *str, u_long mac_flags, u_char *address, int *prefix_seen, u_char *plen, char *errmsg, size_t errmsgsize)
 Parses a mac address in form of XX:XX:XX:XX:XX:XX, can use ':' or '.
int format_mac_addr (char *buf, size_t bufsz, u_char *mac, int prefix, u_char plen)
 Formats the MAC address with or without a prefix.


Detailed Description

Generalized MAC address parser APIs.


Define Documentation

#define MAC_ADDRESS_BUF_SZ   21
 

Given a string return the length of buffer needed to store this entry in its native format.

For a MAC Address this should never take more than XX:XX:XX:XX:XX:XX bytes (21).


Function Documentation

int format_mac_addr char *  buf,
size_t  bufsz,
u_char *  mac,
int  prefix,
u_char  plen
 

Formats the MAC address with or without a prefix.

Address comes out in the form of xx:xx:xx;xx:xx/pp or xx:xx:xx:xx:xx:xx

Parameters:
[out] buf Output buffer
[in] bufsz Size of output buffer
[in] mac MAC address
[in] prefix Prefix length should be appened to the end of buffer
[in] plen Prefix length
Returns:
The number of characters written into the buffer, not including the null-terminator character.

parse_retcode_t parse_mac_addr const char *  str,
u_long  mac_flags,
u_char *  address,
int *  prefix_seen,
u_char *  plen,
char *  errmsg,
size_t  errmsgsize
 

Parses a mac address in form of XX:XX:XX:XX:XX:XX, can use ':' or '.

' as delimiters.

The delimiters can fall on any byte/nibble boundary i.e. XXXX.XX.XX.XXXX. XXX.X.X.X.X

Parameters:
[in] str Address to be parsed
[in] mac_flags 
  • PMF_PREFIX require a prefix
  • PMF_MULTICAST require multicast address
[out] address Result address
[out] prefix_seen Prefix length was seen in string
[out] plen Result refix length
[out] errmsg When an error occurs, the error message is written here
[in] errmsgsize Size of the message buffer
Returns:
Status of parsing the string:
  • PARSE_OK on success
  • PARSE_ERR could not grok the string, likely not a MAC address
  • PARSE_ERR_RESTRICT string is an address, but failed some restriction


2007-2009 Juniper Networks, Inc. All rights reserved. The information contained herein is confidential information of Juniper Networks, Inc., and may not be used, disclosed, distributed, modified, or copied without the prior written consent of Juniper Networks, Inc. in an express license. This information is subject to change by Juniper Networks, Inc. Juniper Networks, the Juniper Networks logo, and JUNOS are registered trademarks of Juniper Networks, Inc. in the United States and other countries. All other trademarks, service marks, registered trademarks, or registered service marks are the property of their respective owners.
Generated on Sun May 30 20:23:40 2010 for libjuniper by Doxygen 1.4.5