WIZnet Library for my tests.

Fork of WIZnet_Library by WIZnet

Committer:
Whisper_84
Date:
Wed Jan 06 09:10:31 2016 +0000
Revision:
9:b5e8a0f64fea
Parent:
7:7c67a8922ec5
Create project for test Ethernet shield and stepper motor driver.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Bongjun 7:7c67a8922ec5 1 /* Copyright (C) 2012 mbed.org, MIT License
Bongjun 7:7c67a8922ec5 2 *
Bongjun 7:7c67a8922ec5 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
Bongjun 7:7c67a8922ec5 4 * and associated documentation files (the "Software"), to deal in the Software without restriction,
Bongjun 7:7c67a8922ec5 5 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
Bongjun 7:7c67a8922ec5 6 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
Bongjun 7:7c67a8922ec5 7 * furnished to do so, subject to the following conditions:
Bongjun 7:7c67a8922ec5 8 *
Bongjun 7:7c67a8922ec5 9 * The above copyright notice and this permission notice shall be included in all copies or
Bongjun 7:7c67a8922ec5 10 * substantial portions of the Software.
Bongjun 7:7c67a8922ec5 11 *
Bongjun 7:7c67a8922ec5 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
Bongjun 7:7c67a8922ec5 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Bongjun 7:7c67a8922ec5 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
Bongjun 7:7c67a8922ec5 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Bongjun 7:7c67a8922ec5 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Bongjun 7:7c67a8922ec5 17 */
Bongjun 7:7c67a8922ec5 18 #include "Socket.h"
Bongjun 7:7c67a8922ec5 19 #include "Endpoint.h"
Bongjun 7:7c67a8922ec5 20
Bongjun 7:7c67a8922ec5 21 Endpoint::Endpoint() {
Bongjun 7:7c67a8922ec5 22 reset_address();
Bongjun 7:7c67a8922ec5 23 }
Bongjun 7:7c67a8922ec5 24 Endpoint::~Endpoint() {}
jbkim 0:b72d22e10709 25
Bongjun 7:7c67a8922ec5 26 void Endpoint::reset_address(void) {
Bongjun 7:7c67a8922ec5 27 _ipAddress[0] = '\0';
Bongjun 7:7c67a8922ec5 28 _port = 0;
Bongjun 7:7c67a8922ec5 29 }
Bongjun 7:7c67a8922ec5 30
Bongjun 7:7c67a8922ec5 31 int Endpoint::set_address(const char* host, const int port) {
Bongjun 7:7c67a8922ec5 32 //Resolve DNS address or populate hard-coded IP address
Bongjun 7:7c67a8922ec5 33 WIZnet_Chip* eth = WIZnet_Chip::getInstance();
Bongjun 7:7c67a8922ec5 34 if (eth == NULL) {
Bongjun 7:7c67a8922ec5 35 error("Endpoint constructor error: no WIZnet chip instance available!\r\n");
Bongjun 7:7c67a8922ec5 36 return -1;
Bongjun 7:7c67a8922ec5 37 }
Bongjun 7:7c67a8922ec5 38 uint32_t addr;
Bongjun 7:7c67a8922ec5 39 if (!eth->gethostbyname(host, &addr)) {
Bongjun 7:7c67a8922ec5 40 return -1;
Bongjun 7:7c67a8922ec5 41 }
Bongjun 7:7c67a8922ec5 42 snprintf(_ipAddress, sizeof(_ipAddress), "%d.%d.%d.%d", (addr>>24)&0xff, (addr>>16)&0xff, (addr>>8)&0xff, addr&0xff);
Bongjun 7:7c67a8922ec5 43 _port = port;
Bongjun 7:7c67a8922ec5 44 return 0;
Bongjun 7:7c67a8922ec5 45 }
Bongjun 7:7c67a8922ec5 46
Bongjun 7:7c67a8922ec5 47 char* Endpoint::get_address() {
Bongjun 7:7c67a8922ec5 48 return _ipAddress;
Bongjun 7:7c67a8922ec5 49 }
Bongjun 7:7c67a8922ec5 50
Bongjun 7:7c67a8922ec5 51 int Endpoint::get_port() {
Bongjun 7:7c67a8922ec5 52 return _port;
Bongjun 7:7c67a8922ec5 53 }
Bongjun 7:7c67a8922ec5 54