]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/snmp/Session.cc
4 * DEBUG: section 49 SNMP Interface
9 #include "base/TextException.h"
10 #include "ipc/TypedMsgHdr.h"
12 #include "snmp/Session.h"
15 Snmp::Session::Session()
20 Snmp::Session::Session(const Session
& session
)
25 Snmp::Session::~Session()
31 Snmp::Session::operator = (const Session
& session
)
39 Snmp::Session::clear()
41 xmemset(this, 0, sizeof(*this));
47 if (community_len
> 0) {
48 Must(community
!= NULL
);
57 Snmp::Session::assign(const Session
& session
)
59 memcpy(this, &session
, sizeof(*this));
60 if (session
.community
!= NULL
) {
61 community
= (u_char
*)xstrdup((char*)session
.community
);
62 Must(community
!= NULL
);
64 if (session
.peername
!= NULL
) {
65 peername
= xstrdup(session
.peername
);
66 Must(peername
!= NULL
);
71 Snmp::Session::pack(Ipc::TypedMsgHdr
& msg
) const
74 msg
.putInt(community_len
);
75 if (community_len
> 0) {
76 Must(community
!= NULL
);
77 msg
.putFixed(community
, community_len
);
81 int len
= peername
!= NULL
? strlen(peername
) : 0;
84 msg
.putFixed(peername
, len
);
85 msg
.putPod(remote_port
);
86 msg
.putPod(local_port
);
90 Snmp::Session::unpack(const Ipc::TypedMsgHdr
& msg
)
94 community_len
= msg
.getInt();
95 if (community_len
> 0) {
96 community
= static_cast<u_char
*>(xmalloc(community_len
+ 1));
97 Must(community
!= NULL
);
98 msg
.getFixed(community
, community_len
);
99 community
[community_len
] = 0;
103 int len
= msg
.getInt();
105 peername
= static_cast<char*>(xmalloc(len
+ 1));
106 Must(peername
!= NULL
);
107 msg
.getFixed(peername
, len
);
110 msg
.getPod(remote_port
);
111 msg
.getPod(local_port
);