Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00047 #include <dev/board.h>
00048
00049 #include <dev/urom.h>
00050
00051 #include <sys/version.h>
00052 #include <sys/timer.h>
00053 #include <sys/confnet.h>
00054 #include <sys/socket.h>
00055
00056 #include <arpa/inet.h>
00057
00058 #include <pro/dhcp.h>
00059 #include <pro/httpd.h>
00060
00061 #include <io.h>
00062 #include <errno.h>
00063
00069 int main(void)
00070 {
00071 uint32_t baud = 115200;
00072 TCPSOCKET *sock;
00073 FILE *stream;
00074
00075
00076
00077
00078 NutRegisterDevice(&DEV_CONSOLE, 0, 0);
00079 freopen(DEV_CONSOLE_NAME, "w", stdout);
00080 _ioctl(_fileno(stdout), UART_SETSPEED, &baud);
00081
00082 printf("\n\nSimple HTTP Daemon running on Nut/OS %s\n",
00083 NutVersionString());
00084
00085
00086
00087
00088 printf("Configure %s...", DEV_ETHER_NAME);
00089 if (NutRegisterDevice(&DEV_ETHER, 0, 0)) {
00090 puts("failed. Cannot register Ethernet device.");
00091 for (;;);
00092 }
00093 if (NutDhcpIfConfig(DEV_ETHER_NAME, NULL, 60000)) {
00094 puts("failed. Cannot configure network.\nUse editconf.");
00095 for (;;);
00096 }
00097 printf("%s ready\n", inet_ntoa(confnet.cdn_ip_addr));
00098
00099
00100
00101
00102 printf("Register UROM file system...");
00103 if (NutRegisterDevice(&devUrom, 0, 0)) {
00104 puts("failed.");
00105 for (;;);
00106 }
00107 puts("OK.");
00108
00109
00110
00111
00112 for (;;) {
00113
00114 sock = NutTcpCreateSocket();
00115 if (sock == NULL) {
00116 printf("Error %d creating socket.\n", errno);
00117 NutSleep(1000);
00118 continue;
00119 }
00120
00121
00122
00123 printf("Listening...");
00124 NutTcpAccept(sock, 80);
00125 printf("Connected...");
00126
00127
00128 stream = _fdopen((int) ((uintptr_t) sock), "r+b");
00129 if (stream == NULL) {
00130 printf("Error %d creating stream.\n", errno);
00131 } else {
00132
00133
00134 NutHttpProcessRequest(stream);
00135
00136
00137 fclose(stream);
00138 }
00139
00140
00141 NutTcpCloseSocket(sock);
00142 puts("Disconnected");
00143 }
00144 return 0;
00145 }