61 lines
2.3 KiB
C
61 lines
2.3 KiB
C
/*
|
|
Copyright (c) 2012, Matthias Schiffer <mschiffer@universe-factory.net>
|
|
All rights reserved.
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
modification, are permitted provided that the following conditions are met:
|
|
|
|
1. Redistributions of source code must retain the above copyright notice,
|
|
this list of conditions and the following disclaimer.
|
|
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
this list of conditions and the following disclaimer in the documentation
|
|
and/or other materials provided with the distribution.
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
*/
|
|
|
|
|
|
#ifndef _FFD_UTIL_H_
|
|
#define _FFD_UTIL_H_
|
|
|
|
#include "types.h"
|
|
|
|
#include <stdarg.h>
|
|
#include <stdlib.h>
|
|
#include <time.h>
|
|
|
|
|
|
bool file_readv(const char *file, const char *format, va_list ap);
|
|
void random_bytes(void *buffer, size_t len);
|
|
|
|
static inline bool is_eth_addr_unspec(const eth_addr_t *address) {
|
|
const uint8_t *a = address->d;
|
|
|
|
if (a[0]||a[1]||a[2]||a[3]||a[4]||a[5])
|
|
return false;
|
|
else
|
|
return true;
|
|
}
|
|
|
|
static inline bool are_eth_addrs_equal(const eth_addr_t *address1, const eth_addr_t *address2) {
|
|
const uint8_t *a = address1->d;
|
|
const uint8_t *b = address2->d;
|
|
|
|
return (a[0]==b[0] && a[1]==b[1] && a[2]==b[2] && a[3]==b[3] && a[4]==b[4] && a[5]==b[5]);
|
|
}
|
|
|
|
/* returns (tp1 - tp2) in milliseconds */
|
|
static inline int timespec_diff(const struct timespec *tp1, const struct timespec *tp2) {
|
|
return ((tp1->tv_sec - tp2->tv_sec))*1000 + (tp1->tv_nsec - tp2->tv_nsec)/1e6;
|
|
}
|
|
|
|
#endif /* _FFD_UTIL_H_ */
|