`libnetdude` Manual
Prev |  | Next

# libnd_misc

## Name

libnd_misc --

## Synopsis

    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);

## Description

## Details

### libnd_misc_writen ()

    guint       libnd_misc_writen               (int fd,
                                                 const guchar *data,
                                                 guint size);

The function tries to write n buffers to the given file descriptor.

`fd` :

  file descriptor

`data` :

  data buffer

`size` :

  size of buffer

Returns :

  number of bytes written, or value < 0 on error.

### libnd_misc_readn ()

    guint       libnd_misc_readn                (int fd,
                                                 guchar *data,
                                                 guint size);

The function tries to read n buffers from the given file descriptor.

`fd` :

  file descriptor

`data` :

  data buffer

`size` :

  size of buffer

Returns :

  number of bytes read, or value < 0 on error.

### libnd_misc_readline ()

    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.

`fd` :

  file descriptor

`data` :

  data buffer

`size` :

  size of buffer

Returns :

  number of bytes read.

### libnd_misc_ones_complement_checksum ()

    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`.

`data` :

  pointer to data to checksum.

`data_len` :

  length of `data`.

`sum` :

  pre-added input.

Returns :

  checksum.

### libnd_misc_in_cksum ()

    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`.

`addr` :

  data to checksum.

`addr_len` :

  length of `addr` data.

`preadd` :

  pre-added input.

Returns :

  checksum.

### libnd_misc_exists ()

    gboolean    libnd_misc_exists               (const char *filename);

The function checks whether `filename` exists and returns the result.

`filename` :

  name of file.

Returns :

  TRUE when `filename` exists, FALSE otherwise.

### libnd_misc_can_read ()

    gboolean    libnd_misc_can_read             (const char *filename);

The function checks whether `filename` can be read and returns the result.

`filename` :

  name of file.

Returns :

  TRUE if file is readable, FALSE if it is not or if there is another error (such as `filename` doesn't exist).

### libnd_misc_can_write ()

    gboolean    libnd_misc_can_write            (const char *filename);

The function checks whether `filename` can be written to and returns the result.

`filename` :

  name of file.

Returns :

  TRUE if file is writeable, FALSE if it is not or if there is another error (such as `filename` doesn't exist).

### libnd_misc_is_tcpdump_file ()

    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.

`filename` :

  name of file.

Returns :

  TRUE if test was positive, FALSE otherwise or if there was an error.

### libnd_misc_can_exec ()

    gboolean    libnd_misc_can_exec             (const char *filename);

The function checks whether `filename` can be executed and returns the result.

`filename` :

  name of file.

Returns :

  TRUE if file is executable, FALSE if it is not or if there is another error (such as `filename` doesn't exist).

### libnd_misc_is_dir ()

    gboolean    libnd_misc_is_dir               (const char *filename);

The function checks whether `filename` is a directory and returns the result.

`filename` :

  name of file.

Returns :

  TRUE if file is a directory, FALSE if it is not or if there is another error (such as `filename` doesn't exist).

### libnd_misc_int_cmp ()

    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.

`int1` :

  pointer using integer value.

`int2` :

  pointer using integer value.

Returns :

  comparison result.

### libnd_misc_add_slash ()

    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` :

  filename to test.

Returns :

  resulting string.

### libnd_misc_get_if_names ()

    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` :

  flags the interface must have set (IFF_xxx values, see net/if.h).

Returns :

  list of strings. You need to free this list and its entries if you don't need the result any more.

### libnd_misc_get_if_mtu ()

    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 ...

`ifname` :

  name of interface to query.

Returns :

### libnd_misc_get_hardware_string ()

    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".

`str` :

  pointer to space filled with string.

`str_len` :

  available string length.

`address` :

  hardware address data.

`addr_len` :

  length of hardware address in bytes.

### libnd_misc_get_unnamed_string ()

    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()` the pointer if you want to keep it around.

Returns :

  new filename.

### libnd_misc_timeval_to_string ()

    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".

`tv` :

  timeval to print string for.

Returns :

  ASCII version of time interval `tv`.

### libnd_misc_memdup ()

    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.

`data` :

  input data.

`data_len` :

  number of bytes to copy.

Returns :

  new memory chunk, or NULL if allocation failed.

### libnd_misc_ctime ()

    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.

`tv` :

  timestamp to convert.

`buf` :

  buffer to hold result.

`buflen` :

  length of `buf` in bytes.

`fix_gmt` :

  whether to keep time local or make it relative to GMT.

`add_usec` :

  whether to include the microseconds of `tv` in the output.

### libnd_misc_get_gmt_deviation ()

    int         libnd_misc_get_gmt_deviation    (void);

The function returns the number of seconds our local time deviates from GMT.

Returns :

  deviation in seconds.

### libnd_misc_get_tmpfile ()

    char*       libnd_misc_get_tmpfile          (const char *filename);

`filename` :

Returns :

Prev | Home | Next
libnd_macros | Up | libnd_null_protocol