Main Page | Modules | Class List | Directories | File List | Class Members | File Members | Related Pages

addr.h

Go to the documentation of this file.
00001 /*
00002  * addr.h
00003  *
00004  * Network address operations.
00005  *
00006  * Copyright (c) 2000 Dug Song <dugsong@monkey.org>
00007  *
00008  * $Id: addr.h,v 1.12 2003/02/27 03:44:55 dugsong Exp $
00009  */
00010 
00011 #ifndef DNET_ADDR_H
00012 #define DNET_ADDR_H
00013 
00014 #define ADDR_TYPE_NONE          0       /* No address set */
00015 #define ADDR_TYPE_ETH           1       /* Ethernet */
00016 #define ADDR_TYPE_IP            2       /* Internet Protocol v4 */
00017 #define ADDR_TYPE_IP6           3       /* Internet Protocol v6 */
00018 
00019 struct addr {
00020         uint16_t                addr_type;
00021         uint16_t                addr_bits;
00022         union {
00023                 eth_addr_t      __eth;
00024                 ip_addr_t       __ip;
00025                 ip6_addr_t      __ip6;
00026                 
00027                 uint8_t         __data8[16];
00028                 uint16_t        __data16[8];
00029                 uint32_t        __data32[4];
00030         } __addr_u;
00031 };
00032 #define addr_eth        __addr_u.__eth
00033 #define addr_ip         __addr_u.__ip
00034 #define addr_ip6        __addr_u.__ip6
00035 #define addr_data8      __addr_u.__data8
00036 #define addr_data16     __addr_u.__data16
00037 #define addr_data32     __addr_u.__data32
00038 
00039 #define addr_pack(addr, type, bits, data, len) do {     \
00040         (addr)->addr_type = type;                       \
00041         (addr)->addr_bits = bits;                       \
00042         memmove((addr)->addr_data8, (char *)data, len); \
00043 } while (0)
00044 
00045 __BEGIN_DECLS
00046 int      addr_cmp(const struct addr *a, const struct addr *b);
00047 
00048 int      addr_bcast(const struct addr *a, struct addr *b);
00049 int      addr_net(const struct addr *a, struct addr *b);
00050 
00051 char    *addr_ntop(const struct addr *src, char *dst, size_t size);
00052 int      addr_pton(const char *src, struct addr *dst);
00053 
00054 char    *addr_ntoa(const struct addr *a);
00055 #define  addr_aton      addr_pton
00056 
00057 int      addr_ntos(const struct addr *a, struct sockaddr *sa);
00058 int      addr_ston(const struct sockaddr *sa, struct addr *a);
00059 
00060 int      addr_btos(uint16_t bits, struct sockaddr *sa);
00061 int      addr_stob(const struct sockaddr *sa, uint16_t *bits);
00062 
00063 int      addr_btom(uint16_t bits, void *mask, size_t size);
00064 int      addr_mtob(const void *mask, size_t size, uint16_t *bits);
00065 __END_DECLS
00066 
00067 #endif /* DNET_ADDR_H */

Generated on Sun May 14 14:51:10 2006 by  doxygen 1.4.2