A library for talking to Multi-Tech's Cellular SocketModem Devices.
Dependents: M2X_dev axeda_wrapper_dev MTS_M2x_Example1 MTS_Cellular_Connect_Example ... more
Socket/Endpoint.cpp@152:9a2c7ed27744, 2014-09-02 (annotated)
- Committer:
- mfiore
- Date:
- Tue Sep 02 18:38:55 2014 +0000
- Revision:
- 152:9a2c7ed27744
- Parent:
- 56:e5e5351f14b3
Wifi: fix compatibility break with old shields by checking for both old and new style responses to "show connection" command
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jengbrecht | 20:6e7eaf4f8634 | 1 | /* Copyright (C) 2012 mbed.org, MIT License |
jengbrecht | 20:6e7eaf4f8634 | 2 | * |
jengbrecht | 20:6e7eaf4f8634 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
jengbrecht | 20:6e7eaf4f8634 | 4 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
jengbrecht | 20:6e7eaf4f8634 | 5 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
jengbrecht | 20:6e7eaf4f8634 | 6 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
jengbrecht | 20:6e7eaf4f8634 | 7 | * furnished to do so, subject to the following conditions: |
jengbrecht | 20:6e7eaf4f8634 | 8 | * |
jengbrecht | 20:6e7eaf4f8634 | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
jengbrecht | 20:6e7eaf4f8634 | 10 | * substantial portions of the Software. |
jengbrecht | 20:6e7eaf4f8634 | 11 | * |
jengbrecht | 20:6e7eaf4f8634 | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
jengbrecht | 20:6e7eaf4f8634 | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
jengbrecht | 20:6e7eaf4f8634 | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
jengbrecht | 20:6e7eaf4f8634 | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
jengbrecht | 20:6e7eaf4f8634 | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
jengbrecht | 20:6e7eaf4f8634 | 17 | */ |
jengbrecht | 20:6e7eaf4f8634 | 18 | #include "Socket/Socket.h" |
jengbrecht | 20:6e7eaf4f8634 | 19 | #include "Socket/Endpoint.h" |
jengbrecht | 20:6e7eaf4f8634 | 20 | #include <cstring> |
jengbrecht | 20:6e7eaf4f8634 | 21 | |
jengbrecht | 20:6e7eaf4f8634 | 22 | using std::memset; |
jengbrecht | 20:6e7eaf4f8634 | 23 | |
jengbrecht | 20:6e7eaf4f8634 | 24 | Endpoint::Endpoint() |
jengbrecht | 20:6e7eaf4f8634 | 25 | { |
mfiore | 29:7408b1bdad37 | 26 | reset_address(); |
jengbrecht | 20:6e7eaf4f8634 | 27 | } |
mfiore | 22:bf3f59bf19d8 | 28 | |
jengbrecht | 20:6e7eaf4f8634 | 29 | Endpoint::~Endpoint() |
jengbrecht | 20:6e7eaf4f8634 | 30 | { |
jengbrecht | 20:6e7eaf4f8634 | 31 | } |
jengbrecht | 20:6e7eaf4f8634 | 32 | |
jengbrecht | 20:6e7eaf4f8634 | 33 | void Endpoint::reset_address(void) |
jengbrecht | 20:6e7eaf4f8634 | 34 | { |
jengbrecht | 20:6e7eaf4f8634 | 35 | _ipAddress[0] = '\0'; |
jengbrecht | 20:6e7eaf4f8634 | 36 | _port = 0; |
jengbrecht | 20:6e7eaf4f8634 | 37 | } |
jengbrecht | 20:6e7eaf4f8634 | 38 | |
jengbrecht | 20:6e7eaf4f8634 | 39 | int Endpoint::set_address(const char* host, const int port) |
jengbrecht | 20:6e7eaf4f8634 | 40 | { |
mfiore | 29:7408b1bdad37 | 41 | int length = strlen(host) + 1; // size of host including terminating character |
mfiore | 29:7408b1bdad37 | 42 | if (length > sizeof(_ipAddress)) { |
mfiore | 29:7408b1bdad37 | 43 | printf("[ERROR] could not set address because the hostname is too long\r\n"); |
mfiore | 29:7408b1bdad37 | 44 | return -1; |
mfiore | 29:7408b1bdad37 | 45 | } else { |
mfiore | 29:7408b1bdad37 | 46 | strncpy((char*) _ipAddress, host, length); |
mfiore | 29:7408b1bdad37 | 47 | _ipAddress[length] = '\0'; |
mfiore | 29:7408b1bdad37 | 48 | _port = port; |
mfiore | 29:7408b1bdad37 | 49 | } |
jengbrecht | 20:6e7eaf4f8634 | 50 | return 0; |
jengbrecht | 20:6e7eaf4f8634 | 51 | } |
jengbrecht | 20:6e7eaf4f8634 | 52 | |
jengbrecht | 20:6e7eaf4f8634 | 53 | char* Endpoint::get_address() |
jengbrecht | 20:6e7eaf4f8634 | 54 | { |
jengbrecht | 20:6e7eaf4f8634 | 55 | return _ipAddress; |
jengbrecht | 20:6e7eaf4f8634 | 56 | } |
jengbrecht | 20:6e7eaf4f8634 | 57 | |
jengbrecht | 20:6e7eaf4f8634 | 58 | int Endpoint::get_port() |
jengbrecht | 20:6e7eaf4f8634 | 59 | { |
jengbrecht | 20:6e7eaf4f8634 | 60 | return _port; |
jengbrecht | 20:6e7eaf4f8634 | 61 | } |