Example program for the BSDInterface

Dependencies:   BSDInterface NetworkSocketAPI

Fork of HelloLWIPInterface by NetworkSocketAPI

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /* NetworkSocketAPI Example Program
00002  * Copyright (c) 2015 ARM Limited
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 #include "BSDInterface.h"
00018 #include "TCPSocket.h"
00019 #include <stdio.h>
00020 
00021 BSDInterface iface;
00022 TCPSocket sock(&iface);
00023 
00024 int main()
00025 {
00026     printf("NetworkSocketAPI Example\r\n");
00027 
00028     const char *ip = iface.getIPAddress();
00029     const char *mac = iface.getMACAddress();
00030     printf("IP Address is: %s\r\n", (ip) ? ip : "No IP");
00031     printf("MAC Address is: %s\r\n", (mac) ? mac : "No MAC");
00032 
00033     sock.open("time-a.nist.gov", 37);
00034     printf("time-a.nist.gov resolved to: %s\r\n", sock.getIPAddress());
00035 
00036     unsigned char recieved[100] = {0};
00037     int32_t size = 0;
00038     size = sock.recv(recieved, sizeof(recieved));
00039 
00040     sock.close();
00041 
00042     printf("Recieved: %d bytes, %02x%02x%02x%02x\r\n", size,
00043             recieved[0], recieved[1], recieved[2], recieved[3]);
00044     printf("NetworkSocketAPI Example Finished\r\n");
00045 }