network.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. //
  2. // Created by janco on 25-2-16.
  3. //
  4. #include <dev/board.h>
  5. #include <dev/debug.h>
  6. #include <sys/timer.h>
  7. #include <sys/confnet.h>
  8. #include <sys/socket.h>
  9. #include <stdlib.h>
  10. #include <string.h>
  11. #include <time.h>
  12. #include <net/route.h>
  13. #include <dev/nicrtl.h>
  14. #include <stdio.h>
  15. #include <io.h>
  16. #include <arpa/inet.h>
  17. #include <pro/dhcp.h>
  18. #include <pro/sntp.h>
  19. #include "network.h"
  20. #include "ntp.h"
  21. void NetworkInit() {
  22. /* Register de internet controller. */
  23. if (NutRegisterDevice(&DEV_ETHER, 0, 0)) {
  24. printf("Registering failed.");
  25. }/* Netwerk configureren op dhcp */
  26. else if (NutDhcpIfConfig(DEV_ETHER_NAME, NULL, 0)) {
  27. /* Done. */
  28. }else {
  29. printf("Ik heb een internet connectie. Ip is: %s", inet_ntoa(confnet.cdn_ip_addr));
  30. }
  31. }
  32. void httpGet(){
  33. TCPSOCKET* sock = NutTcpCreateSocket();
  34. char http[] = "GET /Projecten/projectgroepa6/internetradio/gettimezone.php HTTP/1.1\r\nHost: jancokock.me \r\n\r\n";
  35. char buffer = (char *) malloc(8);
  36. int len = sizeof(http);
  37. if (NutTcpConnect(sock, inet_addr("62.195.226.247"), 80)) {
  38. printf("Can't connect to sever\n");
  39. }else{
  40. FILE *stream;
  41. stream = _fdopen((int) sock, "r b");
  42. if(NutTcpSend(sock, http, len) != len){
  43. printf("Writing headers failed.");
  44. }else{
  45. printf("Headers writed. Now reading.");
  46. NutTcpReceive(sock, buffer, sizeof(buffer));
  47. //fread(buffer, 1, sizeof(buffer), stream);
  48. NutDelay(1000);
  49. printf("buffer: %s", buffer);
  50. };
  51. fclose(stream);
  52. }
  53. NutTcpCloseSocket(sock);
  54. }