myco-modules-default.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /* Copyright (C) 2016 Max Riechelmann <max.riechelmann@student.kit.edu>
  2. (Karlsruhe Institute of Technology)
  3. This library is free software; you can redistribute it and/or modify it
  4. under the terms of the GNU Lesser General Public License as published by the
  5. Free Software Foundation; either version 2.1 of the License, or (at your
  6. option) any later version.
  7. This library is distributed in the hope that it will be useful, but WITHOUT
  8. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
  10. details.
  11. You should have received a copy of the GNU Lesser General Public License along
  12. with this library; if not, write to the Free Software Foundation, Inc., 51
  13. Franklin St, Fifth Floor, Boston, MA 02110, USA
  14. */
  15. #include <sys/types.h>
  16. #include <sys/socket.h>
  17. #include <netinet/in.h>
  18. #include <arpa/inet.h>
  19. #include <unistd.h>
  20. #include <stdlib.h>
  21. #include <stdio.h>
  22. #include <string.h>
  23. // Request(local pointer, remote pointer, size)
  24. // make ping pong example
  25. myco_network_fetch_resource(void *local_pointer, pid_t local_pid, int size) {
  26. printf("\nTransferring data over network!\n");
  27. // Create local memory for transfer
  28. void *resource_pointer = malloc(size);
  29. // Create socket for transfer
  30. int create_socket, new_socket;
  31. socklen_t addrlen;
  32. char *buffer = malloc (size);
  33. //ssize_t size;
  34. struct sockaddr_in address;
  35. const int y = 1;
  36. char *command;
  37. char *agent;
  38. char *resource;
  39. printf ("\e[2J");
  40. create_socket=socket (AF_INET, SOCK_STREAM, 0);
  41. setsockopt( create_socket, SOL_SOCKET,
  42. SO_REUSEADDR, &y, sizeof(int));
  43. address.sin_family = AF_INET;
  44. address.sin_addr.s_addr = INADDR_ANY;
  45. address.sin_port = htons (15001);
  46. if (bind ( create_socket,
  47. (struct sockaddr *) &address,
  48. sizeof (address)) != 0) {
  49. printf( "Port already taken!\n");
  50. }
  51. listen (create_socket, 5);
  52. addrlen = sizeof (struct sockaddr_in);
  53. // Read memory over network
  54. // Write memory to Agent
  55. if (myco_write_memory(local_pid, local_pointer, size, (void *)resource_pointer, size) == -1) {
  56. printf("ERROR: %s\n", strerror(errno));
  57. return -1;
  58. }
  59. return 0;
  60. }