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

This is a Digital Library

With over 100,000 free electronic resource in Persian, Arabic and English

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

Mike D. Schiffman

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

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

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







Binary Buffers

The binary buffer routines offer the application programmer a simple interface for manipulating arbitrary dynamic buffers (blobs) of data.



blob_t *blob_new (void);


blob_new() allocates a new dynamic buffer that is ready for use. The internal state for the buffer, which includes an offset variable, is initialized to 0 with a BUFSIZ number of bytes allocated. Note that BUFSIZ is a system-dependent, symbolic constant and is 1024 on some platforms (OpenBSD) and 8192 on others (Linux). This situation generally should not matter because the blob buffers will grow via realloc() as needed. Upon success, the function returns a valid blob_t handle pointer; upon failure, the function returns NULL.



int blob_read (blob_t *b, void *buf, int len);


blob_read() reads the len number of bytes from b and copies them into buf. Note that the number of bytes actually copied might be less than len if len is larger than the number of bytes left to be read from b. Upon success, the function returns the number of bytes copied; upon failure, the function returns 0 (still technically the number of bytes copied).



int blob_write (blob_t *b, const void *buf, int len);


blob_write() writes len bytes from buf into b and updates the internal current offset variable to reflect the write. Upon success, the function returns the number of bytes written; upon failure, the function returns -1.



int blob_seek (blob_t *b, int off, int whence);


blob_seek() repositions the offset to off in b according to the directive whence, which should be either SEEK_CUR or SEEK_END. If whence is SEEK_CUR, the offset is repositioned from its current location plus off. If whence is SEEK_END, however, it is repositioned from the end of the current buffer plus off. If repositioning results in the offset being less than 0 or greater than the current data buffer length, the function fails. Upon suc-cess, the function returns the new absolute offset; upon failure, the function returns -1.



int blob_index (blob_t *b, const void *buf, int len);


blob_index() returns the offset of the first occurrence of buf of size len in b. Upon success, the function returns the offset of buf; upon failure (buf is not found), the function returns -1.



int blob_rindex (blob_t *b, const void *buf, int len);


blob_index() returns the offset of the last occurrence of buf of size len in b. Upon success, the function returns the offset of buf; upon failure (buf is not found), the function returns -1.



int blob_pack (blob_t *b, const void *fmt, ...);


blob_pack() converts and writes data into b according to the format string specified by fmt. The format string fmt is a standard format string akin to what the printf() family of functions accepts. It should consist of zero or more format specifiers. These specifiers can be ordinary characters, which write to b verbatim, or a series of one or more conversion arguments that result in special formatting being applied to the string before copying to b. Table 6.5 summarizes the seven different conversion specifiers that blob_pack() supports.
































































Table 6.5: blob_pack() Format Conversion Specifiers


FLAG


MEANING





D


An unsigned 32-bit integer in network byte order





H


An unsigned 16-bit integer in network byte order





b


A binary buffer (length specifier required)





c


An unsigned character





d


An unsigned 32-bit integer in host byte order





h


An unsigned 16-bit integer in host byte order





s


A C-style null-terminated string







The character % introduces each conversion specification, the length specifier can also prefix it. Additionally, the arguments must correspond properly (after type promotion) with the length and conversion specifiers. The length specifier is either a decimal digit string specifying the length of the followingChapter 10.



int blob_unpack (blob_t *b, const void *fmt, ...);


blob_unpack() is identical to blob_pack() except that it reads data from b.



int blob_print (blob_t *b, char *style, int len);


blob_print() prints len bytes of the contents of b from the current offset to the end of the buffer by using the style that style specifies. At this writing, the only supported printing style is hexl, which prints the buffer in a typical hexadecimal format. The function does not fail and always returns 0.



blob_t *blob_free (blob_t *b);


blob_free() frees the memory associated with b. The function returns NULL.

/ 135