util.h 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #ifndef ZMAP_UTIL_H
  2. #define ZMAP_UTIL_H
  3. #include <stdio.h>
  4. #include <stdint.h>
  5. #include "types.h"
  6. int max_int(int a, int b);
  7. // Splits comma delimited string into char*[]. Does not handle
  8. // escaping or complicated setups - designed to process a set
  9. // of fields that the user wants output
  10. void split_string(char *in, int *len, char ***results);
  11. // Print a string using w length long lines, attempting to break on
  12. // spaces
  13. void fprintw(FILE *f, char *s, size_t w);
  14. // pretty print elapsed (or estimated) number of seconds
  15. void time_string(uint32_t time, int est, char *buf, size_t len);
  16. // pretty print quantities
  17. void number_string(uint32_t n, char *buf, size_t len);
  18. // Convert a string representation of a MAC address to a byte array
  19. int parse_mac(macaddr_t *out, char *in);
  20. int check_range(int v, int min, int max);
  21. int file_exists(char *name);
  22. // If running as root, drops priviledges to that of user "nobody".
  23. // Otherwise, does nothing.
  24. int drop_privs();
  25. // Set CPU affinity to a single core
  26. int set_cpu(uint32_t core);
  27. #endif /* ZMAP_UTIL_H */