virmacaddr.h 2.6 KB
Newer Older
1 2 3
/*
 * virmacaddr.h: MAC address handling
 *
4
 * Copyright (C) 2006-2013 Red Hat, Inc.
5 6 7 8 9 10 11 12 13 14 15 16
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
17
 * License along with this library.  If not, see
O
Osier Yang 已提交
18
 * <http://www.gnu.org/licenses/>.
19 20
 */

21 22
#ifndef LIBVIRT_VIRMACADDR_H
# define LIBVIRT_VIRMACADDR_H
23 24

# include "internal.h"
25
# include "viralloc.h"
26 27

# define VIR_MAC_BUFLEN 6
28
# define VIR_MAC_HEXLEN (VIR_MAC_BUFLEN * 2)
29
# define VIR_MAC_PREFIX_BUFLEN 3
S
Stefan Berger 已提交
30 31
# define VIR_MAC_STRING_BUFLEN (VIR_MAC_BUFLEN * 3)

32 33 34 35 36 37
typedef struct _virMacAddr virMacAddr;
typedef virMacAddr *virMacAddrPtr;

struct _virMacAddr {
    unsigned char addr[VIR_MAC_BUFLEN];
};
38 39 40 41 42 43 44
/* This struct is used as a part of a larger struct that is
 * overlaid on an ethernet packet captured with libpcap, so it
 * must not have any extra members added - it must remain exactly
 * 6 bytes in length.
 */
verify(sizeof(struct _virMacAddr) == 6);

45 46

int virMacAddrCompare(const char *mac1, const char *mac2);
47 48
int virMacAddrCmp(const virMacAddr *mac1, const virMacAddr *mac2);
int virMacAddrCmpRaw(const virMacAddr *mac1,
49
                     const unsigned char s[VIR_MAC_BUFLEN]);
50
void virMacAddrSet(virMacAddrPtr dst, const virMacAddr *src);
51
void virMacAddrSetRaw(virMacAddrPtr dst, const unsigned char s[VIR_MAC_BUFLEN]);
52 53
void virMacAddrGetRaw(const virMacAddr *src, unsigned char dst[VIR_MAC_BUFLEN]);
const char *virMacAddrFormat(const virMacAddr *addr,
54
                             char *str);
55
void virMacAddrGenerate(const unsigned char prefix[VIR_MAC_PREFIX_BUFLEN],
56
                        virMacAddrPtr addr) ATTRIBUTE_NOINLINE;
57
int virMacAddrParse(const char* str,
58
                    virMacAddrPtr addr) ATTRIBUTE_RETURN_CHECK;
59 60 61
int virMacAddrParseHex(const char* str,
                       virMacAddrPtr addr)
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
62 63
bool virMacAddrIsUnicast(const virMacAddr *addr);
bool virMacAddrIsMulticast(const virMacAddr *addr);
64
bool virMacAddrIsBroadcastRaw(const unsigned char s[VIR_MAC_BUFLEN]);
65 66
void virMacAddrFree(virMacAddrPtr addr);

67
VIR_DEFINE_AUTOPTR_FUNC(virMacAddr, virMacAddrFree)
68

69
#endif /* LIBVIRT_VIRMACADDR_H */