OpenClonk
C4Network2Address.cpp
Go to the documentation of this file.
1 /*
2  * OpenClonk, http://www.openclonk.org
3  *
4  * Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de/
5  * Copyright (c) 2010-2016, The OpenClonk Team and contributors
6  *
7  * Distributed under the terms of the ISC license; see accompanying file
8  * "COPYING" for details.
9  *
10  * "Clonk" is a registered trademark of Matthes Bender, used with permission.
11  * See accompanying file "TRADEMARK" for details.
12  *
13  * To redistribute this file separately, substitute the full license texts
14  * for the above references.
15  */
16 
17 #include "C4Include.h"
19 
20 #ifndef _WIN32
21 #include <arpa/inet.h>
22 #include <netdb.h>
23 #include <ifaddrs.h>
24 #include <net/if.h>
25 #endif
26 
27 // *** C4Network2Address
28 
30 {
31  // Clear
32  if (pComp->isDeserializer())
33  {
34  addr.Clear();
35  }
36 
37  // Write protocol
39  {
40  { "UDP", P_UDP },
41  { "TCP", P_TCP },
42 
43  { nullptr, P_NONE },
44  };
45  pComp->Value(mkEnumAdaptT<uint8_t>(eProtocol, Protocols));
46  pComp->Separator(StdCompiler::SEP_PART2); // ':'
47 
49 }
50 
52 {
53  switch (eProtocol)
54  {
55  case P_UDP: return FormatString("UDP:%s", addr.ToString().getData());
56  case P_TCP: return FormatString("TCP:%s", addr.ToString().getData());
57  default: return StdStrBuf("INVALID");
58  }
59 }
60 
62 {
63  return eProtocol == addr2.getProtocol() && addr == addr2.getAddr();
64 }
65 
66 
@ P_NONE
Definition: C4Network2IO.h:31
@ P_UDP
Definition: C4Network2IO.h:31
@ P_TCP
Definition: C4Network2IO.h:31
StdDefaultAdapt< T, D > mkDefaultAdapt(T &&rValue, const D &rDefault)
Definition: StdAdaptors.h:64
Definition: StdAdaptors.h:795
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:270
void CompileFunc(StdCompiler *pComp)
bool operator==(const C4Network2Address &addr) const
C4Network2IOProtocol eProtocol
const C4NetIO::addr_t & getAddr() const
C4NetIO::addr_t addr
StdStrBuf toString() const
C4Network2IOProtocol getProtocol() const
virtual bool Separator(Sep eSep=SEP_SEP)
Definition: StdCompiler.h:119
void Value(const T &rStruct)
Definition: StdCompiler.h:161
virtual bool isDeserializer()
Definition: StdCompiler.h:53
const char * getData() const
Definition: StdBuf.h:442
StdStrBuf ToString(int flags=0) const
Definition: C4NetIO.cpp:604