Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: HelloWizFi250Interface
Fork of NetworkSocketAPI by
SocketInterface.cpp@23:1e86d9fb3d86, 2016-02-18 (annotated)
- Committer:
- Christopher Haster
- Date:
- Thu Feb 18 04:05:09 2016 -0600
- Branch:
- api-changes
- Revision:
- 23:1e86d9fb3d86
- Child:
- 28:163fbe3263f4
Added shallow implementation of simple methods in interfaces
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| Christopher Haster |
23:1e86d9fb3d86 | 1 | /* SocketInterface Base Class |
| Christopher Haster |
23:1e86d9fb3d86 | 2 | * Copyright (c) 2015 ARM Limited |
| Christopher Haster |
23:1e86d9fb3d86 | 3 | * |
| Christopher Haster |
23:1e86d9fb3d86 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| Christopher Haster |
23:1e86d9fb3d86 | 5 | * you may not use this file except in compliance with the License. |
| Christopher Haster |
23:1e86d9fb3d86 | 6 | * You may obtain a copy of the License at |
| Christopher Haster |
23:1e86d9fb3d86 | 7 | * |
| Christopher Haster |
23:1e86d9fb3d86 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| Christopher Haster |
23:1e86d9fb3d86 | 9 | * |
| Christopher Haster |
23:1e86d9fb3d86 | 10 | * Unless required by applicable law or agreed to in writing, software |
| Christopher Haster |
23:1e86d9fb3d86 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| Christopher Haster |
23:1e86d9fb3d86 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| Christopher Haster |
23:1e86d9fb3d86 | 13 | * See the License for the specific language governing permissions and |
| Christopher Haster |
23:1e86d9fb3d86 | 14 | * limitations under the License. |
| Christopher Haster |
23:1e86d9fb3d86 | 15 | */ |
| Christopher Haster |
23:1e86d9fb3d86 | 16 | |
| Christopher Haster |
23:1e86d9fb3d86 | 17 | #include "SocketInterface.h" |
| Christopher Haster |
23:1e86d9fb3d86 | 18 | #include <stdlib.h> |
| Christopher Haster |
23:1e86d9fb3d86 | 19 | #include <string.h> |
| Christopher Haster |
23:1e86d9fb3d86 | 20 | |
| Christopher Haster |
23:1e86d9fb3d86 | 21 | #define IP_SIZE 16 |
| Christopher Haster |
23:1e86d9fb3d86 | 22 | |
| Christopher Haster |
23:1e86d9fb3d86 | 23 | SocketInterface::SocketInterface() |
| Christopher Haster |
23:1e86d9fb3d86 | 24 | : _ip_address(0) |
| Christopher Haster |
23:1e86d9fb3d86 | 25 | , _port(0) { |
| Christopher Haster |
23:1e86d9fb3d86 | 26 | } |
| Christopher Haster |
23:1e86d9fb3d86 | 27 | |
| Christopher Haster |
23:1e86d9fb3d86 | 28 | SocketInterface::~SocketInterface() { |
| Christopher Haster |
23:1e86d9fb3d86 | 29 | if (_ip_address) free(_ip_address); |
| Christopher Haster |
23:1e86d9fb3d86 | 30 | } |
| Christopher Haster |
23:1e86d9fb3d86 | 31 | |
| Christopher Haster |
23:1e86d9fb3d86 | 32 | void SocketInterface::setIPAddress(const char *ip) { |
| Christopher Haster |
23:1e86d9fb3d86 | 33 | _ip_address = (char*)malloc(IP_SIZE); |
| Christopher Haster |
23:1e86d9fb3d86 | 34 | strcpy(_ip_address, ip); |
| Christopher Haster |
23:1e86d9fb3d86 | 35 | } |
| Christopher Haster |
23:1e86d9fb3d86 | 36 | |
| Christopher Haster |
23:1e86d9fb3d86 | 37 | void SocketInterface::setPort(uint16_t port) { |
| Christopher Haster |
23:1e86d9fb3d86 | 38 | _port = port; |
| Christopher Haster |
23:1e86d9fb3d86 | 39 | } |
| Christopher Haster |
23:1e86d9fb3d86 | 40 | |
| Christopher Haster |
23:1e86d9fb3d86 | 41 | const char *SocketInterface::getIPAddress() { |
| Christopher Haster |
23:1e86d9fb3d86 | 42 | return _ip_address; |
| Christopher Haster |
23:1e86d9fb3d86 | 43 | } |
| Christopher Haster |
23:1e86d9fb3d86 | 44 | |
| Christopher Haster |
23:1e86d9fb3d86 | 45 | uint16_t SocketInterface::getPort() { |
| Christopher Haster |
23:1e86d9fb3d86 | 46 | return _port; |
| Christopher Haster |
23:1e86d9fb3d86 | 47 | } |
| Christopher Haster |
23:1e86d9fb3d86 | 48 |
