Cleanup in elf.c with .bss section clean; adm command mounts cdrom instead of floppy...
[ZeXOS.git] / apps / webcl / net.c
blobf4c117cb3123634bc15dba4642f8e6c432212e67
1 /*
2 * ZeX/OS
3 * Copyright (C) 2008 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
4 * Copyright (C) 2009 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include <fcntl.h>
22 #include <netdb.h>
23 #include <stdio.h>
24 #include <string.h>
25 #include <stdlib.h>
26 #include <unistd.h>
27 #include <arpa/inet.h>
28 #include <netinet/in.h>
29 #include <sys/socket.h>
31 #define ESC 1
33 int sock;
35 static struct sockaddr_in serverSock; // Remote socket
36 static struct hostent *host; // Remote host
38 extern int http_request (char *address, unsigned address_len, char *dir, unsigned dir_len);
40 int init (char *address)
42 // Let's get info about remote computer
43 if ((host = gethostbyname ((char *) address)) == NULL) {
44 //printf ("Wrong address -> %s:%d\n", addr, port);
45 printf ("Wrong address\n");
46 return 0;
49 // Create socket
50 if ((sock = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP)) == -1) {
51 printf ("Cant create socket\n");
52 return 0;
55 // Fill structure sockaddr_in
56 // 1) Family of protocols
57 serverSock.sin_family = AF_INET;
58 // 2) Number of server port
59 serverSock.sin_port = htons (80);
60 // 3) Setup ip address of server, where we want to connect
61 memcpy (&(serverSock.sin_addr), host->h_addr, host->h_length);
63 // Now we are able to connect to remote server
64 if (connect (sock, (struct sockaddr *) &serverSock, sizeof (serverSock)) == -1) {
65 printf ("Connection cant be estabilished -> %s:%d\n", address, 80);
66 return -1;
69 printf ("webcl -> connected to %s:80 server\n", address);
71 return http_request (address, strlen (address), "/", 1);
74 int loop ()
77 return 1;