Lab2_part4
Dependencies: EthernetInterface mbed-rtos mbed
Revision 1:c615a1ddf092, committed 2018-02-12
- Comitter:
- bjs9
- Date:
- Mon Feb 12 21:23:18 2018 +0000
- Parent:
- 0:ceed50ae31a8
- Commit message:
- Lab2_Part4;
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r ceed50ae31a8 -r c615a1ddf092 main.cpp --- a/main.cpp Mon Feb 12 21:18:19 2018 +0000 +++ b/main.cpp Mon Feb 12 21:23:18 2018 +0000 @@ -1,31 +1,23 @@ #include "mbed.h" #include "EthernetInterface.h" +#include "mbed.h" + +Ethernet eth; + int main() { - EthernetInterface eth; - eth.init(); //Use DHCP - eth.connect(); - printf("IP Address is %s\n", eth.getIPAddress()); - - TCPSocketConnection sock; - sock.connect("mbed.org", 80); - - char http_cmd[] = "GET /media/uploads/mbed_official/hello.txt HTTP/1.0\n\n"; - sock.send_all(http_cmd, sizeof(http_cmd)-1); - - char buffer[300]; - int ret; - while (true) { - ret = sock.receive(buffer, sizeof(buffer)-1); - if (ret <= 0) - break; - buffer[ret] = '\0'; - printf("Received %d chars from server:\n%s\n", ret, buffer); + char buf[0x600]; + + while(1) { + int size = eth.receive(); + if(size > 0) { + eth.read(buf, size); + printf("Destination: %02X:%02X:%02X:%02X:%02X:%02X\n", + buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]); + printf("Source: %02X:%02X:%02X:%02X:%02X:%02X\n", + buf[6], buf[7], buf[8], buf[9], buf[10], buf[11]); + } + + wait(1); } - - sock.close(); - - eth.disconnect(); - - while(1) {} -} +} \ No newline at end of file