21 static const char C4NetpuncherProtocolVersion = 1;
23 static const size_t HeaderSize = 2, HeaderPSize = 1;
31 if (!rpack.
getPData() || *rpack.
getPData() != C4NetpuncherProtocolVersion)
return nullptr;
39 default:
return nullptr;
43 catch (...) {
return nullptr; }
50 pkt.
New(
sizeof(
type) +
sizeof(C4NetpuncherProtocolVersion) + content.
getSize());
53 offset +=
sizeof(
type);
54 pkt.
Write(&C4NetpuncherProtocolVersion,
sizeof(C4NetpuncherProtocolVersion), offset);
55 offset +=
sizeof(C4NetpuncherProtocolVersion);
56 pkt.
Write(content, offset);
61 if (rpack.
getPSize() < HeaderPSize + 2 + 16)
throw "invalid size";
62 uint16_t port = *getBufPtr<uint16_t>(rpack, HeaderSize);
64 memcpy(&
static_cast<sockaddr_in6*
>(&addr)->sin6_addr, getBufPtr<char>(rpack, HeaderSize +
sizeof(port)), 16);
67 StdBuf C4NetpuncherPacketCReq::PackInto()
const {
69 auto sin6 =
static_cast<sockaddr_in6
>(addr.
AsIPv6());
71 buf.
New(
sizeof(port) +
sizeof(sin6.sin6_addr));
73 buf.
Write(&port,
sizeof(port), offset);
74 offset +=
sizeof(port);
75 buf.
Write(&sin6.sin6_addr,
sizeof(sin6.sin6_addr), offset);
76 static_assert(
sizeof(sin6.sin6_addr) == 16,
"expected sin6_addr to be 16 bytes");
80 template<C4NetpuncherPacketType TYPE>
82 if (rpack.
getPSize() < HeaderPSize +
sizeof(
id))
throw "invalid size";
83 id = *getBufPtr<CID>(rpack, HeaderSize);
86 template<C4NetpuncherPacketType TYPE>
91 buf.
Write(&
id,
sizeof(
id));
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
void SetAddr(const C4NetIO::addr_t &naddr)
uint8_t getStatus() const
const char * getPData() const
C4NetpuncherPacketCReq(const C4NetIOPacket &rpack)
C4NetIOPacket PackTo(const C4NetIO::addr_t &) const
virtual StdBuf PackInto() const =0
std::unique_ptr< C4NetpuncherPacket > uptr
virtual C4NetpuncherPacketType GetType() const =0
static std::unique_ptr< C4NetpuncherPacket > Construct(const C4NetIOPacket &rpack)
C4NetpuncherPacketID(const C4NetIOPacket &rpack)
void Write(const void *pnData, size_t inSize, size_t iAt=0)
void Value(const T &rStruct)
void SetAddress(const sockaddr *addr)
EndpointAddress AsIPv6() const
void CompileFunc(StdCompiler *pComp)