You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You can extract common data types using helper methods:
100
+
101
+
*`.get_string`
102
+
*`.get_object_id` for SNMP OIDs such as 1.3.6.1.2.1
103
+
*`.get_hexstring` for a hex representation of the payload bytes
104
+
*`.get_bytes` for the raw byte data
105
+
*`.get_boolean`
106
+
*`.get_integer` returning an `Int64`
107
+
108
+
109
+
## Notes on IO
110
+
111
+
### Writing to Sockets
7
112
8
113
When writing SNMP messages to the socket, be aware that you should be buffering the write.
9
114
10
115
```crystal
11
116
12
117
session = SNMP::V3::Session.new
13
-
message = session.engine_id_probe
118
+
message = session.engine_validation_probe
14
119
15
-
# buffer the message
120
+
# Ensure sync is false so the message is buffered
16
121
socket.sync = false
17
122
socket.write_bytes message
123
+
124
+
# This requires you to call `flush`
18
125
socket.flush
19
126
20
127
```
@@ -23,3 +130,9 @@ This is because the call to `to_io` on message involves multiple writes to the I
23
130
as the message is progressively constructed. However you don't want each write to
24
131
be sending packets as this will result in a lot of overhead and most SNMP servers
25
132
will not accept fragmented messages.
133
+
134
+
135
+
### Reading from sockets
136
+
137
+
Whilst you'll probably be OK reading data like `socket.read_bytes(ASN1::BER)`
138
+
you should probably be buffering requests based on SNMP PDU Max Size (defaulting to 65507 bytes) and throwing away any buffered data that can't be read after buffering or a short timeout.
0 commit comments