DCS_TEAM / GPRS-server

Fork of GPRSInterface by -deleted-

Committer:
lawliet
Date:
Tue Feb 25 02:52:48 2014 +0000
Revision:
0:8ccbd963e74d
Initial version of GPRS Interface

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lawliet 0:8ccbd963e74d 1 /*
lawliet 0:8ccbd963e74d 2 Endpoint.cpp
lawliet 0:8ccbd963e74d 3 2014 Copyright (c) Seeed Technology Inc. All right reserved.
lawliet 0:8ccbd963e74d 4
lawliet 0:8ccbd963e74d 5 Author:lawliet zou(lawliet.zou@gmail.com)
lawliet 0:8ccbd963e74d 6 2014-2-24
lawliet 0:8ccbd963e74d 7
lawliet 0:8ccbd963e74d 8 This library is free software; you can redistribute it and/or
lawliet 0:8ccbd963e74d 9 modify it under the terms of the GNU Lesser General Public
lawliet 0:8ccbd963e74d 10 License as published by the Free Software Foundation; either
lawliet 0:8ccbd963e74d 11 version 2.1 of the License, or (at your option) any later version.
lawliet 0:8ccbd963e74d 12
lawliet 0:8ccbd963e74d 13 This library is distributed in the hope that it will be useful,
lawliet 0:8ccbd963e74d 14 but WITHOUT ANY WARRANTY; without even the implied warranty of
lawliet 0:8ccbd963e74d 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
lawliet 0:8ccbd963e74d 16 Lesser General Public License for more details.
lawliet 0:8ccbd963e74d 17
lawliet 0:8ccbd963e74d 18 You should have received a copy of the GNU Lesser General Public
lawliet 0:8ccbd963e74d 19 License along with this library; if not, write to the Free Software
lawliet 0:8ccbd963e74d 20 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
lawliet 0:8ccbd963e74d 21 */
lawliet 0:8ccbd963e74d 22 #include "Socket/Socket.h"
lawliet 0:8ccbd963e74d 23 #include "Socket/Endpoint.h"
lawliet 0:8ccbd963e74d 24
lawliet 0:8ccbd963e74d 25 Endpoint::Endpoint()
lawliet 0:8ccbd963e74d 26 {
lawliet 0:8ccbd963e74d 27 reset_address();
lawliet 0:8ccbd963e74d 28 }
lawliet 0:8ccbd963e74d 29 Endpoint::~Endpoint() {}
lawliet 0:8ccbd963e74d 30
lawliet 0:8ccbd963e74d 31 void Endpoint::reset_address(void)
lawliet 0:8ccbd963e74d 32 {
lawliet 0:8ccbd963e74d 33 _ipAddress[0] = '\0';
lawliet 0:8ccbd963e74d 34 _port = 0;
lawliet 0:8ccbd963e74d 35 }
lawliet 0:8ccbd963e74d 36
lawliet 0:8ccbd963e74d 37 int Endpoint::set_address(const char* host, const int port)
lawliet 0:8ccbd963e74d 38 {
lawliet 0:8ccbd963e74d 39 //Resolve DNS address or populate hard-coded IP address
lawliet 0:8ccbd963e74d 40 GPRS* gprs = GPRS::getInstance();
lawliet 0:8ccbd963e74d 41 if (gprs == NULL) {
lawliet 0:8ccbd963e74d 42 return -1;
lawliet 0:8ccbd963e74d 43 }
lawliet 0:8ccbd963e74d 44 uint32_t addr;
lawliet 0:8ccbd963e74d 45 if (!gprs->gethostbyname(host, &addr)) {
lawliet 0:8ccbd963e74d 46 return -1;
lawliet 0:8ccbd963e74d 47 }
lawliet 0:8ccbd963e74d 48 snprintf(_ipAddress, sizeof(_ipAddress), "%d.%d.%d.%d", (addr>>24)&0xff, (addr>>16)&0xff, (addr>>8)&0xff, addr&0xff);
lawliet 0:8ccbd963e74d 49 _port = port;
lawliet 0:8ccbd963e74d 50 return 0;
lawliet 0:8ccbd963e74d 51 }
lawliet 0:8ccbd963e74d 52
lawliet 0:8ccbd963e74d 53 char* Endpoint::get_address()
lawliet 0:8ccbd963e74d 54 {
lawliet 0:8ccbd963e74d 55 return _ipAddress;
lawliet 0:8ccbd963e74d 56 }
lawliet 0:8ccbd963e74d 57
lawliet 0:8ccbd963e74d 58 int Endpoint::get_port()
lawliet 0:8ccbd963e74d 59 {
lawliet 0:8ccbd963e74d 60 return _port;
lawliet 0:8ccbd963e74d 61 }