From b7fd7219ce4fc73939c912d4a02f5b8e4301ede7 Mon Sep 17 00:00:00 2001 From: Johann Latocha Date: Thu, 19 Jan 2012 17:20:02 +0100 Subject: First working version :) --- src/client/client.bak | 75 --------------------------------------------------- src/client/client.c | 22 ++++++++++++++- 2 files changed, 21 insertions(+), 76 deletions(-) delete mode 100644 src/client/client.bak (limited to 'src/client') diff --git a/src/client/client.bak b/src/client/client.bak deleted file mode 100644 index bacfa52..0000000 --- a/src/client/client.bak +++ /dev/null @@ -1,75 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "../include/types.h" - -#define FILE_SIZE 721127424 - -int main(int argc, char *argv[]) -{ - struct sockaddr_in server; - unsigned long addr; - int sock; - - // Create socket - sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); - if (sock < 0) - { - printf("ERROR: Socket failure\n"); - return EXIT_FAILURE; - } - - addr = inet_addr(HOST); - memcpy((char *) &server.sin_addr, &addr, sizeof(addr)); - server.sin_family = AF_INET; // IPv4 - server.sin_port = htons(PORT); // set port number - - // Connect to server - if (connect(sock, (struct sockaddr*) &server, sizeof(server)) < 0) - { - printf("ERROR: Connect failure\n"); - return EXIT_FAILURE; - } - - // Set data - struct dnbd3_request request; - struct dnbd3_reply reply; - request.num = 0; - - // Send to server - int i; - off_t blocks = FILE_SIZE / DNBD3_BLOCK_SIZE; - int e = log(DNBD3_BLOCK_SIZE) / log(2); // logarithmus dualis - - - for (i = 0; i < blocks; i++) - { - request.num = i << e; // multiplie by e - send(sock, (char *) &request, sizeof(request), 0); - recv(sock, &reply, DNBD3_BLOCK_SIZE, MSG_WAITALL); - write(STDOUT_FILENO, reply.data, DNBD3_BLOCK_SIZE); - } - - /* Fetch "rest" bytes */ - int rest = FILE_SIZE % DNBD3_BLOCK_SIZE; - if (rest != 0) - { - request.num = i * DNBD3_BLOCK_SIZE; - send(sock, (char *) &request, sizeof(request), 0); - recv(sock, &reply, sizeof(struct dnbd3_reply), MSG_WAITALL); - write(STDOUT_FILENO, reply.data, rest); - } - - close(sock); - return EXIT_SUCCESS; -} diff --git a/src/client/client.c b/src/client/client.c index 87f20d5..68b7f5c 100644 --- a/src/client/client.c +++ b/src/client/client.c @@ -1,3 +1,23 @@ +/* + * This file is part of the Distributed Network Block Device 3 + * + * Copyright(c) 2011-2012 Johann Latocha + * + * This file may be licensed under the terms of of the + * GNU General Public License Version 2 (the ``GPL''). + * + * Software distributed under the License is distributed + * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either + * express or implied. See the GPL for the specific language + * governing rights and limitations. + * + * You should have received a copy of the GPL along with this + * program. If not, go to http://www.gnu.org/licenses/gpl.html + * or write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + #include #include #include @@ -6,7 +26,7 @@ #include #include -#include "../include/types.h" +#include "../types.h" #include "../version.h" void print_help(char* argv_0) -- cgit v1.2.3-55-g7522