From c279f32d5ffc41ab41a1441687dcb9daea5e6475 Mon Sep 17 00:00:00 2001 From: Nikos Mavrogiannopoulos Date: Wed, 28 Dec 2011 10:40:32 +0200 Subject: updated and included in the documentation the udp code. --- doc/cha-gtls-examples.texi | 17 +++++++++++++---- doc/examples/udp.c | 18 +++++++++++++----- 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 #include -#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"); -- cgit v1.2.1