send-pfring.h 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. * ZMap Copyright 2013 Regents of the University of Michigan
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy
  6. * of the License at http://www.apache.org/licenses/LICENSE-2.0
  7. */
  8. #ifndef ZMAP_SEND_PFRING_H
  9. #define ZMAP_SEND_PFRING_H
  10. #include "../lib/includes.h"
  11. #include <sys/ioctl.h>
  12. #if defined(ZMAP_SEND_BSD_H) || defined(ZMAP_SEND_LINUX_H)
  13. #error "Don't include send-bsd.h or send-linux.h with send-pfring.h"
  14. #endif
  15. int send_run_init(sock_t socket)
  16. {
  17. (void) socket;
  18. // All init for pfring happens in get_socket
  19. return 0;
  20. }
  21. int send_packet(sock_t sock, void *buf, int len, uint32_t idx)
  22. {
  23. sock.pf.buffers[idx]->len = len;
  24. memcpy(sock.pf.buffers[idx]->data, buf, len);
  25. int ret;
  26. do {
  27. ret = pfring_zc_send_pkt(sock.pf.queue, &sock.pf.buffers[idx], 0);
  28. } while (ret < 0);
  29. return ret;
  30. }
  31. void send_finish(sock_t sock) {
  32. pfring_zc_sync_queue(sock.pf.queue, tx_only);
  33. }
  34. #endif /* ZMAP_SEND_PFRING_H */