guint libnd_misc_writen (int fd, const guchar *data, guint size); guint libnd_misc_readn (int fd, guchar *data, guint size); guint libnd_misc_readline (int fd, guchar *data, guint size); int libnd_misc_ones_complement_checksum (const void *data, int data_len, u_int32_t sum); u_short libnd_misc_in_cksum (u_short *addr, int addr_len, u_int preadd); gboolean libnd_misc_exists (const char *filename); gboolean libnd_misc_can_read (const char *filename); gboolean libnd_misc_can_write (const char *filename); gboolean libnd_misc_is_tcpdump_file (const char *filename); gboolean libnd_misc_can_exec (const char *filename); gboolean libnd_misc_is_dir (const char *filename); gint libnd_misc_int_cmp (gconstpointer int1, gconstpointer int2); char* libnd_misc_add_slash (char *filename); GList* libnd_misc_get_if_names (int flags); int libnd_misc_get_if_mtu (const char *ifname); void libnd_misc_get_hardware_string (char *str, guint str_len, guchar *address, guint addr_len); char* libnd_misc_get_unnamed_string (void); char* libnd_misc_timeval_to_string (struct bpf_timeval *tv); guchar* libnd_misc_memdup (const guchar *data, guint data_len); void libnd_misc_ctime (const struct bpf_timeval *tv, char *buf, int buflen, gboolean fix_gmt, gboolean add_usec); int libnd_misc_get_gmt_deviation (void); char* libnd_misc_get_tmpfile (const char *filename); |
guint libnd_misc_writen (int fd, const guchar *data, guint size); |
The function tries to write n buffers to the given file descriptor.
file descriptor
data buffer
size of buffer
number of bytes written, or value < 0 on error.
guint libnd_misc_readn (int fd, guchar *data, guint size); |
The function tries to read n buffers from the given file descriptor.
file descriptor
data buffer
size of buffer
number of bytes read, or value < 0 on error.
guint libnd_misc_readline (int fd, guchar *data, guint size); |
The function reads from a file descriptor until a newline is encountered. WARNING -- this function can BLOCK.
file descriptor
data buffer
size of buffer
number of bytes read.
int libnd_misc_ones_complement_checksum (const void *data, int data_len, u_int32_t sum); |
The function computes the ones-complement checksum of the data pointed to by data. If you want to extend the checksum over data areas not included in data, you can pre-add the sum of that data in units of short ints (16bit) and pass it as sum.
pointer to data to checksum.
length of data.
pre-added input.
checksum.
u_short libnd_misc_in_cksum (u_short *addr, int addr_len, u_int preadd); |
The function computes the Internet checksum of addr. Other data can be included in the checksum by pre-added the sum if that data in units of short ints (16bit) and passing it as preadd.
data to checksum.
length of addr data.
pre-added input.
checksum.
gboolean libnd_misc_exists (const char *filename); |
The function checks whether filename exists and returns the result.
name of file.
TRUE when filename exists, FALSE otherwise.
gboolean libnd_misc_can_read (const char *filename); |
The function checks whether filename can be read and returns the result.
name of file.
TRUE if file is readable, FALSE if it is not or if there is another error (such as filename doesn't exist).
gboolean libnd_misc_can_write (const char *filename); |
The function checks whether filename can be written to and returns the result.
name of file.
TRUE if file is writeable, FALSE if it is not or if there is another error (such as filename doesn't exist).
gboolean libnd_misc_is_tcpdump_file (const char *filename); |
The function checks whether filename is a tcpdump savefile by looking for tcpdump's magic 0xa1b2c3d4 and its variations.
name of file.
TRUE if test was positive, FALSE otherwise or if there was an error.
gboolean libnd_misc_can_exec (const char *filename); |
The function checks whether filename can be executed and returns the result.
name of file.
TRUE if file is executable, FALSE if it is not or if there is another error (such as filename doesn't exist).
gboolean libnd_misc_is_dir (const char *filename); |
The function checks whether filename is a directory and returns the result.
name of file.
TRUE if file is a directory, FALSE if it is not or if there is another error (such as filename doesn't exist).
gint libnd_misc_int_cmp (gconstpointer int1, gconstpointer int2); |
This is a simple compare function for pointers that can be casted (not dereferenced!) to ints, returning -1/0/1 of row1 is smaller/ equal/larger than row2. The signature allows usage with various glib functions.
pointer using integer value.
pointer using integer value.
comparison result.
char* libnd_misc_add_slash (char *filename); |
The function checks if filename ends with a slash and if not, reallocs the memory filename uses and appends a slash.
filename to test.
resulting string.
GList* libnd_misc_get_if_names (int flags); |
The function returns an alphabetically ordered glib list of strings containing the names of those network interfaces that satisfy the given flag combination.
flags the interface must have set (IFF_xxx values, see net/if.h).
list of strings. You need to free this list and its entries if you don't need the result any more.
int libnd_misc_get_if_mtu (const char *ifname); |
The function returns the MTU for a given interface. I have no idea whether this compiles on anything non-Linux ...
name of interface to query.
void libnd_misc_get_hardware_string (char *str, guint str_len, guchar *address, guint addr_len); |
The function places into the space pointed to by str a string representing the hardware address as "xx : xx : ... : xx".
pointer to space filled with string.
available string length.
hardware address data.
length of hardware address in bytes.
char* libnd_misc_get_unnamed_string (void); |
The function returns a pointer to statically allocated data
that gets filled with a numbered dummy file name. You need
to strdup()
new filename.
char* libnd_misc_timeval_to_string (struct bpf_timeval *tv); |
The function returns a static string representing tv as a time interval in the form of, for example, "2 days, 15:26:32:978560".
timeval to print string for.
ASCII version of time interval tv.
guchar* libnd_misc_memdup (const guchar *data, guint data_len); |
The function allocates a chunk of memory of size data_len, and then copies data_len bytes over from data into the newly allocated memory region.
input data.
number of bytes to copy.
new memory chunk, or NULL if allocation failed.
void libnd_misc_ctime (const struct bpf_timeval *tv, char *buf, int buflen, gboolean fix_gmt, gboolean add_usec); |
The function is similar to ctime_r(3). fix_gmt includes the local divergence from GMT, and add_usec includes the microseconds in the timestamp.
timestamp to convert.
buffer to hold result.
length of buf in bytes.
whether to keep time local or make it relative to GMT.
whether to include the microseconds of tv in the output.
int libnd_misc_get_gmt_deviation (void); |
The function returns the number of seconds our local time deviates from GMT.
deviation in seconds.