Integrating the ublox LISA C200 modem
Fork of SprintUSBModemHTTPClientTest by
SprintUSBModem/Socket/Endpoint.cpp@5:3f93dd1d4cb3, 2013-09-26 (annotated)
- Committer:
- sam_grove
- Date:
- Thu Sep 26 00:44:20 2013 -0500
- Revision:
- 5:3f93dd1d4cb3
Exported program and replaced contents of the repo with the source
to build and debug using keil mdk. Libs NOT upto date are lwip, lwip-sys
and socket. these have newer versions under mbed_official but were starting
from a know working point
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sam_grove | 5:3f93dd1d4cb3 | 1 | /* Copyright (C) 2012 mbed.org, MIT License |
sam_grove | 5:3f93dd1d4cb3 | 2 | * |
sam_grove | 5:3f93dd1d4cb3 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
sam_grove | 5:3f93dd1d4cb3 | 4 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
sam_grove | 5:3f93dd1d4cb3 | 5 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
sam_grove | 5:3f93dd1d4cb3 | 6 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
sam_grove | 5:3f93dd1d4cb3 | 7 | * furnished to do so, subject to the following conditions: |
sam_grove | 5:3f93dd1d4cb3 | 8 | * |
sam_grove | 5:3f93dd1d4cb3 | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
sam_grove | 5:3f93dd1d4cb3 | 10 | * substantial portions of the Software. |
sam_grove | 5:3f93dd1d4cb3 | 11 | * |
sam_grove | 5:3f93dd1d4cb3 | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
sam_grove | 5:3f93dd1d4cb3 | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
sam_grove | 5:3f93dd1d4cb3 | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
sam_grove | 5:3f93dd1d4cb3 | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
sam_grove | 5:3f93dd1d4cb3 | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
sam_grove | 5:3f93dd1d4cb3 | 17 | */ |
sam_grove | 5:3f93dd1d4cb3 | 18 | #include "Socket/Socket.h" |
sam_grove | 5:3f93dd1d4cb3 | 19 | #include "Socket/Endpoint.h" |
sam_grove | 5:3f93dd1d4cb3 | 20 | #include <cstring> |
sam_grove | 5:3f93dd1d4cb3 | 21 | |
sam_grove | 5:3f93dd1d4cb3 | 22 | using std::memset; |
sam_grove | 5:3f93dd1d4cb3 | 23 | |
sam_grove | 5:3f93dd1d4cb3 | 24 | Endpoint::Endpoint() { |
sam_grove | 5:3f93dd1d4cb3 | 25 | reset_address(); |
sam_grove | 5:3f93dd1d4cb3 | 26 | } |
sam_grove | 5:3f93dd1d4cb3 | 27 | Endpoint::~Endpoint() {} |
sam_grove | 5:3f93dd1d4cb3 | 28 | |
sam_grove | 5:3f93dd1d4cb3 | 29 | void Endpoint::reset_address(void) { |
sam_grove | 5:3f93dd1d4cb3 | 30 | memset(&_remoteHost, 0, sizeof(struct sockaddr_in)); |
sam_grove | 5:3f93dd1d4cb3 | 31 | _ipAddress[0] = '\0'; |
sam_grove | 5:3f93dd1d4cb3 | 32 | } |
sam_grove | 5:3f93dd1d4cb3 | 33 | |
sam_grove | 5:3f93dd1d4cb3 | 34 | int Endpoint::set_address(const char* host, const int port) { |
sam_grove | 5:3f93dd1d4cb3 | 35 | //Resolve DNS address or populate hard-coded IP address |
sam_grove | 5:3f93dd1d4cb3 | 36 | struct hostent *server = ::gethostbyname(host); |
sam_grove | 5:3f93dd1d4cb3 | 37 | if (server == NULL) |
sam_grove | 5:3f93dd1d4cb3 | 38 | return -1; //Could not resolve address |
sam_grove | 5:3f93dd1d4cb3 | 39 | |
sam_grove | 5:3f93dd1d4cb3 | 40 | reset_address(); |
sam_grove | 5:3f93dd1d4cb3 | 41 | |
sam_grove | 5:3f93dd1d4cb3 | 42 | // Set IP address |
sam_grove | 5:3f93dd1d4cb3 | 43 | std::memcpy((char*) &_remoteHost.sin_addr.s_addr, |
sam_grove | 5:3f93dd1d4cb3 | 44 | (char*) server->h_addr_list[0], server->h_length); |
sam_grove | 5:3f93dd1d4cb3 | 45 | _remoteHost.sin_family = AF_INET; |
sam_grove | 5:3f93dd1d4cb3 | 46 | |
sam_grove | 5:3f93dd1d4cb3 | 47 | // Set port |
sam_grove | 5:3f93dd1d4cb3 | 48 | _remoteHost.sin_port = htons(port); |
sam_grove | 5:3f93dd1d4cb3 | 49 | |
sam_grove | 5:3f93dd1d4cb3 | 50 | return 0; |
sam_grove | 5:3f93dd1d4cb3 | 51 | } |
sam_grove | 5:3f93dd1d4cb3 | 52 | |
sam_grove | 5:3f93dd1d4cb3 | 53 | char* Endpoint::get_address() { |
sam_grove | 5:3f93dd1d4cb3 | 54 | if ((_ipAddress[0] == '\0') && (_remoteHost.sin_addr.s_addr != 0)) |
sam_grove | 5:3f93dd1d4cb3 | 55 | inet_ntoa_r(_remoteHost.sin_addr, _ipAddress, sizeof(_ipAddress)); |
sam_grove | 5:3f93dd1d4cb3 | 56 | return _ipAddress; |
sam_grove | 5:3f93dd1d4cb3 | 57 | } |
sam_grove | 5:3f93dd1d4cb3 | 58 | |
sam_grove | 5:3f93dd1d4cb3 | 59 | int Endpoint::get_port() { |
sam_grove | 5:3f93dd1d4cb3 | 60 | return ntohs(_remoteHost.sin_port); |
sam_grove | 5:3f93dd1d4cb3 | 61 | } |