Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of net-test by
Revision 1:e01aa8a340ad, committed 2016-11-09
- Comitter:
- infinnovation
- Date:
- Wed Nov 09 21:45:12 2016 +0000
- Parent:
- 0:dcf432232b87
- Commit message:
- Initial commit
Changed in this revision
--- a/chlibs.lib Thu Oct 13 22:05:24 2016 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -https://developer.mbed.org/users/infinnovation/code/chlibs/#d833e814f1ab
--- a/main.cpp Thu Oct 13 22:05:24 2016 +0000 +++ b/main.cpp Wed Nov 09 21:45:12 2016 +0000 @@ -1,36 +1,40 @@ -#include "mbed.h" -#include "EthernetInterface.h" -#include "chlibs.h" +#include <mbed.h> +#include <EthernetInterface.h> + +struct TestAddr { + const char *host; + unsigned port; +}; -#define PEER "10.212.1.246" +#define GOOD_HOST "192.168.3.1" +#define BAD_HOST "192.168.3.2" +#define BAD_NET "239.9.9.9" // Multicast + +const TestAddr test_addrs[] = { + {GOOD_HOST, 2}, // port 2 not open; get ECONNREFUSED on Linux + {BAD_HOST, 80}, // get EHOSTUNREACH on Linux + {BAD_NET, 99}, // get ENETUNREACH on Linux +}; EthernetInterface eth; -static void try_connect(unsigned port) { - INFO("connect %s:%u", PEER, port); - TCPSocket sock; - int err = sock.open(ð); - if (err < 0) { - ch_report("sock.open", err); - return; - } - err = sock.connect(PEER, port); - if (err < 0) { - ch_report("sock.connect", err); - return; - } -} - int main() { - ch_log_level = CH_LOG_INFO; - INFO("net-test %s %s", __DATE__, __TIME__); + printf("connect-test\r\n"); int err = eth.connect(); - if (err < 0) ch_fail("eth.connect", err); - INFO("IP address %s", eth.get_ip_address()); + if (err) error("eth.connect: %d\r\n", err); + printf("IP address %s\r\n", eth.get_ip_address()); - try_connect(7); - - INFO("End"); + for (int i = 0; i < sizeof(test_addrs)/sizeof(test_addrs[0]); i++) { + const TestAddr *addr = &test_addrs[i]; + TCPSocket sock; + err = sock.open(ð); + if (err) error("sock.open: %d\r\n", err); + printf("Connecting to %s:%u\r\n", addr->host, addr->port); + err = sock.connect(addr->host, addr->port); + printf("err = %d\r\n", err); + sock.close(); + } + printf("All done\r\n"); return 0; } \ No newline at end of file
--- a/mbed-os.lib Thu Oct 13 22:05:24 2016 +0000 +++ b/mbed-os.lib Wed Nov 09 21:45:12 2016 +0000 @@ -1,1 +1,1 @@ -https://github.com/ARMmbed/mbed-os/#670b0984ebf1207771ef5afbc1c64f85af349da1 +https://github.com/ARMmbed/mbed-os/#a1c0840b3d69060e5eb708edb18358e424a40f51