Wrapper of NetworkSocketAPI for BSD sockets on POSIX systems
Dependents: BSDInterfaceTests HelloBSDInterface
BSDInterface.h@5:1af10f9d9404, 2016-02-25 (annotated)
- Committer:
- Christopher Haster
- Date:
- Thu Feb 25 19:10:07 2016 -0600
- Revision:
- 5:1af10f9d9404
- Parent:
- 4:28479a7d15ad
Moved BSDSocket definition into private class in BSDInterface
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Christopher Haster |
1:29c61c1420c8 | 1 | /* BSD implementation of NetworkInterfaceAPI |
geky | 0:d92b89886434 | 2 | * Copyright (c) 2015 ARM Limited |
geky | 0:d92b89886434 | 3 | * |
geky | 0:d92b89886434 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
geky | 0:d92b89886434 | 5 | * you may not use this file except in compliance with the License. |
geky | 0:d92b89886434 | 6 | * You may obtain a copy of the License at |
geky | 0:d92b89886434 | 7 | * |
geky | 0:d92b89886434 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
geky | 0:d92b89886434 | 9 | * |
geky | 0:d92b89886434 | 10 | * Unless required by applicable law or agreed to in writing, software |
geky | 0:d92b89886434 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
geky | 0:d92b89886434 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
geky | 0:d92b89886434 | 13 | * See the License for the specific language governing permissions and |
geky | 0:d92b89886434 | 14 | * limitations under the License. |
geky | 0:d92b89886434 | 15 | */ |
geky | 0:d92b89886434 | 16 | |
Christopher Haster |
1:29c61c1420c8 | 17 | #ifndef BSD_INTERFACE_H |
Christopher Haster |
1:29c61c1420c8 | 18 | #define BSD_INTERFACE_H |
geky | 0:d92b89886434 | 19 | |
geky | 0:d92b89886434 | 20 | #include "EthernetInterface.h" |
geky | 0:d92b89886434 | 21 | |
geky | 0:d92b89886434 | 22 | |
Christopher Haster |
1:29c61c1420c8 | 23 | /** BSDInterface class |
Christopher Haster |
1:29c61c1420c8 | 24 | * Implementation of the NetworkInterface for BSD sockets |
geky | 0:d92b89886434 | 25 | */ |
Christopher Haster |
1:29c61c1420c8 | 26 | class BSDInterface : public NetworkInterface |
geky | 0:d92b89886434 | 27 | { |
geky | 0:d92b89886434 | 28 | public: |
geky | 0:d92b89886434 | 29 | // Implementation of NetworkInterface |
Christopher Haster |
3:eabc4ea66a64 | 30 | virtual const char *getIPAddress(); |
geky | 0:d92b89886434 | 31 | virtual const char *getMACAddress(); |
geky | 0:d92b89886434 | 32 | |
Christopher Haster |
2:0978e139e1c5 | 33 | virtual int32_t getHostByName(const char *host, char *ip); |
Christopher Haster |
2:0978e139e1c5 | 34 | |
Christopher Haster |
4:28479a7d15ad | 35 | virtual SocketInterface *createSocket(ns_protocol_t proto); |
geky | 0:d92b89886434 | 36 | virtual void destroySocket(SocketInterface *socket); |
Christopher Haster |
5:1af10f9d9404 | 37 | |
Christopher Haster |
5:1af10f9d9404 | 38 | private: |
Christopher Haster |
5:1af10f9d9404 | 39 | // Implementation of the SocketInterface for BSD |
Christopher Haster |
5:1af10f9d9404 | 40 | struct BSDSocket : public SocketInterface |
Christopher Haster |
5:1af10f9d9404 | 41 | { |
Christopher Haster |
5:1af10f9d9404 | 42 | int fd; |
Christopher Haster |
5:1af10f9d9404 | 43 | BSDSocket(int fd) : fd(fd) {} |
Christopher Haster |
5:1af10f9d9404 | 44 | |
Christopher Haster |
5:1af10f9d9404 | 45 | // Implementation of SocketInterface |
Christopher Haster |
5:1af10f9d9404 | 46 | virtual int32_t open(const char *ip, uint16_t port); |
Christopher Haster |
5:1af10f9d9404 | 47 | virtual int32_t close(); |
Christopher Haster |
5:1af10f9d9404 | 48 | |
Christopher Haster |
5:1af10f9d9404 | 49 | virtual int32_t send(const void *data, uint32_t size); |
Christopher Haster |
5:1af10f9d9404 | 50 | virtual int32_t recv(void *data, uint32_t size); |
Christopher Haster |
5:1af10f9d9404 | 51 | }; |
geky | 0:d92b89886434 | 52 | }; |
geky | 0:d92b89886434 | 53 | |
geky | 0:d92b89886434 | 54 | |
geky | 0:d92b89886434 | 55 | #endif |