diff options
author | Johann Latocha | 2012-01-19 17:20:02 +0100 |
---|---|---|
committer | Johann Latocha | 2012-01-19 17:20:02 +0100 |
commit | b7fd7219ce4fc73939c912d4a02f5b8e4301ede7 (patch) | |
tree | 4a36476deebc1b7c66c459472a6b0183eaff3b47 /src/client | |
parent | initial commit (diff) | |
download | dnbd3-b7fd7219ce4fc73939c912d4a02f5b8e4301ede7.tar.gz dnbd3-b7fd7219ce4fc73939c912d4a02f5b8e4301ede7.tar.xz dnbd3-b7fd7219ce4fc73939c912d4a02f5b8e4301ede7.zip |
First working version :)
Diffstat (limited to 'src/client')
-rw-r--r-- | src/client/client.bak | 75 | ||||
-rw-r--r-- | src/client/client.c | 22 |
2 files changed, 21 insertions, 76 deletions
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 <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <errno.h> -#include <sys/types.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <netdb.h> -#include <arpa/inet.h> -#include <unistd.h> - -#include <math.h> - -#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 <johann@latocha.de> + * + * 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 <stdio.h> #include <stdlib.h> #include <fcntl.h> @@ -6,7 +26,7 @@ #include <sys/ioctl.h> #include <netinet/in.h> -#include "../include/types.h" +#include "../types.h" #include "../version.h" void print_help(char* argv_0) |