123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- /* Copyright (C) 2016 Max Riechelmann <max.riechelmann@student.kit.edu>
- (Karlsruhe Institute of Technology)
- This library is free software; you can redistribute it and/or modify it
- under the terms of the GNU Lesser General Public License as published by the
- Free Software Foundation; either version 2.1 of the License, or (at your
- option) any later version.
- This library is distributed in the hope that it will be useful, but WITHOUT
- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
- details.
- You should have received a copy of the GNU Lesser General Public License along
- with this library; if not, write to the Free Software Foundation, Inc., 51
- Franklin St, Fifth Floor, Boston, MA 02110, USA
- */
- #include <sys/types.h>
- #include <sys/socket.h>
- #include <netinet/in.h>
- #include <arpa/inet.h>
- #include <unistd.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- // Request(local pointer, remote pointer, size)
- // make ping pong example
- myco_network_fetch_resource(void *local_pointer, pid_t local_pid, int size) {
- printf("\nTransferring data over network!\n");
- // Create local memory for transfer
- void *resource_pointer = malloc(size);
- // Create socket for transfer
- int create_socket, new_socket;
- socklen_t addrlen;
- char *buffer = malloc (size);
- //ssize_t size;
- struct sockaddr_in address;
- const int y = 1;
- char *command;
- char *agent;
- char *resource;
- printf ("\e[2J");
- create_socket=socket (AF_INET, SOCK_STREAM, 0);
- setsockopt( create_socket, SOL_SOCKET,
- SO_REUSEADDR, &y, sizeof(int));
- address.sin_family = AF_INET;
- address.sin_addr.s_addr = INADDR_ANY;
- address.sin_port = htons (15001);
- if (bind ( create_socket,
- (struct sockaddr *) &address,
- sizeof (address)) != 0) {
- printf( "Port already taken!\n");
- }
- listen (create_socket, 5);
- addrlen = sizeof (struct sockaddr_in);
-
- // Read memory over network
- // Write memory to Agent
- if (myco_write_memory(local_pid, local_pointer, size, (void *)resource_pointer, size) == -1) {
- printf("ERROR: %s\n", strerror(errno));
- return -1;
- }
- return 0;
- }
|