w11 - cpp 0.794
Backend server for Rlink and w11
Loading...
Searching...
No Matches
RethBuf.cpp
Go to the documentation of this file.
1// $Id: RethBuf.cpp 1186 2019-07-12 17:49:59Z mueller $
2// SPDX-License-Identifier: GPL-3.0-or-later
3// Copyright 2017- by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
4//
5// Revision History:
6// Date Rev Version Comment
7// 2017-04-16 880 1.0 Initial version
8// 2017-02-12 850 0.1 First draft
9// ---------------------------------------------------------------------------
10
15#include <stdlib.h>
16#include <unistd.h>
17
18#include <arpa/inet.h>
19
20#include <sstream>
21
22#include "librtools/RosFill.hpp"
25
26#include "RethBuf.hpp"
27#include "RethTools.hpp"
28
29using namespace std;
30
36// all method definitions in namespace Retro
37namespace Retro {
38
39//------------------------------------------+-----------------------------------
40// constants definitions
41const size_t RethBuf::kMaxSize;
42const size_t RethBuf::kMinSize;
43const size_t RethBuf::kCrcSize;
44const size_t RethBuf::kWOffDstMac;
45const size_t RethBuf::kWOffSrcMac;
46const size_t RethBuf::kWOffTyp;
47
48//------------------------------------------+-----------------------------------
51 : fTime(),
52 fSize(0)
53{}
54
55//------------------------------------------+-----------------------------------
58{}
59
60//------------------------------------------+-----------------------------------
62
63uint16_t RethBuf::Type() const
64{
65 return ntohs(Buf16()[kWOffTyp]);
66}
67
68//------------------------------------------+-----------------------------------
70
71ssize_t RethBuf::Read(int fd)
72{
73 ssize_t irc = ::read(fd, fBuf, kMaxSize);
74 fSize = (irc > 0) ? irc : 0;
75 return irc;
76}
77
78//------------------------------------------+-----------------------------------
80
81ssize_t RethBuf::Write(int fd) const
82{
83 return ::write(fd, fBuf, fSize);
84}
85
86//------------------------------------------+-----------------------------------
88
89std::string RethBuf::FrameInfo() const
90{
91 std::ostringstream sos;
94 << " typ: " << RosPrintBvi(Type(),16)
95 << " siz: " << RosPrintf(Size(),"d",4);
96 return sos.str();
97}
98
99//------------------------------------------+-----------------------------------
101
102void RethBuf::Dump(std::ostream& os, int ind, const char* text,
103 int detail) const
104{
105 RosFill bl(ind);
106 os << bl << (text?text:"--") << "RethBuf @ " << this << endl;
107 os << bl << " fTime: " << fTime << endl;
108 os << bl << " fBuf: " << FrameInfo() << endl;
109
110 if (detail < 0) return; // detail<0 --> info only
111
112 int ibeg = 0;
113 int imax = int(Size())-1;
114 for (int iline=0; ; iline++) {
115 if (ibeg > imax) break;
116 if (detail <= 0 && iline >= 6) break; // detail>1 --> full buffer
117 int iend = ibeg + 15;
118 int igap = 0;
119 if (iend > imax) {
120 igap = iend - imax;
121 iend = imax;
122 }
123 os << bl << " " << RosPrintf(ibeg,"x0", 4) << ":";
124 // print hex
125 for (int i=ibeg; i<=iend; i++) os << " " << RosPrintf(Buf8()[i],"x0", 2);
126 for (int i=0; i<igap; i++) os << " ";
127 // print ascii
128 os << " ";
129 for (int i=ibeg; i<=iend; i++) {
130 char c = char(Buf8()[i]);
131 if (c < 0x20 || c >= 0x7F) c = '.';
132 os << RosPrintf(char(c),"c");
133 }
134 os << endl;
135 ibeg += 16;
136 }
137
138 return;
139}
140
141} // end namespace Retro
ssize_t Read(int fd)
FIXME_docs.
Definition: RethBuf.cpp:71
~RethBuf()
Destructor.
Definition: RethBuf.cpp:57
static const size_t kCrcSize
size of ethernet CRC
Definition: RethBuf.hpp:70
static const size_t kMinSize
min ethernet frame size
Definition: RethBuf.hpp:69
void Dump(std::ostream &os, int ind=0, const char *text=0, int detail=0) const
FIXME_docs.
Definition: RethBuf.cpp:102
static const size_t kWOffTyp
offset type in 16 bit wrds
Definition: RethBuf.hpp:73
RethBuf()
Default constructor.
Definition: RethBuf.cpp:50
const uint8_t * Buf8() const
FIXME_docs.
Definition: RethBuf.ipp:76
uint8_t fBuf[kMaxSize+kCrcSize]
Definition: RethBuf.hpp:78
uint64_t MacDestination() const
FIXME_docs.
Definition: RethBuf.ipp:142
uint64_t MacSource() const
FIXME_docs.
Definition: RethBuf.ipp:150
static const size_t kWOffDstMac
offset dst mac in 16 bit wrds
Definition: RethBuf.hpp:71
static const size_t kWOffSrcMac
offset src mac in 16 bit wrds
Definition: RethBuf.hpp:72
static const size_t kMaxSize
max ethernet frame size
Definition: RethBuf.hpp:68
const uint16_t * Buf16() const
FIXME_docs.
Definition: RethBuf.ipp:84
std::string FrameInfo() const
FIXME_docs.
Definition: RethBuf.cpp:89
uint16_t Size() const
FIXME_docs.
Definition: RethBuf.ipp:60
ssize_t Write(int fd) const
FIXME_docs.
Definition: RethBuf.cpp:81
uint16_t fSize
Definition: RethBuf.hpp:77
uint16_t Type() const
FIXME_docs.
Definition: RethBuf.cpp:63
I/O appicator to generate fill characters.
Definition: RosFill.hpp:24
RosPrintfS< bool > RosPrintf(bool value, const char *form=0, int width=0, int prec=0)
Creates a print object for the formatted output of a bool value.
Definition: RosPrintf.ipp:38
std::string Mac2String(uint64_t mac)
FIXME_docs.
Definition: RethTools.cpp:34
Declaration of class ReventLoop.
Definition: ReventLoop.cpp:47