NAME

upscli_connect - Open a connection to a NUT upsd

SYNOPSIS

Note
Two NUT websites

This version of the page reflects NUT release v2.8.0 with codebase commited ff16dabca at 2022-04-04T11:04:28+00:00

Options, features and capabilities in current development (and future releases) are detailed on the main site and may differ from ones described here.

#include <upsclient.h>
int upscli_connect(UPSCONN_t *ups, const char *host, uint16_t port, int flags);

DESCRIPTION

The upscli_connect() function takes the pointer ups to a UPSCONN_t state structure and opens a TCP connection to the host on the given port.

flags may be either UPSCLI_CONN_TRYSSL to try a SSL connection, or UPSCLI_CONN_REQSSL to require a SSL connection.

Introduced in version 2.7, an additional flag UPSCLI_CONN_CERTVERIF now exists to verify the signature offered during the SSL handshake. This flag should be used in conjunction with upscli_init(3) and/or upscli_add_host_cert(3) calls before connecting in order to define a CA certificate with which to verify.

If SSL mode is required, this function will only return successfully if it is able to establish a SSL connection with the server. Possible reasons for failure include no SSL support on the server, and if upsclient itself hasn’t been compiled with SSL support.

You must call upscli_disconnect(3) when finished with a connection, or your program will slowly leak memory and file descriptors.

RETURN VALUE

The upscli_connect() function modifies the UPSCONN_t structure and returns 0 on success, or -1 if an error occurs.

SEE ALSO