0.01.00
socket.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016, The OpenThread Authors.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * 1. Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * 3. Neither the name of the copyright holder nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  * POSSIBILITY OF SUCH DAMAGE.
27  */
28 
34 #ifndef NET_SOCKET_HPP_
35 #define NET_SOCKET_HPP_
36 
37 #include "openthread-core-config.h"
38 
39 #include <openthread/openthread.h>
40 
41 #include "net/ip6_address.hpp"
42 
43 namespace ot {
44 namespace Ip6 {
45 
58 {
59 public:
64  MessageInfo(void) { memset(this, 0, sizeof(*this)); }
65 
72  const Address &GetSockAddr(void) const { return *static_cast<const Address *>(&mSockAddr);}
73 
80  void SetSockAddr(const Address &aAddress) { mSockAddr = aAddress; }
81 
88  uint16_t GetSockPort(void) const { return mSockPort; }
89 
96  void SetSockPort(uint16_t aPort) { mSockPort = aPort; }
97 
104  Address &GetPeerAddr(void) { return *static_cast<Address *>(&mPeerAddr);}
105 
112  const Address &GetPeerAddr(void) const { return *static_cast<const Address *>(&mPeerAddr);}
113 
120  void SetPeerAddr(const Address &aAddress) { mPeerAddr = aAddress; }
121 
128  uint16_t GetPeerPort(void) const { return mPeerPort; }
129 
136  void SetPeerPort(uint16_t aPort) { mPeerPort = aPort; }
137 
144  int8_t GetInterfaceId(void) const { return mInterfaceId; }
145 
152  void SetInterfaceId(int8_t aInterfaceId) { mInterfaceId = aInterfaceId; }
153 
160  uint8_t GetHopLimit(void) const { return mHopLimit; }
161 
168  void SetHopLimit(uint8_t aHopLimit) { mHopLimit = aHopLimit; }
169 
176  const void *GetLinkInfo(void) const { return mLinkInfo; }
177 
184  void SetLinkInfo(const void *aLinkInfo) { mLinkInfo = aLinkInfo; }
185 };
186 
191 class SockAddr: public otSockAddr
192 {
193 public:
198  SockAddr(void) { memset(&mAddress, 0, sizeof(mAddress)), mPort = 0, mScopeId = 0; }
199 
206  Address &GetAddress(void) { return *static_cast<Address *>(&mAddress); }
207 
214  const Address &GetAddress(void) const { return *static_cast<const Address *>(&mAddress); }
215 };
216 
221 } // namespace Ip6
222 } // namespace ot
223 
224 #endif // NET_SOCKET_HPP_
const Address & GetPeerAddr(void) const
This method returns a reference to the peer socket address.
Definition: socket.hpp:112
uint16_t mPeerPort
The peer transport-layer port.
Definition: types.h:456
Definition: cli.cpp:90
This file includes definitions for IPv6 addresses.
This class implements an IPv6 address object.
Definition: ip6_address.hpp:60
void SetSockPort(uint16_t aPort)
This method gets the local socket port.
Definition: socket.hpp:96
void SetLinkInfo(const void *aLinkInfo)
This method sets the pointer to the Link Info.
Definition: socket.hpp:184
This class implements message information for an IPv6 message.
Definition: socket.hpp:57
void SetHopLimit(uint8_t aHopLimit)
This method sets the Hop Limit.
Definition: socket.hpp:168
Address & GetPeerAddr(void)
This method returns a reference to the peer socket address.
Definition: socket.hpp:104
void SetSockAddr(const Address &aAddress)
This method sets the local socket address.
Definition: socket.hpp:80
void SetPeerAddr(const Address &aAddress)
This method sets the peer&#39;s socket address.
Definition: socket.hpp:120
This structure represents an IPv6 socket address.
Definition: types.h:1140
int8_t GetInterfaceId(void) const
This method gets the Interface ID.
Definition: socket.hpp:144
This class implements a socket address.
Definition: socket.hpp:191
int8_t mInterfaceId
An IPv6 interface identifier.
Definition: types.h:461
SockAddr(void)
This constructor initializes the object.
Definition: socket.hpp:198
const Address & GetAddress(void) const
This method returns a reference to the IPv6 address.
Definition: socket.hpp:214
uint16_t GetSockPort(void) const
This method gets the local socket port.
Definition: socket.hpp:88
This file defines the top-level functions for the OpenThread library.
This structure represents the local and peer IPv6 socket addresses.
Definition: types.h:436
void SetPeerPort(uint16_t aPort)
This method gets the peer socket port.
Definition: socket.hpp:136
uint16_t mSockPort
The local transport-layer port.
Definition: types.h:451
void SetInterfaceId(int8_t aInterfaceId)
This method sets the Interface ID.
Definition: socket.hpp:152
otIp6Address mSockAddr
The local IPv6 address.
Definition: types.h:441
const void * mLinkInfo
A pointer to link-specific information.
Definition: types.h:473
uint16_t GetPeerPort(void) const
This method gets the peer socket port.
Definition: socket.hpp:128
const Address & GetSockAddr(void) const
This method returns a reference to the local socket address.
Definition: socket.hpp:72
Address & GetAddress(void)
This method returns a reference to the IPv6 address.
Definition: socket.hpp:206
uint8_t mHopLimit
The IPv6 Hop Limit.
Definition: types.h:466
uint8_t GetHopLimit(void) const
This method gets the Hop Limit.
Definition: socket.hpp:160
const void * GetLinkInfo(void) const
This method returns a pointer to the Link Info.
Definition: socket.hpp:176
otIp6Address mPeerAddr
The peer IPv6 address.
Definition: types.h:446
This file includes compile-time configuration constants for OpenThread.
MessageInfo(void)
This constructor initializes the object.
Definition: socket.hpp:64