xref: /freebsd/contrib/bsnmp/lib/bsnmpclient.3 (revision 4b15965daa99044daf184221b7c283bf7f2d7e66)
1.\"
2.\" Copyright (c) 2004-2005
3.\"	Hartmut Brandt.
4.\"	All rights reserved.
5.\" Copyright (c) 2001-2003
6.\"	Fraunhofer Institute for Open Communication Systems (FhG Fokus).
7.\"	All rights reserved.
8.\"
9.\" Author: Harti Brandt <harti@FreeBSD.org>
10.\"
11.\" Redistribution and use in source and binary forms, with or without
12.\" modification, are permitted provided that the following conditions
13.\" are met:
14.\" 1. Redistributions of source code must retain the above copyright
15.\"    notice, this list of conditions and the following disclaimer.
16.\" 2. Redistributions in binary form must reproduce the above copyright
17.\"    notice, this list of conditions and the following disclaimer in the
18.\"    documentation and/or other materials provided with the distribution.
19.\"
20.\" THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23.\" ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30.\" SUCH DAMAGE.
31.\"
32.\" $Begemot: bsnmp/lib/bsnmpclient.3,v 1.12 2005/10/04 08:46:50 brandt_h Exp $
33.\"
34.Dd June 24, 2025
35.Dt BSNMPCLIENT 3
36.Os
37.Sh NAME
38.Nm snmp_client ,
39.Nm snmp_client_init ,
40.Nm snmp_client_set_host ,
41.Nm snmp_client_set_port ,
42.Nm snmp_send_cb_f ,
43.Nm snmp_timeout_cb_f ,
44.Nm snmp_timeout_start_f ,
45.Nm snmp_timeout_stop_f ,
46.Nm snmp_open ,
47.Nm snmp_close ,
48.Nm snmp_pdu_create ,
49.Nm snmp_add_binding ,
50.Nm snmp_pdu_check ,
51.Nm snmp_pdu_send ,
52.Nm snmp_oid_append ,
53.Nm snmp_parse_server ,
54.Nm snmp_receive ,
55.Nm snmp_table_cb_f ,
56.Nm snmp_table_fetch ,
57.Nm snmp_table_fetch_async ,
58.Nm snmp_dialog ,
59.Nm snmp_discover_engine
60.Nd "SNMP client library"
61.Sh LIBRARY
62Begemot SNMP library
63.Pq libbsnmp, -lbsnmp
64.Sh SYNOPSIS
65.In asn1.h
66.In snmp.h
67.In snmpclient.h
68.Ft typedef void
69.Fn (*snmp_send_cb_f) "struct snmp_pdu *req" "struct snmp_pdu *resp" "void *uarg"
70.Ft typedef void
71.Fn (*snmp_timeout_cb_f) "void *uarg"
72.Ft typedef void *
73.Fn (*snmp_timeout_start_f) "struct timeval *timeout" "snmp_timeout_cb_f callback" "void *uarg"
74.Ft typedef void
75.Fn (*snmp_timeout_stop_f) "void *timeout_id"
76.Vt extern struct snmp_client snmp_client ;
77.Ft void
78.Fn snmp_client_init "struct snmp_client *client"
79.Ft int
80.Fn snmp_client_set_host "struct snmp_client *client" "const char *host"
81.Ft int
82.Fn snmp_client_set_port "struct snmp_client *client" "const char *port"
83.Ft int
84.Fn snmp_open "const char *host" "const char *port" "const char *read_community" "const char *write_community"
85.Ft void
86.Fn snmp_close "void"
87.Ft void
88.Fn snmp_pdu_create "struct snmp_pdu *pdu" "u_int op"
89.Ft int
90.Fn snmp_add_binding "struct snmp_pdu *pdu" "..."
91.Ft int
92.Fn snmp_pdu_check "const struct snmp_pdu *req" "const struct snmp_pdu *resp"
93.Ft int32_t
94.Fn snmp_pdu_send "struct snmp_pdu *pdu" "snmp_send_cb_f func" "void *uarg"
95.Ft int
96.Fn snmp_oid_append "struct asn_oid *oid" "const char *fmt" "..."
97.Ft int
98.Fn snmp_parse_server "struct snmp_client *sc" "const char *str"
99.Ft int
100.Fn snmp_receive "int blocking"
101.Ft typedef void
102.Fn (*snmp_table_cb_f) "void *list" "void *arg" "int res"
103.Ft int
104.Fn snmp_table_fetch "const struct snmp_table *descr" "void *list"
105.Ft int
106.Fn snmp_table_fetch_async "const struct snmp_table *descr" "void *list" "snmp_table_cb_f callback" "void *uarg"
107.Ft int
108.Fn snmp_dialog "struct snmp_pdu *req" "struct snmp_pdu *resp"
109.Ft int
110.Fn snmp_discover_engine "void"
111.Sh DESCRIPTION
112The SNMP library contains routines to easily build SNMP client applications
113that use SNMP versions 1, 2 or 3.
114Most of the routines use a
115.Vt struct snmp_client :
116.Bd -literal -offset indent
117struct snmp_client {
118	enum snmp_version	version;
119	int			trans;	/* which transport to use */
120
121	/* these two are read-only for the application */
122	char			*cport;	/* port number as string */
123	char			*chost;	/* host name or IP address as string */
124
125	char			read_community[SNMP_COMMUNITY_MAXLEN + 1];
126	char			write_community[SNMP_COMMUNITY_MAXLEN + 1];
127
128	/* SNMPv3 specific fields */
129	int32_t			identifier;
130	int32_t			security_model;
131	struct snmp_engine	engine;
132	struct snmp_user	user;
133
134	/* SNMPv3 Access control - VACM*/
135	uint32_t		clen;
136	uint8_t			cengine[SNMP_ENGINE_ID_SIZ];
137	char			cname[SNMP_CONTEXT_NAME_SIZ];
138
139	struct timeval		timeout;
140	u_int			retries;
141
142	int			dump_pdus;
143
144	size_t			txbuflen;
145	size_t			rxbuflen;
146
147	int			fd;
148
149	int32_t			next_reqid;
150	int32_t			max_reqid;
151	int32_t			min_reqid;
152
153	char			error[SNMP_STRERROR_LEN];
154
155	snmp_timeout_start_f	timeout_start;
156	snmp_timeout_stop_f	timeout_stop;
157
158	char			local_path[SUNPATHLEN];
159};
160.Ed
161.Pp
162The fields of this structure are described below.
163.Bl -tag -width "timeout_start"
164.It Va version
165This is the version of SNMP to use.
166See
167.Xr bsnmplib 3
168for applicable values.
169The default version is
170.Li SNMP_V2c .
171.It Va trans
172If this is
173.Dv SNMP_TRANS_LOC_DGRAM
174a local datagram socket is used.
175If it is
176.Dv SNMP_TRANS_LOC_STREAM
177a local stream socket is used.
178For
179.Dv SNMP_TRANS_UDP
180a UDPv4 socket and for
181.Dv SNMP_TRANS_UDP6
182a UDPv6 socket is created.
183It uses the
184.Va chost
185field as the path to the server's socket for local sockets.
186.It Va cport
187The SNMP agent's UDP port number.
188This may be a symbolic port number (from
189.Pa /etc/services )
190or a numeric port number.
191If this field is
192.Li NULL
193(the default) the standard SNMP port is used.
194This field should not be changed directly but rather by calling
195.Fn snmp_client_set_port .
196.It Va chost
197The SNMP agent's host name, IP address or
198.Ux
199domain socket path name.
200If this is
201.Li NULL
202(the default)
203.Li localhost
204is assumed.
205This field should not be changed directly but rather through calling
206.Fn snmp_client_set_host .
207.It Va read_community
208This is the community name to be used for all requests except SET requests.
209The default is
210.Sq public .
211.It Va write_community
212The community name to be used for SET requests.
213The default is
214.Sq private .
215.It Va identifier
216The message identifier value to be used with SNMPv3 PDUs. Incremented with
217each transmitted PDU.
218.It Va security_model
219The security model to be used with SNMPv3 PDUs. Currently only User-Based
220Security model specified by RFC 3414 (value 3) is supported.
221.It Va engine
222The authoritive SNMP engine parameters to be used with SNMPv3 PDUs.
223.It Va user
224The USM SNMP user credentials to be used with SNMPv3 PDUs.
225.It Va clen
226The length of the context engine id to be used with SNMPv3 PDUs.
227.It Va cengine
228The context engine id to be used with SNMPv3 PDUs. Default is empty.
229.It Va cname
230The context name to be used with SNMPv3 PDUs. Default is
231.Sq "" .
232.It Va timeout
233The maximum time to wait for responses to requests.
234If the time elapses, the request is resent up to
235.Va retries
236times.
237The default is 3 seconds.
238.It Va retries
239Number of times a request PDU is to be resent.
240If set to 0, the request is sent only once.
241The default is 3 retransmissions.
242.It Va dump_pdus
243If set to a non-zero value all received and sent PDUs are dumped via
244.Xr snmp_pdu_dump 3 .
245The default is not to dump PDUs.
246.It Va txbuflen
247The encoding buffer size to be allocated for transmitted PDUs.
248The default is 10000 octets.
249.It Va rxbuflen
250The decoding buffer size to be allocated for received PDUs.
251This is the size of the maximum PDU that can be received.
252The default is 10000 octets.
253.It Va fd
254After calling
255.Fn snmp_open
256this is the file socket file descriptor used for sending and receiving PDUs.
257.It Va next_reqid
258The request id of the next PDU to send.
259Used internal by the library.
260.It Va max_reqid
261The maximum request id to use for outgoing PDUs.
262The default is
263.Li INT32_MAX .
264.It Va min_reqid
265The minimum request id to use for outgoing PDUs.
266Request ids are allocated linearily starting at
267.Va min_reqid
268up to
269.Va max_reqid .
270.It Va error
271If an error happens, this field is set to a printable string describing the
272error.
273.It Va timeout_start
274This field must point to a function setting up a one shot timeout.
275After the timeout has elapsed, the given callback function must be called
276with the user argument.
277The
278.Fn timeout_start
279function must return a
280.Vt void *
281identifying the timeout.
282.It Va timeout_stop
283This field must be set to a function that stops a running timeout.
284The function will be called with the return value of the corresponding
285.Fn timeout_start
286function.
287.It Va local_path
288In local socket mode, optional path name the client socket shall be bound to
289before connecting to the server.
290For
291.Dv SOCK_STREAM
292local socket the named path is optional, and library will skip
293.Xr bind 2
294if path is not provided.
295For
296.Dv SOCK_DGRAM
297local socket the named path is required, thus library will create a random
298one in
299.Pa /tmp
300if path is not provided.
301.El
302.Pp
303In the current implementation there is a global variable
304.Pp
305.D1 Vt extern struct snmp_client snmp_client ;
306.Pp
307that is used by all the library functions.
308The first call into the library must be a call to
309.Fn snmp_client_init
310to initialize this global variable to the default values.
311After this call and before calling
312.Fn snmp_open
313the fields of the variable may be modified by the user.
314The modification of the
315.Va chost
316and
317.Va cport
318fields should be done only via the functions
319.Fn snmp_client_set_host
320and
321.Fn snmp_client_set_port .
322.Pp
323The function
324.Fn snmp_open
325creates a UDP or
326.Ux
327domain socket and connects it to the agent's IP address and port.
328If any of the arguments of the call is not
329.Li NULL
330the corresponding field in the global
331.Va snmp_client
332is set from the argument.
333Otherwise the values that are already in that variable are used.
334The function
335.Fn snmp_close
336closes the socket, stops all timeouts and frees all dynamically allocated
337resources.
338.Pp
339The next three functions are used to create request PDUs.
340The function
341.Fn snmp_pdu_create
342initializes a PDU of type
343.Va op .
344It does not allocate space for the PDU itself.
345This is the responsibility of the caller.
346.Fn snmp_add_binding
347adds bindings to the PDU and returns the (zero based) index of the first new
348binding.
349The arguments are pairs of pointer to the OIDs and syntax constants,
350terminated by a NULL.
351The call
352.Bd -literal -offset indent
353snmp_add_binding(&pdu,
354    &oid1, SNMP_SYNTAX_INTEGER,
355    &oid2, SNMP_SYNTAX_OCTETSTRING,
356    NULL);
357.Ed
358.Pp
359adds two new bindings to the PDU and returns the index of the first one.
360It is the responsibility of the caller to set the value part of the binding
361if necessary.
362The functions returns -1 if the maximum number of bindings is exhausted.
363The function
364.Fn snmp_oid_append
365can be used to construct variable OIDs for requests.
366It takes a pointer to an
367.Vt struct asn_oid
368that is to be constructed, a format string, and a number of arguments
369the type of which depends on the format string.
370The format string is interpreted
371character by character in the following way:
372.Bl -tag -width ".It Li ( Va N Ns Li )"
373.It Li i
374This format expects an argument of type
375.Vt asn_subid_t
376and appends this as a single integer to the OID.
377.It Li a
378This format expects an argument of type
379.Vt struct in_addr
380and appends to four parts of the IP address to the OID.
381.It Li s
382This format expects an argument of type
383.Vt const char *
384and appends the length of the string (as computed by
385.Xr strlen 3 )
386and each of the characters in the string to the OID.
387.It ( Va N Ns )
388This format expects no argument.
389.Va N
390must be a decimal number and is stored into an internal variable
391.Va size .
392.It Li b
393This format expects an argument of type
394.Vt const char *
395and appends
396.Va size
397characters from the string to the OID.
398The string may contain
399.Li NUL
400characters.
401.It Li c
402This format expects two arguments: one of type
403.Vt size_t
404and one of type
405.Vt const u_char * .
406The first argument gives the number of bytes to append to the OID from the string
407pointed to by the second argument.
408.El
409.Pp
410The function
411.Fn snmp_pdu_check
412may be used to check a response PDU.
413A number of checks are performed
414(error code, equal number of bindings, syntaxes and values for SET PDUs).
415The function returns +1 if everything is ok, 0 if a NOSUCHNAME or similar
416error was detected, -1 if the response PDU had fatal errors
417and -2 if
418.Fa resp
419is
420.Li NULL
421(a timeout occurred).
422.Pp
423The function
424.Fn snmp_pdu_send
425encodes and sends the given PDU.
426It records the PDU together with the callback
427and user pointers in an internal list and arranges for retransmission if no
428response is received.
429When a response is received or the retransmission count
430is exceeded the callback
431.Fa func
432is called with the original request PDU, the response PDU and the user argument
433.Fa uarg .
434If the retransmit count is exceeded,
435.Fa func
436is called with the original request PDU, the response pointer set to
437.Li NULL
438and the user argument
439.Fa uarg .
440The caller should not free the request PDU until the callback function is
441called.
442The callback function must free the request PDU and the response PDU (if not
443.Li NULL ).
444.Pp
445The function
446.Fn snmp_receive
447tries to receive a PDU.
448If the argument is zero, the function polls to see
449whether a packet is available, if the argument is non-zero, the function blocks
450until the next packet is received.
451The packet is delivered via the usual callback
452mechanism (non-response packets are silently dropped).
453The function returns 0, if a packet was received and successfully dispatched,
454-1 if an error occurred or no packet was available (in polling mode).
455.Pp
456The next two functions are used to retrieve tables from SNMP agents.
457They use
458the following input structure, that describes the table:
459.Bd -literal -offset indent
460struct snmp_table {
461	struct asn_oid		table;
462	struct asn_oid		last_change;
463	u_int			max_iter;
464	size_t			entry_size;
465	u_int			index_size;
466	uint64_t		req_mask;
467
468	struct snmp_table_entry {
469	    asn_subid_t		subid;
470	    enum snmp_syntax	syntax;
471	    off_t		offset;
472	}			entries[];
473};
474.Ed
475.Pp
476The fields of this structure have the following meaning:
477.Bl -tag -width "last_change"
478.It Va table
479This is the base OID of the table.
480.It Va last_change
481Some tables have a scalar variable of type TIMETICKS attached to them,
482that holds the time when the table was last changed.
483This OID should be the OID of this variable (without the \&.0 index).
484When the table is retrieved
485with multiple GET requests, and the variable changes between two request,
486the table fetch is restarted.
487.It Va max_iter
488Maximum number of tries to fetch the table.
489.It Va entry_size
490The table fetching routines return a list of structures one for each table
491row.
492This variable is the size of one structure and used to
493.Xr malloc 3
494the structure.
495.It Va index_size
496This is the number of index columns in the table.
497.It Va req_mask
498This is a bit mask with a 1 for each table column that is required.
499Bit 0 corresponds to the first element (index 0) in the array
500.Va entries ,
501bit 1 to the second (index 1) and so on.
502SNMP tables may be sparse.
503For sparse columns the bit should not be set.
504If the bit for a given column is set and
505the column value cannot be retrieved for a given row, the table fetch is
506restarted assuming that the table is currently being modified by the agent.
507The bits for the index columns are ignored.
508.It Va entries
509This is a variable sized array of column descriptors.
510This array is terminated by an element with syntax
511.Li SNMP_SYNTAX_NULL .
512The first
513.Va index_size
514elements describe all the index columns of the table, the rest are normal
515columns.
516If for the column at
517.Ql entries[N]
518the expression
519.Ql req_mask & (1 << N)
520yields true, the column is considered a required column.
521The fields of this the array elements have the following meaning:
522.Bl -tag -width "syntax"
523.It Va subid
524This is the OID subid of the column.
525This is ignored for index entries.
526Index entries are decoded according to the
527.Va syntax
528field.
529.It Va syntax
530This is the syntax of the column or index.
531A syntax of
532.Li SNMP_SYNTAX_NULL
533terminates the array.
534.It Va offset
535This is the starting offset of the value of the column in the return structures.
536This field can be set with the ISO-C
537.Fn offsetof
538macro.
539.El
540.El
541.Pp
542Both table fetching functions return TAILQ (see
543.Xr queue 3 )
544of structures--one for each table row.
545These structures must start with a
546.Fn TAILQ_ENTRY
547and a
548.Vt uint64_t
549and are allocated via
550.Xr malloc 3 .
551The
552.Fa list
553argument of the table functions must point to a
554.Fn TAILQ_HEAD .
555The
556.Vt uint64_t
557fields, usually called
558.Va found
559is used to indicate which of the columns have been found for the given
560row.
561It is encoded like the
562.Fa req_mask
563field.
564.Pp
565The function
566.Fn snmp_table_fetch
567synchronously fetches the given table.
568If everything is ok 0 is returned.
569Otherwise the function returns -1 and sets an appropriate error string.
570The function
571.Fn snmp_table_fetch_async
572fetches the tables asynchronously.
573If either the entire table is fetch, or
574an error occurs the callback function
575.Fa callback
576is called with the callers arguments
577.Fa list
578and
579.Fa uarg
580and a parameter that is either 0 if the table was fetched, or
581-1 if there was an error.
582The function itself returns -1 if it could not
583initialize fetching of the table.
584.Pp
585The following table description is used to fetch the ATM interface table:
586.Bd -literal -offset indent
587/*
588 * ATM interface table
589 */
590struct atmif {
591	TAILQ_ENTRY(atmif) link;
592	uint64_t	found;
593	int32_t		index;
594	u_char		*ifname;
595	size_t		ifnamelen;
596	uint32_t	node_id;
597	uint32_t	pcr;
598	int32_t		media;
599	uint32_t	vpi_bits;
600	uint32_t	vci_bits;
601	uint32_t	max_vpcs;
602	uint32_t	max_vccs;
603	u_char		*esi;
604	size_t		esilen;
605	int32_t		carrier;
606};
607TAILQ_HEAD(atmif_list, atmif);
608
609/* list of all ATM interfaces */
610struct atmif_list atmif_list;
611
612static const struct snmp_table atmif_table = {
613	OIDX_begemotAtmIfTable,
614	OIDX_begemotAtmIfTableLastChange, 2,
615	sizeof(struct atmif),
616	1, 0x7ffULL,
617	{
618	  { 0, SNMP_SYNTAX_INTEGER,
619		offsetof(struct atmif, index) },
620	  { 1, SNMP_SYNTAX_OCTETSTRING,
621		offsetof(struct atmif, ifname) },
622	  { 2, SNMP_SYNTAX_GAUGE,
623		offsetof(struct atmif, node_id) },
624	  { 3, SNMP_SYNTAX_GAUGE,
625		offsetof(struct atmif, pcr) },
626	  { 4, SNMP_SYNTAX_INTEGER,
627		offsetof(struct atmif, media) },
628	  { 5, SNMP_SYNTAX_GAUGE,
629		offsetof(struct atmif, vpi_bits) },
630	  { 6, SNMP_SYNTAX_GAUGE,
631		offsetof(struct atmif, vci_bits) },
632	  { 7, SNMP_SYNTAX_GAUGE,
633		offsetof(struct atmif, max_vpcs) },
634	  { 8, SNMP_SYNTAX_GAUGE,
635		offsetof(struct atmif, max_vccs) },
636	  { 9, SNMP_SYNTAX_OCTETSTRING,
637		offsetof(struct atmif, esi) },
638	  { 10, SNMP_SYNTAX_INTEGER,
639		offsetof(struct atmif, carrier) },
640          { 0, SNMP_SYNTAX_NULL, 0 }
641	}
642};
643
644\&...
645	if (snmp_table_fetch(&atmif_table, &atmif_list) != 0)
646		errx(1, "AtmIf table: %s", snmp_client.error);
647\&...
648.Ed
649.Pp
650The function
651.Fn snmp_dialog
652is used to execute a synchonuous dialog with the agent.
653The request PDU
654.Fa req
655is sent and the function blocks until the response PDU is received.
656Note,
657that asynchonuous receives are handled (i.e. callback functions of other send
658calls or table fetches may be called while in the function).
659The response PDU is returned in
660.Fa resp .
661If no response could be received after all timeouts and retries, the function
662returns -1.
663If a response was received 0 is returned.
664.Pp
665The function
666.Fn snmp_discover_engine
667is used to discover the authoritative snmpEngineId of a remote SNMPv3 agent.
668A request PDU with empty USM user name is sent and the client's engine
669parameters are set according to the snmpEngine parameters received in the
670response PDU.
671If the client is configured to use authentication and/or privacy and the
672snmpEngineBoots and/or snmpEngineTime in the response had zero values, an
673additional request (possibly encrypted) with the appropriate user credentials
674is sent to fetch the missing values.
675Note, that the function blocks until the discovery process is completed.
676If no response could be received after all timeouts and retries, or the
677response contained errors the function returns -1.
678If the discovery process was completed 0 is returned.
679.Pp
680The function
681.Fn snmp_parse_server
682is used to parse an SNMP server specification string and fill in the
683fields of a
684.Vt struct snmp_client .
685The syntax of a server specification is
686.Pp
687.D1 [trans::][community@][server][:port]
688.Pp
689where
690.Va trans
691is the transport name (one of
692.Qq udp ,
693.Qq udp6 ,
694.Qq stream
695or
696.Qq dgram ) ,
697.Va community
698is the string to be used for both the read and the write community,
699.Va server
700is the server's host name in case of UDP and the path name in case
701of a local socket, and
702.Va port
703is the port in case of UDP transport.
704The function returns 0 in the case of success and return -1 and sets
705the error string in case of an error.
706.Pp
707The function
708.Fn snmp_parse_serverr
709fills the transport, the port number and the community strings with
710reasonable default values when they are not specified.
711The default transport
712is
713.Dv SNMP_TRANS_UDP .
714If the host name contains a slash the default is modified to
715.Dv SNMP_TRANS_LOC_DGRAM .
716If the host name looks like a numeric IPv6 address the default is
717.Dv SNMP_TRANS_UDP6 .
718For numeric IPv6 addresses the transport name udp is automatically
719translated as
720.Dv SNMP_TRANS_UDP6 .
721The default port number (for
722.Dv udp
723or
724.Dv udp6 )
725is
726.Qq snmp .
727The default read community is
728.Qq public
729and the default write community
730.Qq private .
731.Pp
732.Fn snmp_parse_server
733recognizes path names, host names and numerical IPv4 and IPv6 addresses.
734A string consisting of digits and periods is assumed to be an IPv4 address
735and must be parseable by
736.Fn inet_aton 3 .
737An IPv6 address is any string enclosed in square brackets.
738It must be parseable with
739.Fn gethostinfo 3 .
740.Pp
741The port number for
742.Fn snmp_parse_server
743can be specified numerically or symbolically.
744It is ignored for local sockets.
745.Sh DIAGNOSTICS
746If an error occurs in any of the functions an error indication as described
747above is returned.
748Additionally the function sets a printable error string in the
749.Va error
750field of
751.Va snmp_client .
752.Sh SEE ALSO
753.Xr gensnmptree 1 ,
754.Xr bsnmpd 1 ,
755.Xr bsnmpagent 3 ,
756.Xr bsnmplib 3
757.Sh STANDARDS
758This implementation conforms to the applicable IETF RFCs and ITU-T
759recommendations.
760.Sh AUTHORS
761.An Hartmut Brandt Aq harti@FreeBSD.org
762.An Kendy Kutzner Aq kutzner@fokus.gmd.de
763