socket-linux.c 668 B

123456789101112131415161718192021222324252627
  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. #include "socket.h"
  9. #include <string.h>
  10. #include <errno.h>
  11. #include "../lib/includes.h"
  12. #include "../lib/logger.h"
  13. sock_t get_socket(UNUSED uint32_t id)
  14. {
  15. int sock = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
  16. if (sock <= 0) {
  17. log_fatal("send", "couldn't create socket. "
  18. "Are you root? Error: %s\n", strerror(errno));
  19. }
  20. sock_t s;
  21. s.sock = sock;
  22. return s;
  23. }