123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- /* 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>
- #define BUF 1024
- int myco_network_fetch_resource(void *local_pointer, pid_t local_pid, int resource_size) {
- printf("\nTransferring data over network!\n");
- int port = 15001;
- int create_socket, new_socket;
- socklen_t addrlen;
- char *buffer = malloc (BUF);
- ssize_t size;
- struct sockaddr_in address;
- const int y = 1;
- char *command;
- char *agent;
- char *resource;
- 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 (port);
- if (bind ( create_socket,
- (struct sockaddr *) &address,
- sizeof (address)) != 0) {
- printf( "Port already taken!\n");
- }
- listen (create_socket, 5);
- addrlen = sizeof (struct sockaddr_in);
- while (1) {
- new_socket = accept (create_socket, (struct sockaddr *) &address, &addrlen);
- printf("DEBUG\n");
- if (new_socket > 0)
- inet_ntoa (address.sin_addr);
- do {
- size = recv (new_socket, buffer, BUF-1, 0);
- if( size > 0)
- buffer[size] = '\0';
- printf ("DEBUG: %s\n", buffer);
- } while (strcmp (buffer, "quit\n") != 0);
- close (new_socket);
- }
- close (create_socket);
- /*
- // 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;
- }
|