This is WIZnet Ethernet Interface using Hardware TCP/IP chip, W5500, W5200 and W5100. One of them can be selected by enabling it in wiznet.h.
Fork of WIZnet_Library by
WIZnetInterface/Socket/Endpoint.cpp@3:9997e2b7d459, 2014-07-10 (annotated)
- Committer:
- Bongjun
- Date:
- Thu Jul 10 04:55:47 2014 +0000
- Revision:
- 3:9997e2b7d459
- Parent:
- 0:b72d22e10709
fix Sn_IR read error
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jbkim | 0:b72d22e10709 | 1 | /* Copyright (C) 2012 mbed.org, MIT License |
jbkim | 0:b72d22e10709 | 2 | * |
jbkim | 0:b72d22e10709 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
jbkim | 0:b72d22e10709 | 4 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
jbkim | 0:b72d22e10709 | 5 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
jbkim | 0:b72d22e10709 | 6 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
jbkim | 0:b72d22e10709 | 7 | * furnished to do so, subject to the following conditions: |
jbkim | 0:b72d22e10709 | 8 | * |
jbkim | 0:b72d22e10709 | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
jbkim | 0:b72d22e10709 | 10 | * substantial portions of the Software. |
jbkim | 0:b72d22e10709 | 11 | * |
jbkim | 0:b72d22e10709 | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
jbkim | 0:b72d22e10709 | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
jbkim | 0:b72d22e10709 | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
jbkim | 0:b72d22e10709 | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
jbkim | 0:b72d22e10709 | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
jbkim | 0:b72d22e10709 | 17 | */ |
jbkim | 0:b72d22e10709 | 18 | #include "Socket.h" |
jbkim | 0:b72d22e10709 | 19 | #include "Endpoint.h" |
jbkim | 0:b72d22e10709 | 20 | |
jbkim | 0:b72d22e10709 | 21 | Endpoint::Endpoint() { |
jbkim | 0:b72d22e10709 | 22 | reset_address(); |
jbkim | 0:b72d22e10709 | 23 | } |
jbkim | 0:b72d22e10709 | 24 | Endpoint::~Endpoint() {} |
jbkim | 0:b72d22e10709 | 25 | |
jbkim | 0:b72d22e10709 | 26 | void Endpoint::reset_address(void) { |
jbkim | 0:b72d22e10709 | 27 | _ipAddress[0] = '\0'; |
jbkim | 0:b72d22e10709 | 28 | _port = 0; |
jbkim | 0:b72d22e10709 | 29 | } |
jbkim | 0:b72d22e10709 | 30 | |
jbkim | 0:b72d22e10709 | 31 | int Endpoint::set_address(const char* host, const int port) { |
jbkim | 0:b72d22e10709 | 32 | //Resolve DNS address or populate hard-coded IP address |
jbkim | 0:b72d22e10709 | 33 | WIZnet_Chip* eth = WIZnet_Chip::getInstance(); |
jbkim | 0:b72d22e10709 | 34 | if (eth == NULL) { |
jbkim | 0:b72d22e10709 | 35 | return -1; |
jbkim | 0:b72d22e10709 | 36 | } |
jbkim | 0:b72d22e10709 | 37 | uint32_t addr; |
jbkim | 0:b72d22e10709 | 38 | if (!eth->gethostbyname(host, &addr)) { |
jbkim | 0:b72d22e10709 | 39 | return -1; |
jbkim | 0:b72d22e10709 | 40 | } |
jbkim | 0:b72d22e10709 | 41 | snprintf(_ipAddress, sizeof(_ipAddress), "%d.%d.%d.%d", (addr>>24)&0xff, (addr>>16)&0xff, (addr>>8)&0xff, addr&0xff); |
jbkim | 0:b72d22e10709 | 42 | _port = port; |
jbkim | 0:b72d22e10709 | 43 | return 0; |
jbkim | 0:b72d22e10709 | 44 | } |
jbkim | 0:b72d22e10709 | 45 | |
jbkim | 0:b72d22e10709 | 46 | char* Endpoint::get_address() { |
jbkim | 0:b72d22e10709 | 47 | return _ipAddress; |
jbkim | 0:b72d22e10709 | 48 | } |
jbkim | 0:b72d22e10709 | 49 | |
jbkim | 0:b72d22e10709 | 50 | int Endpoint::get_port() { |
jbkim | 0:b72d22e10709 | 51 | return _port; |
jbkim | 0:b72d22e10709 | 52 | } |
jbkim | 0:b72d22e10709 | 53 |