documented update
[gnutls.git] / doc / examples / ex-alert.c
blob6bc14562fe44d3fbb964a4523808d9bacafb491c
1 /* This example code is placed in the public domain. */
3 #ifdef HAVE_CONFIG_H
4 #include <config.h>
5 #endif
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <gnutls/gnutls.h>
11 #include "examples.h"
13 /* This function will check whether the given return code from
14 * a gnutls function (recv/send), is an alert, and will print
15 * that alert.
17 void
18 check_alert (gnutls_session_t session, int ret)
20 int last_alert;
22 if (ret == GNUTLS_E_WARNING_ALERT_RECEIVED
23 || ret == GNUTLS_E_FATAL_ALERT_RECEIVED)
25 last_alert = gnutls_alert_get (session);
27 /* The check for renegotiation is only useful if we are
28 * a server, and we had requested a rehandshake.
30 if (last_alert == GNUTLS_A_NO_RENEGOTIATION &&
31 ret == GNUTLS_E_WARNING_ALERT_RECEIVED)
32 printf ("* Received NO_RENEGOTIATION alert. "
33 "Client Does not support renegotiation.\n");
34 else
35 printf ("* Received alert '%d': %s.\n", last_alert,
36 gnutls_alert_get_name (last_alert));