summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/cha-gtls-examples.texi17
-rw-r--r--doc/examples/udp.c18
2 files changed, 26 insertions, 9 deletions
diff --git a/doc/cha-gtls-examples.texi b/doc/cha-gtls-examples.texi
index 23f76100d8..68230a9d33 100644
--- a/doc/cha-gtls-examples.texi
+++ b/doc/cha-gtls-examples.texi
@@ -29,7 +29,8 @@ implemented by another example.
* Client with Resume capability example::
* Simple client example with SRP authentication::
* Simple client example in C++::
-* Helper function for TCP connections::
+* Helper functions for TCP connections::
+* Helper functions for UDP connections::
@end menu
@node Simple client example with anonymous authentication
@@ -135,14 +136,22 @@ the GnuTLS C++ API.
@verbatiminclude examples/ex-cxx.cpp
-@node Helper function for TCP connections
-@subsection Helper function for TCP connections
+@node Helper functions for TCP connections
+@subsection Helper functions for TCP connections
-This helper function abstracts away TCP connection handling from the
+Those helper function abstract away TCP connection handling from the
other examples. It is required to build some examples.
@verbatiminclude examples/tcp.c
+@node Helper functions for UDP connections
+@subsection Helper functions for UDP connections
+
+The UDP helper functions abstract away UDP connection handling from the
+other examples. It is required to build the examples using UDP.
+
+@verbatiminclude examples/udp.c
+
@node Server examples
@section Server examples
diff --git a/doc/examples/udp.c b/doc/examples/udp.c
index 3eb567af50..0c48ac1b5b 100644
--- a/doc/examples/udp.c
+++ b/doc/examples/udp.c
@@ -13,9 +13,7 @@
#include <netinet/in.h>
#include <unistd.h>
-#define SA struct sockaddr
-
-/* tcp.c */
+/* udp.c */
int udp_connect (void);
void udp_close (int sd);
@@ -27,7 +25,7 @@ udp_connect (void)
{
const char *PORT = "5557";
const char *SERVER = "127.0.0.1";
- int err, sd;
+ int err, sd, optval;
struct sockaddr_in sa;
/* connects to server
@@ -39,7 +37,17 @@ udp_connect (void)
sa.sin_port = htons (atoi (PORT));
inet_pton (AF_INET, SERVER, &sa.sin_addr);
- err = connect (sd, (SA *) & sa, sizeof (sa));
+#if defined(IP_DONTFRAG)
+ optval = 1;
+ setsockopt (sd, IPPROTO_IP, IP_DONTFRAG,
+ (const void *) &optval, sizeof (optval));
+#elif defined(IP_MTU_DISCOVER)
+ optval = IP_PMTUDISC_DO;
+ setsockopt(sd, IPPROTO_IP, IP_MTU_DISCOVER,
+ (const void*) &optval, sizeof (optval));
+#endif
+
+ err = connect (sd, (struct sockaddr *) & sa, sizeof (sa));
if (err < 0)
{
fprintf (stderr, "Connect error\n");