⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 glue.hh

📁 Click is a modular router toolkit. To use it you ll need to know how to compile and install the sof
💻 HH
📖 第 1 页 / 共 2 页
字号:
// -*- c-basic-offset: 4; related-file-name: "../../lib/glue.cc" -*-#ifndef CLICK_GLUE_HH#define CLICK_GLUE_HH// Removes many common #include <header>s and abstracts differences between// kernel and user space, and between operating systems.// HEADERS#if CLICK_LINUXMODULE# define _LOOSE_KERNEL_NAMES 1 /* define ino_t, off_t, etc. */# undef __KERNEL_STRICT_NAMES# ifndef __OPTIMIZE__#  define __OPTIMIZE__ 1 /* get ntohl() macros. otherwise undefined. */# endif# include <click/cxxprotect.h>CLICK_CXX_PROTECT# ifdef WANT_MOD_USE_COUNT#  define __NO_VERSION__#  include <linux/module.h>#  define HAVE_MOD_USE_COUNT 1# endif# include <linux/kernel.h># include <linux/string.h># include <linux/skbuff.h># if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0)#  include <linux/malloc.h>#  include <linux/vmalloc.h>#  include <linux/interrupt.h># else#  include <linux/hardirq.h># endif# include <linux/ctype.h># include <linux/time.h># include <linux/errno.h>CLICK_CXX_UNPROTECT# include <click/cxxunprotect.h>#elif CLICK_BSDMODULE# include <click/cxxprotect.h>CLICK_CXX_PROTECT# include <sys/ctype.h># include <sys/systm.h># include <sys/time.h># include <sys/param.h># include <sys/kernel.h># include <sys/mbuf.h># include <sys/malloc.h># include <sys/libkern.h># include <sys/proc.h># include <sys/sysproto.h>CLICK_CXX_UNPROTECT# include <click/cxxunprotect.h>#else /* CLICK_USERLEVEL */# include <stdio.h># include <stdlib.h># include <string.h># include <ctype.h># include <errno.h># include <limits.h># include <time.h># include <sys/socket.h># include <netinet/in.h># include <sys/time.h># if CLICK_NSextern "C" int simclick_gettimeofday(struct timeval *);# endif# if HAVE_MULTITHREAD#  include <pthread.h># endif#endif// DEBUGGING OUTPUTextern "C" {void click_chatter(const char *fmt, ...);}// DEBUG MALLOC#if CLICK_DMALLOC && (CLICK_LINUXMODULE || CLICK_BSDMODULE)extern uint32_t click_dmalloc_where;# define CLICK_DMALLOC_REG(s) do { const unsigned char *__str = reinterpret_cast<const unsigned char *>(s); click_dmalloc_where = (__str[0]<<24) | (__str[1]<<16) | (__str[2]<<8) | __str[3]; } while (0)#else# define CLICK_DMALLOC_REG(s)#endif// LALLOC#if CLICK_LINUXMODULE# define CLICK_LALLOC(size)	(click_lalloc((size)))# define CLICK_LFREE(p, size)	(click_lfree((p), (size)))extern "C" {void *click_lalloc(size_t size);void click_lfree(volatile void *p, size_t size);}#else# define CLICK_LALLOC(size)	((void *)(new uint8_t[(size)]))# define CLICK_LFREE(p, size)	delete[] ((uint8_t *)(p))#endif// RANDOMNESSCLICK_DECLS/** @brief Return a number between 0 and CLICK_RAND_MAX, inclusive. * * CLICK_RAND_MAX is guaranteed to be at least 2^31 - 1. */uint32_t click_random();/** @brief Return a number between @a low and @a high, inclusive. * * Returns @a low if @a low >= @a high. */uint32_t click_random(uint32_t low, uint32_t high);/** @brief Set the click_random() seed to @a seed. */void click_srandom(uint32_t seed);/** @brief Set the click_random() seed using a source of true randomness, * if available. */void click_random_srandom();#if CLICK_BSDMODULE# define CLICK_RAND_MAX 0x7FFFFFFFU#elif !CLICK_LINUXMODULE && RAND_MAX >= 0x7FFFFFFFU# define CLICK_RAND_MAX RAND_MAX#else# define CLICK_RAND_MAX 0x7FFFFFFFUextern uint32_t click_random_seed;#endifinline uint32_t click_random() {#if CLICK_BSDMODULE    return random();#elif CLICK_LINUXMODULE    click_random_seed = click_random_seed * 69069L + 5;    return (click_random_seed ^ jiffies) & CLICK_RAND_MAX; // XXX jiffies??#elif HAVE_RANDOM && CLICK_RAND_MAX == RAND_MAX    return random();#else    return rand();#endif}inline void click_srandom(uint32_t seed) {#if CLICK_BSDMODULE    srandom(seed);#elif !CLICK_LINUXMODULE && HAVE_RANDOM && CLICK_RAND_MAX == RAND_MAX    srandom(seed);#elif !CLICK_LINUXMODULE && CLICK_RAND_MAX == RAND_MAX    srand(seed);#else    click_random_seed = seed;#endif}CLICK_ENDDECLS// SORTING/** @brief Sort array of elements according to @a compar. * @param base pointer to array of elements * @param n number of elements in @a param * @param size size of an element * @param compar comparison function * @param user_data user data for comparison function * * Sorts an array of elements.  The comparison function is called as "@a * param(@i a, @i b, @a user_data)", where @i a and @i b are pointers into the * array starting at @a base, and @a user_data is click_qsort's @a user_data * parameter.  The function should return an integer less than zero, equal to * zero, or greater than zero depending on whether @i a compares less than @i * b, equal to @i b, or greater than @i b, respectively.  On return the * elements in the @a param array have been reordered into strictly increasing * order.  The function always returns 0. * * Click_qsort() is not a stable sort. * * @warning click_qsort() shuffles elements by swapping memory, rather than by * calling copy constructors or swap().  It is thus not safe for all types. * In particular, objects like Bitvector that maintain pointers into their own * representations are not safe to sort with click_qsort().  Conservatively, * it is safe to sort fundamental data types (like int and pointers), plain * old data types, and simple objects.  It is also safe to sort String and * StringAccum objects, and to sort Vector objects that contain objects * that are safe to sort themselves. * * @note The implementation is based closely on "Engineering a Sort Function," * Jon L. Bentley and M. Douglas McIlroy, <em>Software---Practice & * Experience</em>, 23(11), 1249-1265, Nov. 1993.  It has been coded * iteratively rather than recursively, and does no dynamic memory allocation, * so it will not exhaust stack space in the kernel. */int click_qsort(void *base, size_t n, size_t size,		int (*compar)(const void *a, const void *b, void *user_data),		void *user_data = 0);/** @brief Sort array of elements according to @a compar. * @param base pointer to array of elements * @param n number of elements in @a param * @param size size of an element * @param compar comparison function * * @deprecated Prefer the variant where @a compar takes an extra void * *user_data argument.  This variant depends on a nonstandard function * pointer cast. */int click_qsort(void *base, size_t n, size_t size,		int (*compar)(const void *a, const void *b)) CLICK_DEPRECATED;/** @brief Generic comparison function useful for click_qsort. * * Compares @a a and @a b using operator<(). */template <typename T> int click_compare(const void *a, const void *b, void *){    const T *ta = static_cast<const T *>(a);    const T *tb = static_cast<const T *>(b);    return (*ta < *tb ? -1 : (*tb < *ta ? 1 : 0));}/** @brief Sort array of elements using operator<(). */template <typename T> int click_qsort(T *base, size_t n){    return click_qsort(base, n, sizeof(T), &click_compare<T>);}// OTHER#if CLICK_LINUXMODULEextern "C" {long strtol(const char *, char **, int);inline unsigned longstrtoul(const char *nptr, char **endptr, int base){    return simple_strtoul(nptr, endptr, base);}# if __GNUC__ == 2 && __GNUC_MINOR__ == 96int click_strcmp(const char *, const char *);inline intstrcmp(const char *a, const char *b){    return click_strcmp(a, b);}# endif}#elif CLICK_BSDMODULE/* Char-type glue */# define _U	0x01	/* upper */# define _L	0x02	/* lower */# define _D	0x04	/* digit */# define _C	0x08	/* cntrl */# define _P	0x10	/* punct */# define _S	0x20	/* white space (space/lf/tab) */# define _X	0x40	/* hex digit */# define _SP	0x80	/* hard space (0x20) */extern unsigned char _ctype[];# define __ismask(x)	(_ctype[(int)(unsigned char)(x)])# define isalnum(c)	((__ismask(c)&(_U|_L|_D)) != 0)# define strchr(s, c)	index(s, c)# define memmove(dst, src, len)		bcopy((src), (dst), (len))typedef struct ifnet net_device;#else /* not CLICK_LINUXMODULE || CLICK_BSDMODULE */// provide a definition for net_devicetypedef struct device net_device;#endif /* CLICK_LINUXMODULE */// COMPILE-TIME ASSERTION CHECKING#define static_assert(x) switch (x) case 0: case !!(x):// PROCESSOR IDENTITIES#if CLICK_LINUXMODULEtypedef uint32_t click_processor_t;#elif CLICK_USERLEVEL && HAVE_MULTITHREAD

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -