]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
updated and included in the documentation the udp code.
authorNikos Mavrogiannopoulos <nmav@gnutls.org>
Wed, 28 Dec 2011 08:40:32 +0000 (10:40 +0200)
committerNikos Mavrogiannopoulos <nmav@gnutls.org>
Wed, 28 Dec 2011 14:08:55 +0000 (16:08 +0200)
doc/cha-gtls-examples.texi
doc/examples/udp.c

index 23f76100d89c8e647840fccaf1ef12a096d3631a..68230a9d33a03752d3f146f95a1df26589990051 100644 (file)
@@ -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
 
index 3eb567af5002ee712176dccdba7d1c1a63195219..0c48ac1b5b7ed8b9b4f8ae2c3a8861ebf6cb9805 100644 (file)
@@ -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");