Example program for the BSDInterface
Dependencies: BSDInterface NetworkSocketAPI
Fork of HelloLWIPInterface by
main.cpp@50:6566cd992ac6, 2016-02-28 (annotated)
- Committer:
- Christopher Haster
- Date:
- Sun Feb 28 11:27:32 2016 -0600
- Revision:
- 50:6566cd992ac6
- Parent:
- 49:e1689f3f04f3
Fixed name collision with global symbols
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sam_grove | 0:1984a177ff56 | 1 | /* NetworkSocketAPI Example Program |
sam_grove | 0:1984a177ff56 | 2 | * Copyright (c) 2015 ARM Limited |
sam_grove | 0:1984a177ff56 | 3 | * |
sam_grove | 0:1984a177ff56 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
sam_grove | 0:1984a177ff56 | 5 | * you may not use this file except in compliance with the License. |
sam_grove | 0:1984a177ff56 | 6 | * You may obtain a copy of the License at |
sam_grove | 0:1984a177ff56 | 7 | * |
sam_grove | 0:1984a177ff56 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
sam_grove | 0:1984a177ff56 | 9 | * |
sam_grove | 0:1984a177ff56 | 10 | * Unless required by applicable law or agreed to in writing, software |
sam_grove | 0:1984a177ff56 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
sam_grove | 0:1984a177ff56 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
sam_grove | 0:1984a177ff56 | 13 | * See the License for the specific language governing permissions and |
sam_grove | 0:1984a177ff56 | 14 | * limitations under the License. |
sam_grove | 0:1984a177ff56 | 15 | */ |
sam_grove | 0:1984a177ff56 | 16 | |
geky | 47:ac3cc44106cb | 17 | #include "BSDInterface.h" |
Christopher Haster |
30:f80540b6e2db | 18 | #include "TCPSocket.h" |
Christopher Haster |
49:e1689f3f04f3 | 19 | #include <stdio.h> |
sam_grove | 0:1984a177ff56 | 20 | |
geky | 47:ac3cc44106cb | 21 | BSDInterface iface; |
Christopher Haster |
50:6566cd992ac6 | 22 | TCPSocket sock(&iface); |
sam_grove | 2:7283ce112304 | 23 | |
sam_grove | 0:1984a177ff56 | 24 | int main() |
sam_grove | 20:4cb9ef3b0cc9 | 25 | { |
bridadan | 14:c47437f5dae8 | 26 | printf("NetworkSocketAPI Example\r\n"); |
sam_grove | 4:cb8a17dd6746 | 27 | |
geky | 47:ac3cc44106cb | 28 | const char *ip = iface.getIPAddress(); |
geky | 47:ac3cc44106cb | 29 | const char *mac = iface.getMACAddress(); |
Christopher Haster |
30:f80540b6e2db | 30 | printf("IP Address is: %s\r\n", (ip) ? ip : "No IP"); |
Christopher Haster |
30:f80540b6e2db | 31 | printf("MAC Address is: %s\r\n", (mac) ? mac : "No MAC"); |
sarahmarshy | 22:1d355289fc18 | 32 | |
Christopher Haster |
50:6566cd992ac6 | 33 | sock.open("time-a.nist.gov", 37); |
Christopher Haster |
50:6566cd992ac6 | 34 | printf("time-a.nist.gov resolved to: %s\r\n", sock.getIPAddress()); |
sarahmarshy | 21:979b1db5d7da | 35 | |
Christopher Haster |
50:6566cd992ac6 | 36 | unsigned char recieved[100] = {0}; |
Christopher Haster |
30:f80540b6e2db | 37 | int32_t size = 0; |
Christopher Haster |
50:6566cd992ac6 | 38 | size = sock.recv(recieved, sizeof(recieved)); |
Christopher Haster |
30:f80540b6e2db | 39 | |
Christopher Haster |
50:6566cd992ac6 | 40 | sock.close(); |
Christopher Haster |
30:f80540b6e2db | 41 | |
Christopher Haster |
49:e1689f3f04f3 | 42 | printf("Recieved: %d bytes, %02x%02x%02x%02x\r\n", size, |
Christopher Haster |
30:f80540b6e2db | 43 | recieved[0], recieved[1], recieved[2], recieved[3]); |
sam_grove | 24:471a07e886ae | 44 | printf("NetworkSocketAPI Example Finished\r\n"); |
sam_grove | 0:1984a177ff56 | 45 | } |