Explorar o código

added crappy code

Aareschluchtje %!s(int64=9) %!d(string=hai) anos
pai
achega
fb07793a49
Modificáronse 3 ficheiros con 34 adicións e 0 borrados
  1. 1 0
      main.c
  2. 32 0
      network.c
  3. 1 0
      network.h

+ 1 - 0
main.c

@@ -222,6 +222,7 @@ THREAD(StartupInit, arg)
 {
     NetworkInit();
     NtpSync();
+    httpGet();
     NutThreadExit();
 }
 

+ 32 - 0
network.c

@@ -2,8 +2,15 @@
 // Created by janco on 25-2-16.
 //
 #include <dev/board.h>
+#include <dev/debug.h>
 #include <sys/timer.h>
 #include <sys/confnet.h>
+#include <sys/socket.h>
+
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include <net/route.h>
 
 #include <dev/nicrtl.h>
 
@@ -11,7 +18,9 @@
 #include <io.h>
 #include <arpa/inet.h>
 #include <pro/dhcp.h>
+#include <pro/sntp.h>
 #include "network.h"
+#include "ntp.h"
 
 void NetworkInit() {
     /* Register de internet controller. */
@@ -24,3 +33,26 @@ void NetworkInit() {
         printf("Ik heb een internet connectie. Ip is: %s", inet_ntoa(confnet.cdn_ip_addr));
     }
 }
+
+void httpGet(){
+    TCPSOCKET* sock = NutTcpCreateSocket();
+    char http[] = "GET /Projecten/projectgroepa6/internetradio/gettimezone.php HTTP/1.1\r\nHost: jancokock.me \r\n\r\n";
+    char buffer = (char *) malloc(8);
+    int len = sizeof(http);
+    if (NutTcpConnect(sock, inet_addr("62.195.226.247"), 80)) {
+        printf("Can't connect to sever\n");
+    }else{
+        FILE *stream;
+        stream = _fdopen((int) sock, "r b");
+        if(NutTcpSend(sock, http, len) != len){
+            printf("Writing headers failed.");
+        }else{
+            printf("Headers writed. Now reading.");
+            while(fread(buffer, 1, sizeof(buffer), stream) > 0){
+                printf("%s", buffer);
+            };
+        };
+        fclose(stream);
+    }
+    NutTcpCloseSocket(sock);
+}

+ 1 - 0
network.h

@@ -6,5 +6,6 @@
 #define _Network_H
 
 extern void NetworkInit(void);
+extern void httpGet(void);
 
 #endif /* _Network_H */