Building.Open.Source.Network.Security.Tools.Components.And.Techniques [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Building.Open.Source.Network.Security.Tools.Components.And.Techniques [Electronic resources] - نسخه متنی

Mike D. Schiffman

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید







Addressing Functions

Consisting mainly of conversion routines, libdnet provides a rich subset of network address manipulation functions. For simplicity's sake, libdnet specifies and uses its own native address format for most operations: struct addr. We further describe this format in the datatypes section. At this writing, libdnet has support for only two address types (addr_type), which we show in Table 6.1.








































Table 6.1: libdnet Address Types

CONSTANT


MEANING





ADDR_TYPE_NONE


No address set





ADDR_TYPE_ETH


48-bit Ethernet address





ADDR_TYPE_IP


32-bit IPv4 address









int addr_cmp (const struct addr *a, const struct addr *b);


addr_cmp() compares the address that a points to with the address to which b points. If they are identical, the function returns 0. If a differs from b, the function returns a positive or negative integer denoting the difference in bits. Ostensibly, this function does not fail, but the addr_type of both addresses must be the same for it to work properly.



int addr_bcast(const struct addr *a, struct addr *b);


addr_bcast() determines the broadcast address for the network specified in a and writes it to b. Upon success, the function returns 0; upon failure (if the address in a is not a supported type), the function returns −1 and sets errno.



int addr_ntop(const struct addr *src, char *dst, size_t size);


addr_ntop() converts a network address in src to its numerical presentation format ("10.0.0.1") and writes it in dst, which should be a pointer to a character buffer of size bytes. No address-to-name resolution is performed. To be large enough to hold all of the data, Ethernet addresses should have a size of at least 18 bytes (up to 17 characters to contain the presentation format of the address and one NULL byte). For IP addresses, the size should be at least 16 bytes (up to 15 characters to contain the presentation format of the address and one NULL byte). Upon success, the function returns 0; upon failure (if the address in src is not a supported type or the buffer size is too small), the function returns −1 and sets errno.



int addr_pton(const char *src, struct addr *dst);


addr_pton() converts a presentation format address in src to libdnetstyle addr and writes it to dst. This function might call inet_pton() internally, which might incur a DNS or YP lookup. Upon success, the function returns 0; upon failure, the function returns −1 and sets errno.



int addr_aton(const char *src, struct addr *dst);


addr_aton() is the same function as addr_pton().



char *addr_ntoa(const struct addr *a);


addr_ntoa() converts the libdnet address in a and returns a pointer to the presentation format string. This function actually is a wrapper to addr_ntop() with a static internal buffer. Upon success, the function returns a pointer to the converted address; upon failure (if addr_ntop() fails), the function returns NULL.



int addr_ntos(const struct addr *a, struct sockaddr *sa);


addr_ntos() converts the libdnet address in a to the appropriate sock-addr type and writes it to sa. Upon success, the function returns 0; upon failure, the function returns −1 and sets errno.



int addr_ston(const struct sockaddr *sa, struct addr *a);


addr_ston() converts a sockaddr format address in sa to a libdnet format address and writes it to a. Upon success, the function returns 0; upon failure, the function returns −1 and sets errno.



int addr_btom(uint16_t bits, void *mask, size_t size);


addr_btom() converts the netmask length in bits to a netmask and writes it to mask, which should be at least size bytes. The function returns 0.



int addr_mtob(const void *mask, size_t size, uint16_t *bits);


addr_mtob() determines the size in bits of a network byte-ordered net-mask mask of size size and writes it to bits. The function returns 0.



int addr_btos(uint16_t bits, struct sockaddr *sa);


addr_btos() converts the netmask length in bits to a netmask, as specified by sa. The function returns 0.



int addr_stob(const struct sockaddr *sa, uint16_t *bits);


addr_stob() determines the size in bits of a netmask specified by sa and writes it to bits. The function returns 0.

/ 135