socket.c 857 B

12345678910111213141516171819202122232425262728293031
  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_dryrun_socket(void)
  14. {
  15. // we need a socket in order to gather details about the system
  16. // such as source MAC address and IP address. However, because
  17. // we don't want to require root access in order to run dryrun,
  18. // we just create a TCP socket.
  19. int sock = socket(AF_INET, SOCK_STREAM, 0);
  20. if (sock <= 0) {
  21. log_fatal("send", "couldn't create socket. Error: %s\n",
  22. strerror(errno));
  23. }
  24. sock_t s;
  25. s.sock = sock;
  26. return s;
  27. }