-set socket options before “socket.bind” -listen for incoming SOCK_STREAM connections only before “socket.accept” resolves ubuntu errors.
Fork of NSAPITests by
NSAPITests.cpp
- Committer:
- Brian Daniels
- Date:
- 2016-03-02
- Revision:
- 2:41bf867fedd2
- Parent:
- 1:796ba8b082b1
- Child:
- 3:8b595ee6219d
File content as of revision 2:41bf867fedd2:
#include "NetworkInterface.h" #include "TCPSocket.h" #include <stdio.h> #include "string.h" int nsapi_isConnected_test(NetworkInterface *iface) { return !(iface->isConnected()); } int nsapi_getIPAddress_test(NetworkInterface *iface) { if (!iface->getIPAddress()[0]) { printf("'getIpAddress' did not return an IP address\r\n"); return -1; } return 0; } int nsapi_getMACAddress_test(NetworkInterface *iface) { if (!iface->getMACAddress()[0]) { printf("'getMacAddress' did not return a MAC address\r\n"); return -1; } return 0; } int nsapi_getHostByName_test(NetworkInterface *iface) { char ip_address[NS_IP_SIZE] = "\0"; int32_t ret = iface->getHostByName("google.com", ip_address); if (ret) { printf("'getHostByName' failed\r\n"); return -1; } else if (!ip_address[0]) { printf("Returned IP address was null\r\n"); return -2; } else { return 0; } } int nsapi_run_test(const char *name, NetworkInterface *iface, int (*test)(NetworkInterface*)) { int ret; printf("---------------------\r\n"); printf("%s: running...\r\n", name); ret = test(iface); printf("%s: ", name); if (!ret) { printf("PASS\r\n"); } else { printf("FAIL (Return code %d)\r\n", ret); } return ret; } int nsapi_tests(const char *name, NetworkInterface *iface) { int ret = 0; ret |= nsapi_run_test("nsapi_isConnected_test", iface, &nsapi_isConnected_test); ret |= nsapi_run_test("nsapi_getIPAddress_test", iface, &nsapi_getIPAddress_test); ret |= nsapi_run_test("nsapi_getMACAddress_test", iface, &nsapi_getMACAddress_test); ret |= nsapi_run_test("nsapi_getHostByName_test", iface, &nsapi_getHostByName_test); return ret; }