bsd_socket_options.c
Go to the documentation of this file.
1 /**
2  * @file bsd_socket_options.c
3  * @brief BSD socket options
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2024 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneTCP Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 2.4.2
29  **/
30 
31 //Switch to the appropriate trace level
32 #define TRACE_LEVEL BSD_SOCKET_TRACE_LEVEL
33 
34 //Dependencies
35 #include "core/net.h"
36 #include "core/bsd_socket.h"
37 #include "core/bsd_socket_misc.h"
38 #include "debug.h"
39 
40 //Check TCP/IP stack configuration
41 #if (BSD_SOCKET_SUPPORT == ENABLED)
42 
43 //Dependencies
45 
46 
47 /**
48  * @brief Set SO_REUSEADDR option
49  * @param[in] socket Handle referencing the socket
50  * @param[in] optval A pointer to the buffer in which the value for the
51  * requested option is specified
52  * @param[in] optlen The size, in bytes, of the buffer pointed to by the optval
53  * parameter
54  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
55  **/
56 
58  socklen_t optlen)
59 {
60  int_t ret;
61 
62  //Check the length of the option
63  if(optlen >= (socklen_t) sizeof(int_t))
64  {
65  //Get exclusive access
67 
68  //This option specifies whether the socket can be bound to an address
69  //which is already in use
70  if(*optval != 0)
71  {
72  socket->options |= SOCKET_OPTION_REUSE_ADDR;
73  }
74  else
75  {
76  socket->options &= ~SOCKET_OPTION_REUSE_ADDR;
77  }
78 
79  //Release exclusive access
81 
82  //Successful processing
83  ret = SOCKET_SUCCESS;
84  }
85  else
86  {
87  //The option length is not valid
89  ret = SOCKET_ERROR;
90  }
91 
92  //Return status code
93  return ret;
94 }
95 
96 
97 /**
98  * @brief Set SO_BROADCAST option
99  * @param[in] socket Handle referencing the socket
100  * @param[in] optval A pointer to the buffer in which the value for the
101  * requested option is specified
102  * @param[in] optlen The size, in bytes, of the buffer pointed to by the optval
103  * parameter
104  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
105  **/
106 
108  socklen_t optlen)
109 {
110  int_t ret;
111 
112  //Check the length of the option
113  if(optlen >= (socklen_t) sizeof(int_t))
114  {
115  //This option specifies whether transmission and receipt of broadcast
116  //messages are allowed
117  socketEnableBroadcast(socket, *optval);
118 
119  //Successful processing
120  ret = SOCKET_SUCCESS;
121  }
122  else
123  {
124  //The option length is not valid
126  ret = SOCKET_ERROR;
127  }
128 
129  //Return status code
130  return ret;
131 }
132 
133 
134 /**
135  * @brief Set SO_SNDTIMEO option
136  * @param[in] socket Handle referencing the socket
137  * @param[in] optval A pointer to the buffer in which the value for the
138  * requested option is specified
139  * @param[in] optlen The size, in bytes, of the buffer pointed to by the optval
140  * parameter
141  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
142  **/
143 
145  socklen_t optlen)
146 {
147  int_t ret;
148 
149  //Check the length of the option
150  if(optlen >= (socklen_t) sizeof(struct timeval))
151  {
152  //If the specified value is of zero, I/O operations shall not time out
153  if(optval->tv_sec == 0 && optval->tv_usec == 0)
154  {
156  }
157  else
158  {
159  socketSetTimeout(socket, optval->tv_sec * 1000 + optval->tv_usec / 1000);
160  }
161 
162  //Successful processing
163  ret = SOCKET_SUCCESS;
164  }
165  else
166  {
167  //The option length is not valid
169  ret = SOCKET_ERROR;
170  }
171 
172  //Return status code
173  return ret;
174 }
175 
176 
177 /**
178  * @brief Set SO_RCVTIMEO option
179  * @param[in] socket Handle referencing the socket
180  * @param[in] optval A pointer to the buffer in which the value for the
181  * requested option is specified
182  * @param[in] optlen The size, in bytes, of the buffer pointed to by the optval
183  * parameter
184  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
185  **/
186 
188  socklen_t optlen)
189 {
190  int_t ret;
191 
192  //Check the length of the option
193  if(optlen >= (socklen_t) sizeof(struct timeval))
194  {
195  //If the specified value is of zero, I/O operations shall not time out
196  if(optval->tv_sec == 0 && optval->tv_usec == 0)
197  {
199  }
200  else
201  {
202  socketSetTimeout(socket, optval->tv_sec * 1000 + optval->tv_usec / 1000);
203  }
204 
205  //Successful processing
206  ret = SOCKET_SUCCESS;
207  }
208  else
209  {
210  //The option length is not valid
212  ret = SOCKET_ERROR;
213  }
214 
215  //Return status code
216  return ret;
217 }
218 
219 
220 /**
221  * @brief Set SO_SNDBUF option
222  * @param[in] socket Handle referencing the socket
223  * @param[in] optval A pointer to the buffer in which the value for the
224  * requested option is specified
225  * @param[in] optlen The size, in bytes, of the buffer pointed to by the optval
226  * parameter
227  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
228  **/
229 
231  socklen_t optlen)
232 {
233  int_t ret;
234 
235 #if (TCP_SUPPORT == ENABLED)
236 //Check the length of the option
237  if(optlen >= (socklen_t) sizeof(int_t))
238  {
239  //Adjust the size of the send buffer
240  socketSetTxBufferSize(socket, *optval);
241  //Successful processing
242  ret = SOCKET_SUCCESS;
243  }
244  else
245  {
246  //The option length is not valid
248  ret = SOCKET_ERROR;
249  }
250 #else
251  //TCP is not supported
253  ret = SOCKET_ERROR;
254 #endif
255 
256  //Return status code
257  return ret;
258 }
259 
260 
261 /**
262  * @brief Set SO_RCVBUF option
263  * @param[in] socket Handle referencing the socket
264  * @param[in] optval A pointer to the buffer in which the value for the
265  * requested option is specified
266  * @param[in] optlen The size, in bytes, of the buffer pointed to by the optval
267  * parameter
268  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
269  **/
270 
272  socklen_t optlen)
273 {
274  int_t ret;
275 
276 #if (TCP_SUPPORT == ENABLED)
277  //Check the length of the option
278  if(optlen >= (socklen_t) sizeof(int_t))
279  {
280  //Adjust the size of the receive buffer
281  socketSetRxBufferSize(socket, *optval);
282  //Successful processing
283  ret = SOCKET_SUCCESS;
284  }
285  else
286  {
287  //The option length is not valid
289  ret = SOCKET_ERROR;
290  }
291 #else
292  //TCP is not supported
294  ret = SOCKET_ERROR;
295 #endif
296 
297  //Return status code
298  return ret;
299 }
300 
301 
302 /**
303  * @brief Set SO_KEEPALIVE option
304  * @param[in] socket Handle referencing the socket
305  * @param[in] optval A pointer to the buffer in which the value for the
306  * requested option is specified
307  * @param[in] optlen The size, in bytes, of the buffer pointed to by the optval
308  * parameter
309  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
310  **/
311 
313  socklen_t optlen)
314 {
315  int_t ret;
316 
317 #if (TCP_SUPPORT == ENABLED && TCP_KEEP_ALIVE_SUPPORT == ENABLED)
318  //Check the length of the option
319  if(optlen >= (socklen_t) sizeof(int_t))
320  {
321  //This option specifies whether TCP keep-alive is enabled
322  socketEnableKeepAlive(socket, *optval);
323  //Successful processing
324  ret = SOCKET_SUCCESS;
325  }
326  else
327  {
328  //The option length is not valid
330  ret = SOCKET_ERROR;
331  }
332 #else
333  //TCP keep-alive is not supported
335  ret = SOCKET_ERROR;
336 #endif
337 
338  //Return status code
339  return ret;
340 }
341 
342 
343 /**
344  * @brief Set IP_TOS option
345  * @param[in] socket Handle referencing the socket
346  * @param[in] optval A pointer to the buffer in which the value for the
347  * requested option is specified
348  * @param[in] optlen The size, in bytes, of the buffer pointed to by the optval
349  * parameter
350  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
351  **/
352 
354  socklen_t optlen)
355 {
356  int_t ret;
357 
358 #if (IPV4_SUPPORT == ENABLED)
359  //Check the length of the option
360  if(optlen >= (socklen_t) sizeof(int_t))
361  {
362  //Save ToS value
363  socket->tos = *optval & 0xFF;
364  //Successful processing
365  ret = SOCKET_SUCCESS;
366  }
367  else
368  {
369  //The option length is not valid
371  ret = SOCKET_ERROR;
372  }
373 #else
374  //IPv4 is not supported
376  ret = SOCKET_ERROR;
377 #endif
378 
379  //Return status code
380  return ret;
381 }
382 
383 
384 /**
385  * @brief Set IP_TTL option
386  * @param[in] socket Handle referencing the socket
387  * @param[in] optval A pointer to the buffer in which the value for the
388  * requested option is specified
389  * @param[in] optlen The size, in bytes, of the buffer pointed to by the optval
390  * parameter
391  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
392  **/
393 
395  socklen_t optlen)
396 {
397  int_t ret;
398 
399 #if (IPV4_SUPPORT == ENABLED)
400  //Check the length of the option
401  if(optlen >= (socklen_t) sizeof(int_t))
402  {
403  //This option specifies the TTL value associated with an IPv4 socket
404  //for unicast traffic
405  socket->ttl = *optval;
406 
407  //Successful processing
408  ret = SOCKET_SUCCESS;
409  }
410  else
411  {
412  //The option length is not valid
414  ret = SOCKET_ERROR;
415  }
416 #else
417  //IPv4 is not supported
419  ret = SOCKET_ERROR;
420 #endif
421 
422  //Return status code
423  return ret;
424 }
425 
426 
427 /**
428  * @brief Set IP_MULTICAST_IF option
429  * @param[in] socket Handle referencing the socket
430  * @param[in] optval A pointer to the buffer in which the value for the
431  * requested option is specified
432  * @param[in] optlen The size, in bytes, of the buffer pointed to by the optval
433  * parameter
434  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
435  **/
436 
438  const struct in_addr *optval, socklen_t optlen)
439 {
440  int_t ret;
441 
442 #if (IPV4_SUPPORT == ENABLED)
443  //Check the length of the option
444  if(optlen >= (socklen_t) sizeof(struct in_addr))
445  {
446  //Successful processing
447  ret = SOCKET_SUCCESS;
448  }
449  else
450  {
451  //The option length is not valid
453  ret = SOCKET_ERROR;
454  }
455 #else
456  //IPv4 is not supported
458  ret = SOCKET_ERROR;
459 #endif
460 
461  //Return status code
462  return ret;
463 }
464 
465 
466 /**
467  * @brief Set IP_MULTICAST_TTL option
468  * @param[in] socket Handle referencing the socket
469  * @param[in] optval A pointer to the buffer in which the value for the
470  * requested option is specified
471  * @param[in] optlen The size, in bytes, of the buffer pointed to by the optval
472  * parameter
473  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
474  **/
475 
477  socklen_t optlen)
478 {
479  int_t ret;
480 
481 #if (IPV4_SUPPORT == ENABLED)
482  //Check the length of the option
483  if(optlen >= (socklen_t) sizeof(int_t))
484  {
485  //This option specifies the TTL value associated with an IPv4 socket
486  //for multicast traffic
487  socket->multicastTtl = *optval;
488 
489  //Successful processing
490  ret = SOCKET_SUCCESS;
491  }
492  else
493  {
494  //The option length is not valid
496  ret = SOCKET_ERROR;
497  }
498 #else
499  //IPv4 is not supported
501  ret = SOCKET_ERROR;
502 #endif
503 
504  //Return status code
505  return ret;
506 }
507 
508 
509 /**
510  * @brief Set IP_MULTICAST_LOOP option
511  * @param[in] socket Handle referencing the socket
512  * @param[in] optval A pointer to the buffer in which the value for the
513  * requested option is specified
514  * @param[in] optlen The size, in bytes, of the buffer pointed to by the optval
515  * parameter
516  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
517  **/
518 
520  socklen_t optlen)
521 {
522  int_t ret;
523 
524 #if (IPV4_SUPPORT == ENABLED)
525  //Check the length of the option
526  if(optlen >= (socklen_t) sizeof(int_t))
527  {
528  //Get exclusive access
530 
531  //For a socket that has joined one or more multicast groups, this option
532  //controls whether it will receive a copy of outgoing packets sent to
533  //those multicast groups
534  if(*optval != 0)
535  {
537  }
538  else
539  {
541  }
542 
543  //Release exclusive access
545 
546  //Successful processing
547  ret = SOCKET_SUCCESS;
548  }
549  else
550  {
551  //The option length is not valid
553  ret = SOCKET_ERROR;
554  }
555 #else
556  //IPv4 is not supported
558  ret = SOCKET_ERROR;
559 #endif
560 
561  //Return status code
562  return ret;
563 }
564 
565 
566 /**
567  * @brief Set IP_ADD_MEMBERSHIP option
568  * @param[in] socket Handle referencing the socket
569  * @param[in] optval A pointer to the buffer in which the value for the
570  * requested option is specified
571  * @param[in] optlen The size, in bytes, of the buffer pointed to by the optval
572  * parameter
573  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
574  **/
575 
577  const struct ip_mreq *optval, socklen_t optlen)
578 {
579  int_t ret;
580 
581 #if (IPV4_SUPPORT == ENABLED)
582  //Check the length of the option
583  if(optlen >= (socklen_t) sizeof(struct ip_mreq))
584  {
585  error_t error;
587 
588  //Copy IPv4 address
589  groupAddr.length = sizeof(Ipv4Addr);
590  groupAddr.ipv4Addr = optval->imr_multiaddr.s_addr;
591 
592  //Join the socket to the supplied multicast group
594 
595  //Check status code
596  if(!error)
597  {
598  //Successful processing
599  ret = SOCKET_SUCCESS;
600  }
601  else
602  {
603  //The multicast group cannot be joined
605  ret = SOCKET_ERROR;
606  }
607  }
608  else
609  {
610  //The option length is not valid
612  ret = SOCKET_ERROR;
613  }
614 #else
615  //IPv4 is not supported
617  ret = SOCKET_ERROR;
618 #endif
619 
620  //Return status code
621  return ret;
622 }
623 
624 
625 /**
626  * @brief Set IP_DROP_MEMBERSHIP option
627  * @param[in] socket Handle referencing the socket
628  * @param[in] optval A pointer to the buffer in which the value for the
629  * requested option is specified
630  * @param[in] optlen The size, in bytes, of the buffer pointed to by the optval
631  * parameter
632  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
633  **/
634 
636  const struct ip_mreq *optval, socklen_t optlen)
637 {
638  int_t ret;
639 
640 #if (IPV4_SUPPORT == ENABLED)
641  //Check the length of the option
642  if(optlen >= (socklen_t) sizeof(struct ip_mreq))
643  {
645 
646  //Copy IPv4 address
647  groupAddr.length = sizeof(Ipv4Addr);
648  groupAddr.ipv4Addr = optval->imr_multiaddr.s_addr;
649 
650  //Leaves the specified multicast group
652 
653  //Successful processing
654  ret = SOCKET_SUCCESS;
655  }
656  else
657  {
658  //The option length is not valid
660  ret = SOCKET_ERROR;
661  }
662 #else
663  //IPv4 is not supported
665  ret = SOCKET_ERROR;
666 #endif
667 
668  //Return status code
669  return ret;
670 }
671 
672 
673 /**
674  * @brief Set IP_DONTFRAG option
675  * @param[in] socket Handle referencing the socket
676  * @param[in] optval A pointer to the buffer in which the value for the
677  * requested option is specified
678  * @param[in] optlen The size, in bytes, of the buffer pointed to by the optval
679  * parameter
680  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
681  **/
682 
684  socklen_t optlen)
685 {
686  int_t ret;
687 
688 #if (IPV4_SUPPORT == ENABLED)
689  //Check the length of the option
690  if(optlen >= (socklen_t) sizeof(int_t))
691  {
692  //Get exclusive access
694 
695  //This option can be used to set the "don't fragment" flag on IP packets
696  if(*optval != 0)
697  {
699  }
700  else
701  {
703  }
704 
705  //Release exclusive access
707 
708  //Successful processing
709  ret = SOCKET_SUCCESS;
710  }
711  else
712  {
713  //The option length is not valid
715  ret = SOCKET_ERROR;
716  }
717 #else
718  //IPv4 is not supported
720  ret = SOCKET_ERROR;
721 #endif
722 
723  //Return status code
724  return ret;
725 }
726 
727 
728 /**
729  * @brief Set IP_PKTINFO option
730  * @param[in] socket Handle referencing the socket
731  * @param[in] optval A pointer to the buffer in which the value for the
732  * requested option is specified
733  * @param[in] optlen The size, in bytes, of the buffer pointed to by the optval
734  * parameter
735  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
736  **/
737 
739  socklen_t optlen)
740 {
741  int_t ret;
742 
743 #if (IPV4_SUPPORT == ENABLED)
744  //Check the length of the option
745  if(optlen >= (socklen_t) sizeof(int_t))
746  {
747  //Get exclusive access
749 
750  //This option allows an application to enable or disable the return of
751  //packet information
752  if(*optval != 0)
753  {
755  }
756  else
757  {
758  socket->options &= ~SOCKET_OPTION_IPV4_PKT_INFO;
759  }
760 
761  //Release exclusive access
763 
764  //Successful processing
765  ret = SOCKET_SUCCESS;
766  }
767  else
768  {
769  //The option length is not valid
771  ret = SOCKET_ERROR;
772  }
773 #else
774  //IPv4 is not supported
776  ret = SOCKET_ERROR;
777 #endif
778 
779  //Return status code
780  return ret;
781 }
782 
783 
784 /**
785  * @brief Set IP_RECVTOS option
786  * @param[in] socket Handle referencing the socket
787  * @param[in] optval A pointer to the buffer in which the value for the
788  * requested option is specified
789  * @param[in] optlen The size, in bytes, of the buffer pointed to by the optval
790  * parameter
791  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
792  **/
793 
795  socklen_t optlen)
796 {
797  int_t ret;
798 
799 #if (IPV4_SUPPORT == ENABLED)
800  //Check the length of the option
801  if(optlen >= (socklen_t) sizeof(int_t))
802  {
803  //Get exclusive access
805 
806  //This option allows an application to enable or disable the return of
807  //ToS header field on received datagrams
808  if(*optval != 0)
809  {
811  }
812  else
813  {
814  socket->options &= ~SOCKET_OPTION_IPV4_RECV_TOS;
815  }
816 
817  //Release exclusive access
819 
820  //Successful processing
821  ret = SOCKET_SUCCESS;
822  }
823  else
824  {
825  //The option length is not valid
827  ret = SOCKET_ERROR;
828  }
829 #else
830  //IPv4 is not supported
832  ret = SOCKET_ERROR;
833 #endif
834 
835  //Return status code
836  return ret;
837 }
838 
839 
840 /**
841  * @brief Set IP_RECVTTL option
842  * @param[in] socket Handle referencing the socket
843  * @param[in] optval A pointer to the buffer in which the value for the
844  * requested option is specified
845  * @param[in] optlen The size, in bytes, of the buffer pointed to by the optval
846  * parameter
847  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
848  **/
849 
851  socklen_t optlen)
852 {
853  int_t ret;
854 
855 #if (IPV4_SUPPORT == ENABLED)
856  //Check the length of the option
857  if(optlen >= (socklen_t) sizeof(int_t))
858  {
859  //Get exclusive access
861 
862  //This option allows an application to enable or disable the return of
863  //TTL header field on received datagrams
864  if(*optval != 0)
865  {
867  }
868  else
869  {
870  socket->options &= ~SOCKET_OPTION_IPV4_RECV_TTL;
871  }
872 
873  //Release exclusive access
875 
876  //Successful processing
877  ret = SOCKET_SUCCESS;
878  }
879  else
880  {
881  //The option length is not valid
883  ret = SOCKET_ERROR;
884  }
885 #else
886  //IPv4 is not supported
888  ret = SOCKET_ERROR;
889 #endif
890 
891  //Return status code
892  return ret;
893 }
894 
895 
896 /**
897  * @brief Set IPV6_TCLASS option
898  * @param[in] socket Handle referencing the socket
899  * @param[in] optval A pointer to the buffer in which the value for the
900  * requested option is specified
901  * @param[in] optlen The size, in bytes, of the buffer pointed to by the optval
902  * parameter
903  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
904  **/
905 
907  socklen_t optlen)
908 {
909  int_t ret;
910 
911 #if (IPV6_SUPPORT == ENABLED)
912  //Check the length of the option
913  if(optlen >= (socklen_t) sizeof(int_t))
914  {
915  //Save Traffic Class value
916  socket->tos = *optval & 0xFF;
917  //Successful processing
918  ret = SOCKET_SUCCESS;
919  }
920  else
921  {
922  //The option length is not valid
924  ret = SOCKET_ERROR;
925  }
926 #else
927  //IPv6 is not supported
929  ret = SOCKET_ERROR;
930 #endif
931 
932  //Return status code
933  return ret;
934 }
935 
936 
937 /**
938  * @brief Set IPV6_UNICAST_HOPS option
939  * @param[in] socket Handle referencing the socket
940  * @param[in] optval A pointer to the buffer in which the value for the
941  * requested option is specified
942  * @param[in] optlen The size, in bytes, of the buffer pointed to by the optval
943  * parameter
944  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
945  **/
946 
948  socklen_t optlen)
949 {
950  int_t ret;
951 
952 #if (IPV6_SUPPORT == ENABLED)
953  //Check the length of the option
954  if(optlen >= (socklen_t) sizeof(int_t))
955  {
956  //This option specifies the TTL value associated with an IPv6 socket
957  //for unicast traffic
958  socket->ttl = *optval;
959 
960  //Successful processing
961  ret = SOCKET_SUCCESS;
962  }
963  else
964  {
965  //The option length is not valid
967  ret = SOCKET_ERROR;
968  }
969 #else
970  //IPv6 is not supported
972  ret = SOCKET_ERROR;
973 #endif
974 
975  //Return status code
976  return ret;
977 }
978 
979 
980 /**
981  * @brief Set IPV6_MULTICAST_IF option
982  * @param[in] socket Handle referencing the socket
983  * @param[in] optval A pointer to the buffer in which the value for the
984  * requested option is specified
985  * @param[in] optlen The size, in bytes, of the buffer pointed to by the optval
986  * parameter
987  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
988  **/
989 
991  const struct in_addr *optval, socklen_t optlen)
992 {
993  int_t ret;
994 
995 #if (IPV6_SUPPORT == ENABLED)
996  //Check the length of the option
997  if(optlen >= (socklen_t) sizeof(struct in_addr))
998  {
999  //Successful processing
1000  ret = SOCKET_SUCCESS;
1001  }
1002  else
1003  {
1004  //The option length is not valid
1006  ret = SOCKET_ERROR;
1007  }
1008 #else
1009  //IPv6 is not supported
1011  ret = SOCKET_ERROR;
1012 #endif
1013 
1014  //Return status code
1015  return ret;
1016 }
1017 
1018 
1019 /**
1020  * @brief Set IPV6_MULTICAST_HOPS option
1021  * @param[in] socket Handle referencing the socket
1022  * @param[in] optval A pointer to the buffer in which the value for the
1023  * requested option is specified
1024  * @param[in] optlen The size, in bytes, of the buffer pointed to by the optval
1025  * parameter
1026  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
1027  **/
1028 
1030  socklen_t optlen)
1031 {
1032  int_t ret;
1033 
1034 #if (IPV6_SUPPORT == ENABLED)
1035  //Check the length of the option
1036  if(optlen >= (socklen_t) sizeof(int_t))
1037  {
1038  //This option specifies the TTL value associated with an IPv6 socket
1039  //for multicast traffic
1040  socket->multicastTtl = *optval;
1041 
1042  //Successful processing
1043  ret = SOCKET_SUCCESS;
1044  }
1045  else
1046  {
1047  //The option length is not valid
1049  ret = SOCKET_ERROR;
1050  }
1051 #else
1052  //IPv6 is not supported
1054  ret = SOCKET_ERROR;
1055 #endif
1056 
1057  //Return status code
1058  return ret;
1059 }
1060 
1061 
1062 /**
1063  * @brief Set IPV6_MULTICAST_LOOP option
1064  * @param[in] socket Handle referencing the socket
1065  * @param[in] optval A pointer to the buffer in which the value for the
1066  * requested option is specified
1067  * @param[in] optlen The size, in bytes, of the buffer pointed to by the optval
1068  * parameter
1069  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
1070  **/
1071 
1073  socklen_t optlen)
1074 {
1075  int_t ret;
1076 
1077 #if (IPV6_SUPPORT == ENABLED)
1078  //Check the length of the option
1079  if(optlen >= (socklen_t) sizeof(int_t))
1080  {
1081  //Get exclusive access
1083 
1084  //For a socket that has joined one or more multicast groups, this option
1085  //controls whether it will receive a copy of outgoing packets sent to
1086  //those multicast groups
1087  if(*optval != 0)
1088  {
1090  }
1091  else
1092  {
1094  }
1095 
1096  //Release exclusive access
1098 
1099  //Successful processing
1100  ret = SOCKET_SUCCESS;
1101  }
1102  else
1103  {
1104  //The option length is not valid
1106  ret = SOCKET_ERROR;
1107  }
1108 #else
1109  //IPv6 is not supported
1111  ret = SOCKET_ERROR;
1112 #endif
1113 
1114  //Return status code
1115  return ret;
1116 }
1117 
1118 
1119 /**
1120  * @brief Set IPV6_ADD_MEMBERSHIP option
1121  * @param[in] socket Handle referencing the socket
1122  * @param[in] optval A pointer to the buffer in which the value for the
1123  * requested option is specified
1124  * @param[in] optlen The size, in bytes, of the buffer pointed to by the optval
1125  * parameter
1126  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
1127  **/
1128 
1130  const struct ipv6_mreq *optval, socklen_t optlen)
1131 {
1132  int_t ret;
1133 
1134 #if (IPV6_SUPPORT == ENABLED)
1135  //Check the length of the option
1136  if(optlen >= (socklen_t) sizeof(struct ipv6_mreq))
1137  {
1138  error_t error;
1139  IpAddr groupAddr;
1140 
1141  //Copy IPv6 address
1142  groupAddr.length = sizeof(Ipv6Addr);
1143  ipv6CopyAddr(&groupAddr.ipv6Addr, optval->ipv6mr_multiaddr.s6_addr);
1144 
1145  //Join the socket to the supplied multicast group
1147 
1148  //Check status code
1149  if(!error)
1150  {
1151  //Successful processing
1152  ret = SOCKET_SUCCESS;
1153  }
1154  else
1155  {
1156  //The multicast group cannot be joined
1158  ret = SOCKET_ERROR;
1159  }
1160  }
1161  else
1162  {
1163  //The option length is not valid
1165  ret = SOCKET_ERROR;
1166  }
1167 #else
1168  //IPv6 is not supported
1170  ret = SOCKET_ERROR;
1171 #endif
1172 
1173  //Return status code
1174  return ret;
1175 }
1176 
1177 
1178 /**
1179  * @brief Set IPV6_DROP_MEMBERSHIP option
1180  * @param[in] socket Handle referencing the socket
1181  * @param[in] optval A pointer to the buffer in which the value for the
1182  * requested option is specified
1183  * @param[in] optlen The size, in bytes, of the buffer pointed to by the optval
1184  * parameter
1185  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
1186  **/
1187 
1189  const struct ipv6_mreq *optval, socklen_t optlen)
1190 {
1191  int_t ret;
1192 
1193 #if (IPV6_SUPPORT == ENABLED)
1194  //Check the length of the option
1195  if(optlen >= (socklen_t) sizeof(struct ipv6_mreq))
1196  {
1197  IpAddr groupAddr;
1198 
1199  //Copy IPv6 address
1200  groupAddr.length = sizeof(Ipv6Addr);
1201  ipv6CopyAddr(&groupAddr.ipv6Addr, optval->ipv6mr_multiaddr.s6_addr);
1202 
1203  //Leaves the specified multicast group
1205 
1206  //Successful processing
1207  ret = SOCKET_SUCCESS;
1208  }
1209  else
1210  {
1211  //The option length is not valid
1213  ret = SOCKET_ERROR;
1214  }
1215 #else
1216  //IPv6 is not supported
1218  ret = SOCKET_ERROR;
1219 #endif
1220 
1221  //Return status code
1222  return ret;
1223 }
1224 
1225 
1226 /**
1227  * @brief Set IPV6_V6ONLY option
1228  * @param[in] socket Handle referencing the socket
1229  * @param[in] optval A pointer to the buffer in which the value for the
1230  * requested option is specified
1231  * @param[in] optlen The size, in bytes, of the buffer pointed to by the optval
1232  * parameter
1233  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
1234  **/
1235 
1237  socklen_t optlen)
1238 {
1239  int_t ret;
1240 
1241 #if (IPV6_SUPPORT == ENABLED)
1242  //Check the length of the option
1243  if(optlen >= (socklen_t) sizeof(int_t))
1244  {
1245  //Get exclusive access
1247 
1248  //This option indicates if a socket created for the AF_INET6 address
1249  //family is restricted to IPv6 communications only
1250  if(*optval != 0)
1251  {
1252  socket->options |= SOCKET_OPTION_IPV6_ONLY;
1253  }
1254  else
1255  {
1256  socket->options &= ~SOCKET_OPTION_IPV6_ONLY;
1257  }
1258 
1259  //Release exclusive access
1261 
1262  //Successful processing
1263  ret = SOCKET_SUCCESS;
1264  }
1265  else
1266  {
1267  //The option length is not valid
1269  ret = SOCKET_ERROR;
1270  }
1271 #else
1272  //IPv6 is not supported
1274  ret = SOCKET_ERROR;
1275 #endif
1276 
1277  //Return status code
1278  return ret;
1279 }
1280 
1281 
1282 /**
1283  * @brief Set IPV6_DONTFRAG option
1284  * @param[in] socket Handle referencing the socket
1285  * @param[in] optval A pointer to the buffer in which the value for the
1286  * requested option is specified
1287  * @param[in] optlen The size, in bytes, of the buffer pointed to by the optval
1288  * parameter
1289  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
1290  **/
1291 
1293  socklen_t optlen)
1294 {
1295  int_t ret;
1296 
1297 #if (IPV6_SUPPORT == ENABLED)
1298  //Check the length of the option
1299  if(optlen >= (socklen_t) sizeof(int_t))
1300  {
1301  //This option defines a mechanism to turn off the automatic inserting
1302  //of a fragment header for UDP and raw sockets (refer to RFC 3542,
1303  //section 11.2)
1304  if(*optval != 0)
1305  {
1307  }
1308  else
1309  {
1310  socket->options &= ~SOCKET_OPTION_IPV6_DONT_FRAG;
1311  }
1312  }
1313  else
1314  {
1315  //The option length is not valid
1317  ret = SOCKET_ERROR;
1318  }
1319 #else
1320  //IPv6 is not supported
1322  ret = SOCKET_ERROR;
1323 #endif
1324 
1325  //Return status code
1326  return ret;
1327 }
1328 
1329 
1330 /**
1331  * @brief Set IPV6_PKTINFO option
1332  * @param[in] socket Handle referencing the socket
1333  * @param[in] optval A pointer to the buffer in which the value for the
1334  * requested option is specified
1335  * @param[in] optlen The size, in bytes, of the buffer pointed to by the optval
1336  * parameter
1337  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
1338  **/
1339 
1341  socklen_t optlen)
1342 {
1343  int_t ret;
1344 
1345 #if (IPV6_SUPPORT == ENABLED)
1346  //Check the length of the option
1347  if(optlen >= (socklen_t) sizeof(int_t))
1348  {
1349  //Get exclusive access
1351 
1352  //This option allows an application to enable or disable the return of
1353  //packet information
1354  if(*optval != 0)
1355  {
1356  socket->options |= SOCKET_OPTION_IPV6_PKT_INFO;
1357  }
1358  else
1359  {
1360  socket->options &= ~SOCKET_OPTION_IPV6_PKT_INFO;
1361  }
1362 
1363  //Release exclusive access
1365 
1366  //Successful processing
1367  ret = SOCKET_SUCCESS;
1368  }
1369  else
1370  {
1371  //The option length is not valid
1373  ret = SOCKET_ERROR;
1374  }
1375 #else
1376  //IPv6 is not supported
1378  ret = SOCKET_ERROR;
1379 #endif
1380 
1381  //Return status code
1382  return ret;
1383 }
1384 
1385 
1386 /**
1387  * @brief Set IPV6_RECVTCLASS option
1388  * @param[in] socket Handle referencing the socket
1389  * @param[in] optval A pointer to the buffer in which the value for the
1390  * requested option is specified
1391  * @param[in] optlen The size, in bytes, of the buffer pointed to by the optval
1392  * parameter
1393  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
1394  **/
1395 
1397  socklen_t optlen)
1398 {
1399  int_t ret;
1400 
1401 #if (IPV6_SUPPORT == ENABLED)
1402  //Check the length of the option
1403  if(optlen >= (socklen_t) sizeof(int_t))
1404  {
1405  //Get exclusive access
1407 
1408  //This option allows an application to enable or disable the return of
1409  //Traffic Class header field on received datagrams
1410  if(*optval != 0)
1411  {
1413  }
1414  else
1415  {
1417  }
1418 
1419  //Release exclusive access
1421 
1422  //Successful processing
1423  ret = SOCKET_SUCCESS;
1424  }
1425  else
1426  {
1427  //The option length is not valid
1429  ret = SOCKET_ERROR;
1430  }
1431 #else
1432  //IPv6 is not supported
1434  ret = SOCKET_ERROR;
1435 #endif
1436 
1437  //Return status code
1438  return ret;
1439 }
1440 
1441 
1442 /**
1443  * @brief Set IPV6_RECVHOPLIMIT option
1444  * @param[in] socket Handle referencing the socket
1445  * @param[in] optval A pointer to the buffer in which the value for the
1446  * requested option is specified
1447  * @param[in] optlen The size, in bytes, of the buffer pointed to by the optval
1448  * parameter
1449  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
1450  **/
1451 
1453  socklen_t optlen)
1454 {
1455  int_t ret;
1456 
1457 #if (IPV6_SUPPORT == ENABLED)
1458  //Check the length of the option
1459  if(optlen >= (socklen_t) sizeof(int_t))
1460  {
1461  //Get exclusive access
1463 
1464  //This option allows an application to enable or disable the return of
1465  //Hop Limit header field on received datagrams
1466  if(*optval != 0)
1467  {
1469  }
1470  else
1471  {
1473  }
1474 
1475  //Release exclusive access
1477 
1478  //Successful processing
1479  ret = SOCKET_SUCCESS;
1480  }
1481  else
1482  {
1483  //The option length is not valid
1485  ret = SOCKET_ERROR;
1486  }
1487 #else
1488  //IPv6 is not supported
1490  ret = SOCKET_ERROR;
1491 #endif
1492 
1493  //Return status code
1494  return ret;
1495 }
1496 
1497 
1498 /**
1499  * @brief Set TCP_NODELAY option
1500  * @param[in] socket Handle referencing the socket
1501  * @param[in] optval A pointer to the buffer in which the value for the
1502  * requested option is specified
1503  * @param[in] optlen The size, in bytes, of the buffer pointed to by the optval
1504  * parameter
1505  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
1506  **/
1507 
1509  socklen_t optlen)
1510 {
1511  int_t ret;
1512 
1513 #if (TCP_SUPPORT == ENABLED)
1514  //Check the length of the option
1515  if(optlen >= (socklen_t) sizeof(int_t))
1516  {
1517  //Get exclusive access
1519 
1520  //The option enables or disables the Nagle algorithm for TCP sockets
1521  if(*optval != 0)
1522  {
1523  socket->options |= SOCKET_OPTION_TCP_NO_DELAY;
1524  }
1525  else
1526  {
1527  socket->options &= ~SOCKET_OPTION_TCP_NO_DELAY;
1528  }
1529 
1530  //Release exclusive access
1532 
1533  //Successful processing
1534  ret = SOCKET_SUCCESS;
1535  }
1536  else
1537  {
1538  //The option length is not valid
1540  ret = SOCKET_ERROR;
1541  }
1542 #else
1543  //TCP is not supported
1545  ret = SOCKET_ERROR;
1546 #endif
1547 
1548  //Return status code
1549  return ret;
1550 }
1551 
1552 
1553 /**
1554  * @brief Set TCP_MAXSEG option
1555  * @param[in] socket Handle referencing the socket
1556  * @param[in] optval A pointer to the buffer in which the value for the
1557  * requested option is specified
1558  * @param[in] optlen The size, in bytes, of the buffer pointed to by the optval
1559  * parameter
1560  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
1561  **/
1562 
1564  socklen_t optlen)
1565 {
1566  int_t ret;
1567 
1568 #if (TCP_SUPPORT == ENABLED)
1569  //Check the length of the option
1570  if(optlen >= (socklen_t) sizeof(int_t))
1571  {
1572  //Set the maximum segment size for outgoing TCP packets. If this option
1573  //is set before connection establishment, it also change the MSS value
1574  //announced to the other end in the initial SYN packet
1575  socketSetMaxSegmentSize(socket, *optval);
1576 
1577  //Successful processing
1578  ret = SOCKET_SUCCESS;
1579  }
1580  else
1581  {
1582  //The option length is not valid
1584  ret = SOCKET_ERROR;
1585  }
1586 #else
1587  //TCP is not supported
1589  ret = SOCKET_ERROR;
1590 #endif
1591 
1592  //Return status code
1593  return ret;
1594 }
1595 
1596 
1597 /**
1598  * @brief Set TCP_KEEPIDLE option
1599  * @param[in] socket Handle referencing the socket
1600  * @param[in] optval A pointer to the buffer in which the value for the
1601  * requested option is specified
1602  * @param[in] optlen The size, in bytes, of the buffer pointed to by the optval
1603  * parameter
1604  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
1605  **/
1606 
1608  socklen_t optlen)
1609 {
1610  int_t ret;
1611 
1612 #if (TCP_SUPPORT == ENABLED && TCP_KEEP_ALIVE_SUPPORT == ENABLED)
1613  //Check the length of the option
1614  if(optlen >= (socklen_t) sizeof(int_t))
1615  {
1616  //Convert the time interval to milliseconds
1617  socket->keepAliveIdle = *optval * 1000;
1618  //Successful processing
1619  ret = SOCKET_SUCCESS;
1620  }
1621  else
1622  {
1623  //The option length is not valid
1625  ret = SOCKET_ERROR;
1626  }
1627 #else
1628  //TCP keep-alive is not supported
1630  ret = SOCKET_ERROR;
1631 #endif
1632 
1633  //Return status code
1634  return ret;
1635 }
1636 
1637 
1638 /**
1639  * @brief Set TCP_KEEPINTVL option
1640  * @param[in] socket Handle referencing the socket
1641  * @param[in] optval A pointer to the buffer in which the value for the
1642  * requested option is specified
1643  * @param[in] optlen The size, in bytes, of the buffer pointed to by the optval
1644  * parameter
1645  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
1646  **/
1647 
1649  socklen_t optlen)
1650 {
1651  int_t ret;
1652 
1653 #if (TCP_SUPPORT == ENABLED && TCP_KEEP_ALIVE_SUPPORT == ENABLED)
1654  //Check the length of the option
1655  if(optlen >= (socklen_t) sizeof(int_t))
1656  {
1657  //Convert the time interval to milliseconds
1658  socket->keepAliveInterval = *optval * 1000;
1659  //Successful processing
1660  ret = SOCKET_SUCCESS;
1661  }
1662  else
1663  {
1664  //The option length is not valid
1666  ret = SOCKET_ERROR;
1667  }
1668 #else
1669  //TCP keep-alive is not supported
1671  ret = SOCKET_ERROR;
1672 #endif
1673 
1674  //Return status code
1675  return ret;
1676 }
1677 
1678 
1679 /**
1680  * @brief Set TCP_KEEPCNT option
1681  * @param[in] socket Handle referencing the socket
1682  * @param[in] optval A pointer to the buffer in which the value for the
1683  * requested option is specified
1684  * @param[in] optlen The size, in bytes, of the buffer pointed to by the optval
1685  * parameter
1686  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
1687  **/
1688 
1690  socklen_t optlen)
1691 {
1692  int_t ret;
1693 
1694 #if (TCP_SUPPORT == ENABLED && TCP_KEEP_ALIVE_SUPPORT == ENABLED)
1695  //Check the length of the option
1696  if(optlen >= (socklen_t) sizeof(int_t))
1697  {
1698  //Save parameter value
1699  socket->keepAliveMaxProbes = *optval;
1700  //Successful processing
1701  ret = SOCKET_SUCCESS;
1702  }
1703  else
1704  {
1705  //The option length is not valid
1707  ret = SOCKET_ERROR;
1708  }
1709 #else
1710  //TCP keep-alive is not supported
1712  ret = SOCKET_ERROR;
1713 #endif
1714 
1715  //Return status code
1716  return ret;
1717 }
1718 
1719 
1720 /**
1721  * @brief Get SO_REUSEADDR option
1722  * @param[in] socket Handle referencing the socket
1723  * @param[out] optval A pointer to the buffer in which the value for the
1724  * requested option is to be returned
1725  * @param[in,out] optlen The size, in bytes, of the buffer pointed to by the
1726  * optval parameter
1727  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
1728  **/
1729 
1731  socklen_t *optlen)
1732 {
1733  int_t ret;
1734 
1735  //Check the length of the option
1736  if(*optlen >= (socklen_t) sizeof(int_t))
1737  {
1738  //This option specifies whether the socket can be bound to an address
1739  //which is already in use
1740  if((socket->options & SOCKET_OPTION_REUSE_ADDR) != 0)
1741  {
1742  *optval = TRUE;
1743  }
1744  else
1745  {
1746  *optval = FALSE;
1747  }
1748 
1749  //Return the actual length of the option
1750  *optlen = sizeof(int_t);
1751 
1752  //Successful processing
1753  ret = SOCKET_SUCCESS;
1754  }
1755  else
1756  {
1757  //The option length is not valid
1759  ret = SOCKET_ERROR;
1760  }
1761 
1762  //Return status code
1763  return ret;
1764 }
1765 
1766 
1767 /**
1768  * @brief Get SO_BROADCAST option
1769  * @param[in] socket Handle referencing the socket
1770  * @param[out] optval A pointer to the buffer in which the value for the
1771  * requested option is to be returned
1772  * @param[in,out] optlen The size, in bytes, of the buffer pointed to by the
1773  * optval parameter
1774  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
1775  **/
1776 
1778  socklen_t *optlen)
1779 {
1780  int_t ret;
1781 
1782  //Check the length of the option
1783  if(*optlen >= (socklen_t) sizeof(int_t))
1784  {
1785  //This option specifies whether transmission and receipt of broadcast
1786  //messages are allowed
1787  if((socket->options & SOCKET_OPTION_BROADCAST) != 0)
1788  {
1789  *optval = TRUE;
1790  }
1791  else
1792  {
1793  *optval = FALSE;
1794  }
1795 
1796  //Return the actual length of the option
1797  *optlen = sizeof(int_t);
1798 
1799  //Successful processing
1800  ret = SOCKET_SUCCESS;
1801  }
1802  else
1803  {
1804  //The option length is not valid
1806  ret = SOCKET_ERROR;
1807  }
1808 
1809  //Return status code
1810  return ret;
1811 }
1812 
1813 
1814 /**
1815  * @brief Get SO_SNDTIMEO option
1816  * @param[in] socket Handle referencing the socket
1817  * @param[out] optval A pointer to the buffer in which the value for the
1818  * requested option is to be returned
1819  * @param[in,out] optlen The size, in bytes, of the buffer pointed to by the
1820  * optval parameter
1821  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
1822  **/
1823 
1825  socklen_t *optlen)
1826 {
1827  int_t ret;
1828 
1829  //Check the length of the option
1830  if(*optlen >= (socklen_t) sizeof(struct timeval))
1831  {
1832  //Return the timeout value
1833  if(socket->timeout == INFINITE_DELAY)
1834  {
1835  optval->tv_sec = 0;
1836  optval->tv_usec = 0;
1837  }
1838  else
1839  {
1840  optval->tv_sec = socket->timeout / 1000;
1841  optval->tv_usec = (socket->timeout % 1000) * 1000;
1842  }
1843 
1844  //Return the actual length of the option
1845  *optlen = sizeof(struct timeval);
1846  //Successful processing
1847  ret = SOCKET_SUCCESS;
1848  }
1849  else
1850  {
1851  //The option length is not valid
1853  ret = SOCKET_ERROR;
1854  }
1855 
1856  //Return status code
1857  return ret;
1858 }
1859 
1860 
1861 /**
1862  * @brief Get SO_RCVTIMEO option
1863  * @param[in] socket Handle referencing the socket
1864  * @param[out] optval A pointer to the buffer in which the value for the
1865  * requested option is to be returned
1866  * @param[in,out] optlen The size, in bytes, of the buffer pointed to by the
1867  * optval parameter
1868  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
1869  **/
1870 
1872  socklen_t *optlen)
1873 {
1874  int_t ret;
1875 
1876  //Check the length of the option
1877  if(*optlen >= (socklen_t) sizeof(struct timeval))
1878  {
1879  //Return the timeout value
1880  if(socket->timeout == INFINITE_DELAY)
1881  {
1882  optval->tv_sec = 0;
1883  optval->tv_usec = 0;
1884  }
1885  else
1886  {
1887  optval->tv_sec = socket->timeout / 1000;
1888  optval->tv_usec = (socket->timeout % 1000) * 1000;
1889  }
1890 
1891  //Return the actual length of the option
1892  *optlen = sizeof(struct timeval);
1893  //Successful processing
1894  ret = SOCKET_SUCCESS;
1895  }
1896  else
1897  {
1898  //The option length is not valid
1900  ret = SOCKET_ERROR;
1901  }
1902 
1903  //Return status code
1904  return ret;
1905 }
1906 
1907 
1908 /**
1909  * @brief Get SO_SNDBUF option
1910  * @param[in] socket Handle referencing the socket
1911  * @param[out] optval A pointer to the buffer in which the value for the
1912  * requested option is to be returned
1913  * @param[in,out] optlen The size, in bytes, of the buffer pointed to by the
1914  * optval parameter
1915  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
1916  **/
1917 
1919  socklen_t *optlen)
1920 {
1921  int_t ret;
1922 
1923 #if (TCP_SUPPORT == ENABLED)
1924  //Check the length of the option
1925  if(*optlen >= (socklen_t) sizeof(int_t))
1926  {
1927  //Return the size of the send buffer
1928  *optval = socket->txBufferSize;
1929  //Return the actual length of the option
1930  *optlen = sizeof(int_t);
1931  //Successful processing
1932  ret = SOCKET_SUCCESS;
1933  }
1934  else
1935  {
1936  //The option length is not valid
1938  ret = SOCKET_ERROR;
1939  }
1940 #else
1941  //TCP is not supported
1943  ret = SOCKET_ERROR;
1944 #endif
1945 
1946  //Return status code
1947  return ret;
1948 }
1949 
1950 
1951 /**
1952  * @brief Get SO_RCVBUF option
1953  * @param[in] socket Handle referencing the socket
1954  * @param[out] optval A pointer to the buffer in which the value for the
1955  * requested option is to be returned
1956  * @param[in,out] optlen The size, in bytes, of the buffer pointed to by the
1957  * optval parameter
1958  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
1959  **/
1960 
1962  socklen_t *optlen)
1963 {
1964  int_t ret;
1965 
1966 #if (TCP_SUPPORT == ENABLED)
1967  //Check the length of the option
1968  if(*optlen >= (socklen_t) sizeof(int_t))
1969  {
1970  //Return the size of the receive buffer
1971  *optval = socket->rxBufferSize;
1972  //Return the actual length of the option
1973  *optlen = sizeof(int_t);
1974  //Successful processing
1975  ret = SOCKET_SUCCESS;
1976  }
1977  else
1978  {
1979  //The option length is not valid
1981  ret = SOCKET_ERROR;
1982  }
1983 #else
1984  //TCP is not supported
1986  ret = SOCKET_ERROR;
1987 #endif
1988 
1989  //Return status code
1990  return ret;
1991 }
1992 
1993 
1994 /**
1995  * @brief Get SO_KEEPALIVE option
1996  * @param[in] socket Handle referencing the socket
1997  * @param[out] optval A pointer to the buffer in which the value for the
1998  * requested option is to be returned
1999  * @param[in,out] optlen The size, in bytes, of the buffer pointed to by the
2000  * optval parameter
2001  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
2002  **/
2003 
2005  socklen_t *optlen)
2006 {
2007  int_t ret;
2008 
2009 #if (TCP_SUPPORT == ENABLED && TCP_KEEP_ALIVE_SUPPORT == ENABLED)
2010  //Check the length of the option
2011  if(*optlen >= (socklen_t) sizeof(int_t))
2012  {
2013  //This option specifies whether TCP keep-alive is enabled
2014  *optval = socket->keepAliveEnabled;
2015  //Successful processing
2016  ret = SOCKET_SUCCESS;
2017  }
2018  else
2019  {
2020  //The option length is not valid
2022  ret = SOCKET_ERROR;
2023  }
2024 #else
2025  //TCP keep-alive is not supported
2027  ret = SOCKET_ERROR;
2028 #endif
2029 
2030  //Return status code
2031  return ret;
2032 }
2033 
2034 
2035 /**
2036  * @brief Get SO_TYPE option
2037  * @param[in] socket Handle referencing the socket
2038  * @param[out] optval A pointer to the buffer in which the value for the
2039  * requested option is to be returned
2040  * @param[in,out] optlen The size, in bytes, of the buffer pointed to by the
2041  * optval parameter
2042  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
2043  **/
2044 
2046  socklen_t *optlen)
2047 {
2048  int_t ret;
2049 
2050  //Check the length of the option
2051  if(*optlen >= (socklen_t) sizeof(int_t))
2052  {
2053  //Return the type of the socket
2054  if(socket->type == SOCKET_TYPE_STREAM)
2055  {
2056  *optval = SOCK_STREAM;
2057  }
2058  else if(socket->type == SOCKET_TYPE_DGRAM)
2059  {
2060  *optval = SOCK_DGRAM;
2061  }
2062  else
2063  {
2064  *optval = SOCK_RAW;
2065  }
2066 
2067  //Return the actual length of the option
2068  *optlen = sizeof(int_t);
2069 
2070  //Successful processing
2071  ret = SOCKET_SUCCESS;
2072  }
2073  else
2074  {
2075  //The option length is not valid
2077  ret = SOCKET_ERROR;
2078  }
2079 
2080  //Return status code
2081  return ret;
2082 }
2083 
2084 
2085 /**
2086  * @brief Get SO_ERROR option
2087  * @param[in] socket Handle referencing the socket
2088  * @param[out] optval A pointer to the buffer in which the value for the
2089  * requested option is to be returned
2090  * @param[in,out] optlen The size, in bytes, of the buffer pointed to by the
2091  * optval parameter
2092  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
2093  **/
2094 
2096  socklen_t *optlen)
2097 {
2098  int_t ret;
2099 
2100  //Check the length of the option
2101  if(*optlen >= (socklen_t) sizeof(int_t))
2102  {
2103  //Return the error code
2104  *optval = socket->errnoCode;
2105  //Return the actual length of the option
2106  *optlen = sizeof(int_t);
2107 
2108  //Clear error status
2109  socket->errnoCode = 0;
2110 
2111  //Successful processing
2112  ret = SOCKET_SUCCESS;
2113  }
2114  else
2115  {
2116  //The option length is not valid
2118  ret = SOCKET_ERROR;
2119  }
2120 
2121  //Return status code
2122  return ret;
2123 }
2124 
2125 
2126 /**
2127  * @brief Get IP_TOS option
2128  * @param[in] socket Handle referencing the socket
2129  * @param[out] optval A pointer to the buffer in which the value for the
2130  * requested option is to be returned
2131  * @param[in,out] optlen The size, in bytes, of the buffer pointed to by the
2132  * optval parameter
2133  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
2134  **/
2135 
2137  socklen_t *optlen)
2138 {
2139  int_t ret;
2140 
2141 #if (IPV4_SUPPORT == ENABLED)
2142  //Check the length of the option
2143  if(*optlen >= (socklen_t) sizeof(int_t))
2144  {
2145  //Return ToS value
2146  *optval = socket->tos;
2147  //Return the actual length of the option
2148  *optlen = sizeof(int_t);
2149 
2150  //Successful processing
2151  ret = SOCKET_SUCCESS;
2152  }
2153  else
2154  {
2155  //The option length is not valid
2157  ret = SOCKET_ERROR;
2158  }
2159 #else
2160  //IPv4 is not supported
2162  ret = SOCKET_ERROR;
2163 #endif
2164 
2165  //Return status code
2166  return ret;
2167 }
2168 
2169 
2170 /**
2171  * @brief Get IP_TTL option
2172  * @param[in] socket Handle referencing the socket
2173  * @param[out] optval A pointer to the buffer in which the value for the
2174  * requested option is to be returned
2175  * @param[in,out] optlen The size, in bytes, of the buffer pointed to by the
2176  * optval parameter
2177  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
2178  **/
2179 
2181  socklen_t *optlen)
2182 {
2183  int_t ret;
2184 
2185 #if (IPV4_SUPPORT == ENABLED)
2186  //Check the length of the option
2187  if(*optlen >= (socklen_t) sizeof(int_t))
2188  {
2189  //Return TTL value
2190  *optval = socket->ttl;
2191  //Return the actual length of the option
2192  *optlen = sizeof(int_t);
2193 
2194  //Successful processing
2195  ret = SOCKET_SUCCESS;
2196  }
2197  else
2198  {
2199  //The option length is not valid
2201  ret = SOCKET_ERROR;
2202  }
2203 #else
2204  //IPv4 is not supported
2206  ret = SOCKET_ERROR;
2207 #endif
2208 
2209  //Return status code
2210  return ret;
2211 }
2212 
2213 
2214 /**
2215  * @brief Get IP_MULTICAST_TTL option
2216  * @param[in] socket Handle referencing the socket
2217  * @param[out] optval A pointer to the buffer in which the value for the
2218  * requested option is to be returned
2219  * @param[in,out] optlen The size, in bytes, of the buffer pointed to by the
2220  * optval parameter
2221  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
2222  **/
2223 
2225  socklen_t *optlen)
2226 {
2227  int_t ret;
2228 
2229 #if (IPV4_SUPPORT == ENABLED)
2230  //Check the length of the option
2231  if(*optlen >= (socklen_t) sizeof(int_t))
2232  {
2233  //Return TTL value for multicast packets
2234  *optval = socket->multicastTtl;
2235  //Return the actual length of the option
2236  *optlen = sizeof(int_t);
2237 
2238  //Successful processing
2239  ret = SOCKET_SUCCESS;
2240  }
2241  else
2242  {
2243  //The option length is not valid
2245  ret = SOCKET_ERROR;
2246  }
2247 #else
2248  //IPv4 is not supported
2250  ret = SOCKET_ERROR;
2251 #endif
2252 
2253  //Return status code
2254  return ret;
2255 }
2256 
2257 
2258 /**
2259  * @brief Get IP_MULTICAST_LOOP option
2260  * @param[in] socket Handle referencing the socket
2261  * @param[out] optval A pointer to the buffer in which the value for the
2262  * requested option is to be returned
2263  * @param[in,out] optlen The size, in bytes, of the buffer pointed to by the
2264  * optval parameter
2265  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
2266  **/
2267 
2269  socklen_t *optlen)
2270 {
2271  int_t ret;
2272 
2273 #if (IPV4_SUPPORT == ENABLED)
2274  //Check the length of the option
2275  if(*optlen >= (socklen_t) sizeof(int_t))
2276  {
2277  //For a socket that has joined one or more multicast groups, this option
2278  //controls whether it will receive a copy of outgoing packets sent to
2279  //those multicast groups
2280  if((socket->options & SOCKET_OPTION_IPV4_MULTICAST_LOOP) != 0)
2281  {
2282  *optval = TRUE;
2283  }
2284  else
2285  {
2286  *optval = FALSE;
2287  }
2288 
2289  //Return the actual length of the option
2290  *optlen = sizeof(int_t);
2291 
2292  //Successful processing
2293  ret = SOCKET_SUCCESS;
2294  }
2295  else
2296  {
2297  //The option length is not valid
2299  ret = SOCKET_ERROR;
2300  }
2301 #else
2302  //IPv4 is not supported
2304  ret = SOCKET_ERROR;
2305 #endif
2306 
2307  //Return status code
2308  return ret;
2309 }
2310 
2311 
2312 /**
2313  * @brief Get IP_DONTFRAG option
2314  * @param[in] socket Handle referencing the socket
2315  * @param[out] optval A pointer to the buffer in which the value for the
2316  * requested option is to be returned
2317  * @param[in,out] optlen The size, in bytes, of the buffer pointed to by the
2318  * optval parameter
2319  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
2320  **/
2321 
2323  socklen_t *optlen)
2324 {
2325  int_t ret;
2326 
2327 #if (IPV4_SUPPORT == ENABLED)
2328  //Check the length of the option
2329  if(*optlen >= (socklen_t) sizeof(int_t))
2330  {
2331  //This option can be used to set the "don't fragment" flag on IP packets
2332  if((socket->options & SOCKET_OPTION_IPV4_DONT_FRAG) != 0)
2333  {
2334  *optval = TRUE;
2335  }
2336  else
2337  {
2338  *optval = FALSE;
2339  }
2340 
2341  //Return the actual length of the option
2342  *optlen = sizeof(int_t);
2343 
2344  //Successful processing
2345  ret = SOCKET_SUCCESS;
2346  }
2347  else
2348  {
2349  //The option length is not valid
2351  ret = SOCKET_ERROR;
2352  }
2353 #else
2354  //IPv4 is not supported
2356  ret = SOCKET_ERROR;
2357 #endif
2358 
2359  //Return status code
2360  return ret;
2361 }
2362 
2363 
2364 /**
2365  * @brief Get IP_PKTINFO option
2366  * @param[in] socket Handle referencing the socket
2367  * @param[out] optval A pointer to the buffer in which the value for the
2368  * requested option is to be returned
2369  * @param[in,out] optlen The size, in bytes, of the buffer pointed to by the
2370  * optval parameter
2371  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
2372  **/
2373 
2375  socklen_t *optlen)
2376 {
2377  int_t ret;
2378 
2379 #if (IPV4_SUPPORT == ENABLED)
2380  //Check the length of the option
2381  if(*optlen >= (socklen_t) sizeof(int_t))
2382  {
2383  //This option allows an application to enable or disable the return of
2384  //packet information
2385  if((socket->options & SOCKET_OPTION_IPV4_PKT_INFO) != 0)
2386  {
2387  *optval = TRUE;
2388  }
2389  else
2390  {
2391  *optval = FALSE;
2392  }
2393 
2394  //Return the actual length of the option
2395  *optlen = sizeof(int_t);
2396 
2397  //Successful processing
2398  ret = SOCKET_SUCCESS;
2399  }
2400  else
2401  {
2402  //The option length is not valid
2404  ret = SOCKET_ERROR;
2405  }
2406 #else
2407  //IPv4 is not supported
2409  ret = SOCKET_ERROR;
2410 #endif
2411 
2412  //Return status code
2413  return ret;
2414 }
2415 
2416 
2417 /**
2418  * @brief Get IP_RECVTOS option
2419  * @param[in] socket Handle referencing the socket
2420  * @param[out] optval A pointer to the buffer in which the value for the
2421  * requested option is to be returned
2422  * @param[in,out] optlen The size, in bytes, of the buffer pointed to by the
2423  * optval parameter
2424  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
2425  **/
2426 
2428  socklen_t *optlen)
2429 {
2430  int_t ret;
2431 
2432 #if (IPV4_SUPPORT == ENABLED)
2433  //Check the length of the option
2434  if(*optlen >= (socklen_t) sizeof(int_t))
2435  {
2436  //This option allows an application to enable or disable the return of
2437  //ToS header field on received datagrams
2438  if((socket->options & SOCKET_OPTION_IPV4_RECV_TOS) != 0)
2439  {
2440  *optval = TRUE;
2441  }
2442  else
2443  {
2444  *optval = FALSE;
2445  }
2446 
2447  //Return the actual length of the option
2448  *optlen = sizeof(int_t);
2449 
2450  //Successful processing
2451  ret = SOCKET_SUCCESS;
2452  }
2453  else
2454  {
2455  //The option length is not valid
2457  ret = SOCKET_ERROR;
2458  }
2459 #else
2460  //IPv4 is not supported
2462  ret = SOCKET_ERROR;
2463 #endif
2464 
2465  //Return status code
2466  return ret;
2467 }
2468 
2469 
2470 /**
2471  * @brief Get IP_RECVTTL option
2472  * @param[in] socket Handle referencing the socket
2473  * @param[out] optval A pointer to the buffer in which the value for the
2474  * requested option is to be returned
2475  * @param[in,out] optlen The size, in bytes, of the buffer pointed to by the
2476  * optval parameter
2477  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
2478  **/
2479 
2481  socklen_t *optlen)
2482 {
2483  int_t ret;
2484 
2485 #if (IPV4_SUPPORT == ENABLED)
2486  //Check the length of the option
2487  if(*optlen >= (socklen_t) sizeof(int_t))
2488  {
2489  //This option allows an application to enable or disable the return of
2490  //TTL header field on received datagrams
2491  if((socket->options & SOCKET_OPTION_IPV4_RECV_TTL) != 0)
2492  {
2493  *optval = TRUE;
2494  }
2495  else
2496  {
2497  *optval = FALSE;
2498  }
2499 
2500  //Return the actual length of the option
2501  *optlen = sizeof(int_t);
2502 
2503  //Successful processing
2504  ret = SOCKET_SUCCESS;
2505  }
2506  else
2507  {
2508  //The option length is not valid
2510  ret = SOCKET_ERROR;
2511  }
2512 #else
2513  //IPv4 is not supported
2515  ret = SOCKET_ERROR;
2516 #endif
2517 
2518  //Return status code
2519  return ret;
2520 }
2521 
2522 
2523 /**
2524  * @brief Get IPV6_TCLASS option
2525  * @param[in] socket Handle referencing the socket
2526  * @param[out] optval A pointer to the buffer in which the value for the
2527  * requested option is to be returned
2528  * @param[in,out] optlen The size, in bytes, of the buffer pointed to by the
2529  * optval parameter
2530  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
2531  **/
2532 
2534  socklen_t *optlen)
2535 {
2536  int_t ret;
2537 
2538 #if (IPV6_SUPPORT == ENABLED)
2539  //Check the length of the option
2540  if(*optlen >= (socklen_t) sizeof(int_t))
2541  {
2542  //Return Traffic Class value
2543  *optval = socket->tos;
2544  //Return the actual length of the option
2545  *optlen = sizeof(int_t);
2546 
2547  //Successful processing
2548  ret = SOCKET_SUCCESS;
2549  }
2550  else
2551  {
2552  //The option length is not valid
2554  ret = SOCKET_ERROR;
2555  }
2556 #else
2557  //IPv6 is not supported
2559  ret = SOCKET_ERROR;
2560 #endif
2561 
2562  //Return status code
2563  return ret;
2564 }
2565 
2566 
2567 /**
2568  * @brief Get IPV6_UNICAST_HOPS option
2569  * @param[in] socket Handle referencing the socket
2570  * @param[out] optval A pointer to the buffer in which the value for the
2571  * requested option is to be returned
2572  * @param[in,out] optlen The size, in bytes, of the buffer pointed to by the
2573  * optval parameter
2574  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
2575  **/
2576 
2578  socklen_t *optlen)
2579 {
2580  int_t ret;
2581 
2582 #if (IPV6_SUPPORT == ENABLED)
2583  //Check the length of the option
2584  if(*optlen >= (socklen_t) sizeof(int_t))
2585  {
2586  //This option specifies the TTL value associated with an IPv6 socket
2587  //for unicast traffic
2588  *optval = socket->ttl;
2589 
2590  //Return the actual length of the option
2591  *optlen = sizeof(int_t);
2592 
2593  //Successful processing
2594  ret = SOCKET_SUCCESS;
2595  }
2596  else
2597  {
2598  //The option length is not valid
2600  ret = SOCKET_ERROR;
2601  }
2602 #else
2603  //IPv6 is not supported
2605  ret = SOCKET_ERROR;
2606 #endif
2607 
2608  //Return status code
2609  return ret;
2610 }
2611 
2612 
2613 /**
2614  * @brief Get IPV6_MULTICAST_HOPS option
2615  * @param[in] socket Handle referencing the socket
2616  * @param[out] optval A pointer to the buffer in which the value for the
2617  * requested option is to be returned
2618  * @param[in,out] optlen The size, in bytes, of the buffer pointed to by the
2619  * optval parameter
2620  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
2621  **/
2622 
2624  socklen_t *optlen)
2625 {
2626  int_t ret;
2627 
2628 #if (IPV6_SUPPORT == ENABLED)
2629  //Check the length of the option
2630  if(*optlen >= (socklen_t) sizeof(int_t))
2631  {
2632  //This option specifies the TTL value associated with an IPv6 socket
2633  //for multicast traffic
2634  *optval = socket->multicastTtl;
2635 
2636  //Return the actual length of the option
2637  *optlen = sizeof(int_t);
2638 
2639  //Successful processing
2640  ret = SOCKET_SUCCESS;
2641  }
2642  else
2643  {
2644  //The option length is not valid
2646  ret = SOCKET_ERROR;
2647  }
2648 #else
2649  //IPv6 is not supported
2651  ret = SOCKET_ERROR;
2652 #endif
2653 
2654  //Return status code
2655  return ret;
2656 }
2657 
2658 
2659 /**
2660  * @brief Get IPV6_MULTICAST_LOOP option
2661  * @param[in] socket Handle referencing the socket
2662  * @param[out] optval A pointer to the buffer in which the value for the
2663  * requested option is to be returned
2664  * @param[in,out] optlen The size, in bytes, of the buffer pointed to by the
2665  * optval parameter
2666  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
2667  **/
2668 
2670  socklen_t *optlen)
2671 {
2672  int_t ret;
2673 
2674 #if (IPV6_SUPPORT == ENABLED)
2675  //Check the length of the option
2676  if(*optlen >= (socklen_t) sizeof(int_t))
2677  {
2678  //For a socket that has joined one or more multicast groups, this option
2679  //controls whether it will receive a copy of outgoing packets sent to
2680  //those multicast groups
2681  if((socket->options & SOCKET_OPTION_IPV6_MULTICAST_LOOP) != 0)
2682  {
2683  *optval = TRUE;
2684  }
2685  else
2686  {
2687  *optval = FALSE;
2688  }
2689 
2690  //Return the actual length of the option
2691  *optlen = sizeof(int_t);
2692 
2693  //Successful processing
2694  ret = SOCKET_SUCCESS;
2695  }
2696  else
2697  {
2698  //The option length is not valid
2700  ret = SOCKET_ERROR;
2701  }
2702 #else
2703  //IPv6 is not supported
2705  ret = SOCKET_ERROR;
2706 #endif
2707 
2708  //Return status code
2709  return ret;
2710 }
2711 
2712 /**
2713  * @brief Get IPV6_V6ONLY option
2714  * @param[in] socket Handle referencing the socket
2715  * @param[out] optval A pointer to the buffer in which the value for the
2716  * requested option is to be returned
2717  * @param[in,out] optlen The size, in bytes, of the buffer pointed to by the
2718  * optval parameter
2719  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
2720  **/
2721 
2723  socklen_t *optlen)
2724 {
2725  int_t ret;
2726 
2727 #if (IPV6_SUPPORT == ENABLED)
2728  //Check the length of the option
2729  if(*optlen >= (socklen_t) sizeof(int_t))
2730  {
2731  //This option indicates if a socket created for the AF_INET6 address
2732  //family is restricted to IPv6 communications only
2733  if((socket->options & SOCKET_OPTION_IPV6_ONLY) != 0)
2734  {
2735  *optval = TRUE;
2736  }
2737  else
2738  {
2739  *optval = FALSE;
2740  }
2741 
2742  //Return the actual length of the option
2743  *optlen = sizeof(int_t);
2744 
2745  //Successful processing
2746  ret = SOCKET_SUCCESS;
2747  }
2748  else
2749  {
2750  //The option length is not valid
2752  ret = SOCKET_ERROR;
2753  }
2754 #else
2755  //IPv6 is not supported
2757  ret = SOCKET_ERROR;
2758 #endif
2759 
2760  //Return status code
2761  return ret;
2762 }
2763 
2764 
2765 /**
2766  * @brief Get IPV6_DONTFRAG option
2767  * @param[in] socket Handle referencing the socket
2768  * @param[out] optval A pointer to the buffer in which the value for the
2769  * requested option is to be returned
2770  * @param[in,out] optlen The size, in bytes, of the buffer pointed to by the
2771  * optval parameter
2772  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
2773  **/
2774 
2776  socklen_t *optlen)
2777 {
2778  int_t ret;
2779 
2780 #if (IPV6_SUPPORT == ENABLED)
2781  //Check the length of the option
2782  if(*optlen >= (socklen_t) sizeof(int_t))
2783  {
2784  //This option defines a mechanism to turn off the automatic inserting
2785  //of a fragment header for UDP and raw sockets (refer to RFC 3542,
2786  //section 11.2)
2787  if((socket->options & SOCKET_OPTION_IPV6_DONT_FRAG) != 0)
2788  {
2789  *optval = TRUE;
2790  }
2791  else
2792  {
2793  *optval = FALSE;
2794  }
2795 
2796  //Return the actual length of the option
2797  *optlen = sizeof(int_t);
2798 
2799  //Successful processing
2800  ret = SOCKET_SUCCESS;
2801  }
2802  else
2803  {
2804  //The option length is not valid
2806  ret = SOCKET_ERROR;
2807  }
2808 #else
2809  //IPv6 is not supported
2811  ret = SOCKET_ERROR;
2812 #endif
2813 
2814  //Return status code
2815  return ret;
2816 }
2817 
2818 
2819 /**
2820  * @brief Get IPV6_PKTINFO option
2821  * @param[in] socket Handle referencing the socket
2822  * @param[out] optval A pointer to the buffer in which the value for the
2823  * requested option is to be returned
2824  * @param[in,out] optlen The size, in bytes, of the buffer pointed to by the
2825  * optval parameter
2826  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
2827  **/
2828 
2830  socklen_t *optlen)
2831 {
2832  int_t ret;
2833 
2834 #if (IPV6_SUPPORT == ENABLED)
2835  //Check the length of the option
2836  if(*optlen >= (socklen_t) sizeof(int_t))
2837  {
2838  //This option allows an application to enable or disable the return of
2839  //packet information
2840  if((socket->options & SOCKET_OPTION_IPV6_PKT_INFO) != 0)
2841  {
2842  *optval = TRUE;
2843  }
2844  else
2845  {
2846  *optval = FALSE;
2847  }
2848 
2849  //Return the actual length of the option
2850  *optlen = sizeof(int_t);
2851 
2852  //Successful processing
2853  ret = SOCKET_SUCCESS;
2854  }
2855  else
2856  {
2857  //The option length is not valid
2859  ret = SOCKET_ERROR;
2860  }
2861 #else
2862  //IPv6 is not supported
2864  ret = SOCKET_ERROR;
2865 #endif
2866 
2867  //Return status code
2868  return ret;
2869 }
2870 
2871 
2872 /**
2873  * @brief Get IPV6_RECVTCLASS option
2874  * @param[in] socket Handle referencing the socket
2875  * @param[out] optval A pointer to the buffer in which the value for the
2876  * requested option is to be returned
2877  * @param[in,out] optlen The size, in bytes, of the buffer pointed to by the
2878  * optval parameter
2879  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
2880  **/
2881 
2883  socklen_t *optlen)
2884 {
2885  int_t ret;
2886 
2887 #if (IPV6_SUPPORT == ENABLED)
2888  //Check the length of the option
2889  if(*optlen >= (socklen_t) sizeof(int_t))
2890  {
2891  //This option allows an application to enable or disable the return of
2892  //Traffic Class header field on received datagrams
2893  if((socket->options & SOCKET_OPTION_IPV6_RECV_TRAFFIC_CLASS) != 0)
2894  {
2895  *optval = TRUE;
2896  }
2897  else
2898  {
2899  *optval = FALSE;
2900  }
2901 
2902  //Return the actual length of the option
2903  *optlen = sizeof(int_t);
2904 
2905  //Successful processing
2906  ret = SOCKET_SUCCESS;
2907  }
2908  else
2909  {
2910  //The option length is not valid
2912  ret = SOCKET_ERROR;
2913  }
2914 #else
2915  //IPv6 is not supported
2917  ret = SOCKET_ERROR;
2918 #endif
2919 
2920  //Return status code
2921  return ret;
2922 }
2923 
2924 
2925 /**
2926  * @brief Get IPV6_RECVHOPLIMIT option
2927  * @param[in] socket Handle referencing the socket
2928  * @param[out] optval A pointer to the buffer in which the value for the
2929  * requested option is to be returned
2930  * @param[in,out] optlen The size, in bytes, of the buffer pointed to by the
2931  * optval parameter
2932  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
2933  **/
2934 
2936  socklen_t *optlen)
2937 {
2938  int_t ret;
2939 
2940 #if (IPV6_SUPPORT == ENABLED)
2941  //Check the length of the option
2942  if(*optlen >= (socklen_t) sizeof(int_t))
2943  {
2944  //This option allows an application to enable or disable the return of
2945  //Hop Limit header field on received datagrams
2946  if((socket->options & SOCKET_OPTION_IPV6_RECV_HOP_LIMIT) != 0)
2947  {
2948  *optval = TRUE;
2949  }
2950  else
2951  {
2952  *optval = FALSE;
2953  }
2954 
2955  //Return the actual length of the option
2956  *optlen = sizeof(int_t);
2957 
2958  //Successful processing
2959  ret = SOCKET_SUCCESS;
2960  }
2961  else
2962  {
2963  //The option length is not valid
2965  ret = SOCKET_ERROR;
2966  }
2967 #else
2968  //IPv6 is not supported
2970  ret = SOCKET_ERROR;
2971 #endif
2972 
2973  //Return status code
2974  return ret;
2975 }
2976 
2977 
2978 /**
2979  * @brief Get TCP_NODELAY option
2980  * @param[in] socket Handle referencing the socket
2981  * @param[out] optval A pointer to the buffer in which the value for the
2982  * requested option is to be returned
2983  * @param[in,out] optlen The size, in bytes, of the buffer pointed to by the
2984  * optval parameter
2985  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
2986  **/
2987 
2989  socklen_t *optlen)
2990 {
2991  int_t ret;
2992 
2993 #if (TCP_SUPPORT == ENABLED)
2994  //Check the length of the option
2995  if(*optlen >= (socklen_t) sizeof(int_t))
2996  {
2997  //The option enables or disables the Nagle algorithm for TCP sockets
2998  if((socket->options & SOCKET_OPTION_TCP_NO_DELAY) != 0)
2999  {
3000  *optval = TRUE;
3001  }
3002  else
3003  {
3004  *optval = FALSE;
3005  }
3006 
3007  //Return the actual length of the option
3008  *optlen = sizeof(int_t);
3009 
3010  //Successful processing
3011  ret = SOCKET_SUCCESS;
3012  }
3013  else
3014  {
3015  //The option length is not valid
3017  ret = SOCKET_ERROR;
3018  }
3019 #else
3020  //TCP is not supported
3022  ret = SOCKET_ERROR;
3023 #endif
3024 
3025  //Return status code
3026  return ret;
3027 }
3028 
3029 
3030 /**
3031  * @brief Get TCP_MAXSEG option
3032  * @param[in] socket Handle referencing the socket
3033  * @param[out] optval A pointer to the buffer in which the value for the
3034  * requested option is to be returned
3035  * @param[in,out] optlen The size, in bytes, of the buffer pointed to by the
3036  * optval parameter
3037  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
3038  **/
3039 
3041  socklen_t *optlen)
3042 {
3043  int_t ret;
3044 
3045 #if (TCP_SUPPORT == ENABLED)
3046  //Check the length of the option
3047  if(*optlen >= (socklen_t) sizeof(int_t))
3048  {
3049  //Get exclusive access
3051 
3052  //Return the maximum segment size for outgoing TCP packets
3053  if(socket->state == TCP_STATE_CLOSED ||
3054  socket->state == TCP_STATE_LISTEN)
3055  {
3056  *optval = socket->mss;
3057  }
3058  else
3059  {
3060  *optval = socket->smss;
3061  }
3062 
3063  //Release exclusive access
3065 
3066  //Successful processing
3067  ret = SOCKET_SUCCESS;
3068  }
3069  else
3070  {
3071  //The option length is not valid
3073  ret = SOCKET_ERROR;
3074  }
3075 #else
3076  //TCP is not supported
3078  ret = SOCKET_ERROR;
3079 #endif
3080 
3081  //Return status code
3082  return ret;
3083 }
3084 
3085 
3086 /**
3087  * @brief Get TCP_KEEPIDLE option
3088  * @param[in] socket Handle referencing the socket
3089  * @param[out] optval A pointer to the buffer in which the value for the
3090  * requested option is to be returned
3091  * @param[in,out] optlen The size, in bytes, of the buffer pointed to by the
3092  * optval parameter
3093  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
3094  **/
3095 
3097  socklen_t *optlen)
3098 {
3099  int_t ret;
3100 
3101 #if (TCP_SUPPORT == ENABLED && TCP_KEEP_ALIVE_SUPPORT == ENABLED)
3102  //Check the length of the option
3103  if(*optlen >= (socklen_t) sizeof(int_t))
3104  {
3105  //Convert the time interval to seconds
3106  *optval = socket->keepAliveIdle / 1000;
3107  //Successful processing
3108  ret = SOCKET_SUCCESS;
3109  }
3110  else
3111  {
3112  //The option length is not valid
3114  ret = SOCKET_ERROR;
3115  }
3116 #else
3117  //TCP keep-alive is not supported
3119  ret = SOCKET_ERROR;
3120 #endif
3121 
3122  //Return status code
3123  return ret;
3124 }
3125 
3126 
3127 /**
3128  * @brief Get TCP_KEEPINTVL option
3129  * @param[in] socket Handle referencing the socket
3130  * @param[out] optval A pointer to the buffer in which the value for the
3131  * requested option is to be returned
3132  * @param[in,out] optlen The size, in bytes, of the buffer pointed to by the
3133  * optval parameter
3134  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
3135  **/
3136 
3138  socklen_t *optlen)
3139 {
3140  int_t ret;
3141 
3142 #if (TCP_SUPPORT == ENABLED && TCP_KEEP_ALIVE_SUPPORT == ENABLED)
3143  //Check the length of the option
3144  if(*optlen >= (socklen_t) sizeof(int_t))
3145  {
3146  //Convert the time interval to seconds
3147  *optval = socket->keepAliveInterval / 1000;
3148  //Successful processing
3149  ret = SOCKET_SUCCESS;
3150  }
3151  else
3152  {
3153  //The option length is not valid
3155  ret = SOCKET_ERROR;
3156  }
3157 #else
3158  //TCP keep-alive is not supported
3160  ret = SOCKET_ERROR;
3161 #endif
3162 
3163 
3164  //Return status code
3165  return ret;
3166 }
3167 
3168 
3169 /**
3170  * @brief Get TCP_KEEPCNT option
3171  * @param[in] socket Handle referencing the socket
3172  * @param[out] optval A pointer to the buffer in which the value for the
3173  * requested option is to be returned
3174  * @param[in,out] optlen The size, in bytes, of the buffer pointed to by the
3175  * optval parameter
3176  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
3177  **/
3178 
3180  socklen_t *optlen)
3181 {
3182  int_t ret;
3183 
3184 #if (TCP_SUPPORT == ENABLED && TCP_KEEP_ALIVE_SUPPORT == ENABLED)
3185  //Check the length of the option
3186  if(*optlen >= (socklen_t) sizeof(int_t))
3187  {
3188  //Return parameter value
3189  *optval = socket->keepAliveMaxProbes;
3190  //Successful processing
3191  ret = SOCKET_SUCCESS;
3192  }
3193  else
3194  {
3195  //The option length is not valid
3197  ret = SOCKET_ERROR;
3198  }
3199 #else
3200  //TCP keep-alive is not supported
3202  ret = SOCKET_ERROR;
3203 #endif
3204 
3205 
3206  //Return status code
3207  return ret;
3208 }
3209 
3210 #endif
int_t socketSetSoSndBufOption(Socket *socket, const int_t *optval, socklen_t optlen)
Set SO_SNDBUF option.
int_t socketGetTcpMaxSegOption(Socket *socket, int_t *optval, socklen_t *optlen)
Get TCP_MAXSEG option.
int_t socklen_t
Length type.
Definition: bsd_socket.h:282
int_t socketSetTcpKeepIdleOption(Socket *socket, const int_t *optval, socklen_t optlen)
Set TCP_KEEPIDLE option.
@ SOCKET_OPTION_IPV4_RECV_TOS
Definition: socket.h:190
int_t socketGetTcpKeepIntvlOption(Socket *socket, int_t *optval, socklen_t *optlen)
Get TCP_KEEPINTVL option.
int_t socketSetSoRcvBufOption(Socket *socket, const int_t *optval, socklen_t optlen)
Set SO_RCVBUF option.
#define ENOPROTOOPT
Definition: bsd_socket.h:249
Helper function for BSD socket API.
int_t socketGetSoRcvBufOption(Socket *socket, int_t *optval, socklen_t *optlen)
Get SO_RCVBUF option.
signed int int_t
Definition: compiler_port.h:49
#define netMutex
Definition: net_legacy.h:195
int_t socketGetIpv6RecvHopLimitOption(Socket *socket, int_t *optval, socklen_t *optlen)
Get IPV6_RECVHOPLIMIT option.
int_t socketSetIpv6TrafficClassOption(Socket *socket, const int_t *optval, socklen_t optlen)
Set IPV6_TCLASS option.
IP network address.
Definition: ip.h:79
int_t socketSetTcpMaxSegOption(Socket *socket, const int_t *optval, socklen_t optlen)
Set TCP_MAXSEG option.
int_t socketGetSoErrorOption(Socket *socket, int_t *optval, socklen_t *optlen)
Get SO_ERROR option.
int_t socketGetIpv6MulticastHopsOption(Socket *socket, int_t *optval, socklen_t *optlen)
Get IPV6_MULTICAST_HOPS option.
#define SOCK_DGRAM
Definition: bsd_socket.h:91
#define SOCKET_ERROR
Definition: bsd_socket.h:223
#define TRUE
Definition: os_port.h:50
@ SOCKET_OPTION_REUSE_ADDR
Definition: socket.h:185
int_t socketSetIpv6MulticastHopsOption(Socket *socket, const int_t *optval, socklen_t optlen)
Set IPV6_MULTICAST_HOPS option.
error_t socketJoinMulticastGroup(Socket *socket, const IpAddr *groupAddr)
Join the specified host group.
Definition: socket.c:426
Ipv6Addr
Definition: ipv6.h:251
@ SOCKET_TYPE_DGRAM
Definition: socket.h:86
int_t socketGetSoRcvTimeoOption(Socket *socket, struct timeval *optval, socklen_t *optlen)
Get SO_RCVTIMEO option.
@ SOCKET_OPTION_IPV6_ONLY
Definition: socket.h:193
int_t socketGetIpTosOption(Socket *socket, int_t *optval, socklen_t *optlen)
Get IP_TOS option.
#define EINVAL
Definition: bsd_socket.h:244
int_t socketSetIpv6MulticastLoopOption(Socket *socket, const int_t *optval, socklen_t optlen)
Set IPV6_MULTICAST_LOOP option.
@ SOCKET_OPTION_IPV6_DONT_FRAG
Definition: socket.h:194
Multicast group information for IPv4 addresses.
Definition: bsd_socket.h:366
@ SOCKET_TYPE_STREAM
Definition: socket.h:85
uint32_t Ipv4Addr
IPv4 network address.
Definition: ipv4.h:267
int_t socketGetIpRecvTtlOption(Socket *socket, int_t *optval, socklen_t *optlen)
Get IP_RECVTTL option.
int_t socketGetTcpKeepIdleOption(Socket *socket, int_t *optval, socklen_t *optlen)
Get TCP_KEEPIDLE option.
@ SOCKET_OPTION_IPV6_RECV_TRAFFIC_CLASS
Definition: socket.h:196
error_t socketSetTxBufferSize(Socket *socket, size_t size)
Specify the size of the TCP send buffer.
Definition: socket.c:663
int_t socketSetIpRecvTtlOption(Socket *socket, const int_t *optval, socklen_t optlen)
Set IP_RECVTTL option.
int_t socketSetIpv6UnicastHopsOption(Socket *socket, const int_t *optval, socklen_t optlen)
Set IPV6_UNICAST_HOPS option.
int_t socketGetTcpKeepCntOption(Socket *socket, int_t *optval, socklen_t *optlen)
Get TCP_KEEPCNT option.
@ SOCKET_OPTION_IPV4_RECV_TTL
Definition: socket.h:191
int_t socketSetSoKeepAliveOption(Socket *socket, const int_t *optval, socklen_t optlen)
Set SO_KEEPALIVE option.
int_t socketGetIpv6MulticastLoopOption(Socket *socket, int_t *optval, socklen_t *optlen)
Get IPV6_MULTICAST_LOOP option.
int_t socketSetIpv6OnlyOption(Socket *socket, const int_t *optval, socklen_t optlen)
Set IPV6_V6ONLY option.
int_t socketSetIpDontFragOption(Socket *socket, const int_t *optval, socklen_t optlen)
Set IP_DONTFRAG option.
#define FALSE
Definition: os_port.h:46
int32_t tv_sec
Definition: bsd_socket.h:503
error_t socketSetRxBufferSize(Socket *socket, size_t size)
Specify the size of the TCP receive buffer.
Definition: socket.c:699
int_t socketSetIpv6DontFragOption(Socket *socket, const int_t *optval, socklen_t optlen)
Set IPV6_DONTFRAG option.
error_t socketEnableKeepAlive(Socket *socket, bool_t enabled)
Enable TCP keep-alive.
Definition: socket.c:535
int_t socketGetSoReuseAddrOption(Socket *socket, int_t *optval, socklen_t *optlen)
Get SO_REUSEADDR option.
error_t
Error codes.
Definition: error.h:43
int_t socketGetIpv6RecvTrafficClassOption(Socket *socket, int_t *optval, socklen_t *optlen)
Get IPV6_RECVTCLASS option.
error_t socketEnableBroadcast(Socket *socket, bool_t enabled)
Enable reception of broadcast messages.
Definition: socket.c:392
Structure that represents an IPv4 address.
Definition: bsd_socket.h:319
@ SOCKET_OPTION_IPV6_RECV_HOP_LIMIT
Definition: socket.h:197
int_t socketGetIpv6DontFragOption(Socket *socket, int_t *optval, socklen_t *optlen)
Get IPV6_DONTFRAG option.
int_t socket(int_t family, int_t type, int_t protocol)
Create a socket that is bound to a specific transport service provider.
Definition: bsd_socket.c:65
void socketSetErrnoCode(Socket *socket, uint_t errnoCode)
Set BSD error code.
int_t socketGetIpPktInfoOption(Socket *socket, int_t *optval, socklen_t *optlen)
Get IP_PKTINFO option.
int_t socketGetIpv6UnicastHopsOption(Socket *socket, int_t *optval, socklen_t *optlen)
Get IPV6_UNICAST_HOPS option.
struct in6_addr ipv6mr_multiaddr
Definition: bsd_socket.h:378
#define SOCK_STREAM
Definition: bsd_socket.h:90
BSD socket API.
int_t socketGetIpv6OnlyOption(Socket *socket, int_t *optval, socklen_t *optlen)
Get IPV6_V6ONLY option.
int_t socketSetIpRecvTosOption(Socket *socket, const int_t *optval, socklen_t optlen)
Set IP_RECVTOS option.
@ SOCKET_OPTION_IPV4_DONT_FRAG
Definition: socket.h:188
int_t socketSetIpTtlOption(Socket *socket, const int_t *optval, socklen_t optlen)
Set IP_TTL option.
#define SOCKET_SUCCESS
Definition: bsd_socket.h:222
@ SOCKET_OPTION_BROADCAST
Definition: socket.h:186
int_t socketSetIpAddMembershipOption(Socket *socket, const struct ip_mreq *optval, socklen_t optlen)
Set IP_ADD_MEMBERSHIP option.
int_t socketSetTcpKeepCntOption(Socket *socket, const int_t *optval, socklen_t optlen)
Set TCP_KEEPCNT option.
error_t socketSetMaxSegmentSize(Socket *socket, size_t mss)
Specify the maximum segment size for outgoing TCP packets.
Definition: socket.c:626
int_t socketSetIpPktInfoOption(Socket *socket, const int_t *optval, socklen_t optlen)
Set IP_PKTINFO option.
int_t socketSetIpDropMembershipOption(Socket *socket, const struct ip_mreq *optval, socklen_t optlen)
Set IP_DROP_MEMBERSHIP option.
struct in_addr imr_multiaddr
Definition: bsd_socket.h:367
int32_t tv_usec
Definition: bsd_socket.h:504
int_t socketSetIpv6RecvHopLimitOption(Socket *socket, const int_t *optval, socklen_t optlen)
Set IPV6_RECVHOPLIMIT option.
int_t socketSetIpv6AddMembershipOption(Socket *socket, const struct ipv6_mreq *optval, socklen_t optlen)
Set IPV6_ADD_MEMBERSHIP option.
int_t socketGetIpMulticastLoopOption(Socket *socket, int_t *optval, socklen_t *optlen)
Get IP_MULTICAST_LOOP option.
int_t socketGetIpTtlOption(Socket *socket, int_t *optval, socklen_t *optlen)
Get IP_TTL option.
int_t socketSetIpTosOption(Socket *socket, const int_t *optval, socklen_t optlen)
Set IP_TOS option.
int_t socketGetIpv6TrafficClassOption(Socket *socket, int_t *optval, socklen_t *optlen)
Get IPV6_TCLASS option.
@ TCP_STATE_CLOSED
Definition: tcp.h:268
int_t socketSetTcpKeepIntvlOption(Socket *socket, const int_t *optval, socklen_t optlen)
Set TCP_KEEPINTVL option.
int_t socketGetSoTypeOption(Socket *socket, int_t *optval, socklen_t *optlen)
Get SO_TYPE option.
in_addr_t s_addr
Definition: bsd_socket.h:320
@ TCP_STATE_LISTEN
Definition: tcp.h:269
#define EFAULT
Definition: bsd_socket.h:243
int_t socketGetSoSndTimeoOption(Socket *socket, struct timeval *optval, socklen_t *optlen)
Get SO_SNDTIMEO option.
#define SOCK_RAW
Definition: bsd_socket.h:92
BSD socket options.
int_t socketGetSoBroadcastOption(Socket *socket, int_t *optval, socklen_t *optlen)
Get SO_BROADCAST option.
#define ipv6CopyAddr(destIpAddr, srcIpAddr)
Definition: ipv6.h:116
@ SOCKET_OPTION_IPV4_MULTICAST_LOOP
Definition: socket.h:187
Timeout structure.
Definition: bsd_socket.h:502
void osAcquireMutex(OsMutex *mutex)
Acquire ownership of the specified mutex object.
Ipv4Addr groupAddr
Definition: igmp_common.h:171
void osReleaseMutex(OsMutex *mutex)
Release ownership of the specified mutex object.
int_t socketSetIpv6DropMembershipOption(Socket *socket, const struct ipv6_mreq *optval, socklen_t optlen)
Set IPV6_DROP_MEMBERSHIP option.
#define Socket
Definition: socket.h:36
int_t socketSetSoSndTimeoOption(Socket *socket, const struct timeval *optval, socklen_t optlen)
Set SO_SNDTIMEO option.
int_t socketSetSoBroadcastOption(Socket *socket, const int_t *optval, socklen_t optlen)
Set SO_BROADCAST option.
@ SOCKET_OPTION_IPV6_PKT_INFO
Definition: socket.h:195
int_t socketGetIpRecvTosOption(Socket *socket, int_t *optval, socklen_t *optlen)
Get IP_RECVTOS option.
int_t socketSetSoRcvTimeoOption(Socket *socket, const struct timeval *optval, socklen_t optlen)
Set SO_RCVTIMEO option.
@ SOCKET_OPTION_IPV6_MULTICAST_LOOP
Definition: socket.h:192
int_t socketGetSoKeepAliveOption(Socket *socket, int_t *optval, socklen_t *optlen)
Get SO_KEEPALIVE option.
int_t socketGetIpDontFragOption(Socket *socket, int_t *optval, socklen_t *optlen)
Get IP_DONTFRAG option.
int_t socketSetIpMulticastTtlOption(Socket *socket, const int_t *optval, socklen_t optlen)
Set IP_MULTICAST_TTL option.
int_t socketSetIpMulticastLoopOption(Socket *socket, const int_t *optval, socklen_t optlen)
Set IP_MULTICAST_LOOP option.
Multicast group information for IPv6 addresses.
Definition: bsd_socket.h:377
int_t socketSetSoReuseAddrOption(Socket *socket, const int_t *optval, socklen_t optlen)
Set SO_REUSEADDR option.
int_t socketSetTcpNoDelayOption(Socket *socket, const int_t *optval, socklen_t optlen)
Set TCP_NODELAY option.
int_t socketSetIpv6MulticastIfOption(Socket *socket, const struct in_addr *optval, socklen_t optlen)
Set IPV6_MULTICAST_IF option.
int_t socketSetIpv6RecvTrafficClassOption(Socket *socket, const int_t *optval, socklen_t optlen)
Set IPV6_RECVTCLASS option.
TCP/IP stack core.
int_t socketSetIpv6PktInfoOption(Socket *socket, const int_t *optval, socklen_t optlen)
Set IPV6_PKTINFO option.
int_t socketGetSoSndBufOption(Socket *socket, int_t *optval, socklen_t *optlen)
Get SO_SNDBUF option.
int_t socketGetIpv6PktInfoOption(Socket *socket, int_t *optval, socklen_t *optlen)
Get IPV6_PKTINFO option.
int_t socketGetTcpNoDelayOption(Socket *socket, int_t *optval, socklen_t *optlen)
Get TCP_NODELAY option.
error_t socketLeaveMulticastGroup(Socket *socket, const IpAddr *groupAddr)
Leave the specified host group.
Definition: socket.c:496
error_t socketSetTimeout(Socket *socket, systime_t timeout)
Set timeout value for blocking operations.
Definition: socket.c:148
int_t socketGetIpMulticastTtlOption(Socket *socket, int_t *optval, socklen_t *optlen)
Get IP_MULTICAST_TTL option.
int_t socketSetIpMulticastIfOption(Socket *socket, const struct in_addr *optval, socklen_t optlen)
Set IP_MULTICAST_IF option.
Debugging facilities.
@ SOCKET_OPTION_TCP_NO_DELAY
Definition: socket.h:198
uint8_t s6_addr[16]
Definition: bsd_socket.h:343
#define INFINITE_DELAY
Definition: os_port.h:75
@ SOCKET_OPTION_IPV4_PKT_INFO
Definition: socket.h:189