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.4
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 SO_NO_CHECK 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 (UDP_SUPPORT == ENABLED)
359  //Check the length of the option
360  if(optlen >= (socklen_t) sizeof(int_t))
361  {
362  //Get exclusive access
364 
365  //This option allows UDP checksum generation to be bypassed
366  if(*optval != 0)
367  {
369  }
370  else
371  {
373  }
374 
375  //Release exclusive access
377 
378  //Successful processing
379  ret = SOCKET_SUCCESS;
380  }
381  else
382  {
383  //The option length is not valid
385  ret = SOCKET_ERROR;
386  }
387 #else
388  //IPv4 is not supported
390  ret = SOCKET_ERROR;
391 #endif
392 
393  //Return status code
394  return ret;
395 }
396 
397 
398 /**
399  * @brief Set IP_TOS option
400  * @param[in] socket Handle referencing the socket
401  * @param[in] optval A pointer to the buffer in which the value for the
402  * requested option is specified
403  * @param[in] optlen The size, in bytes, of the buffer pointed to by the optval
404  * parameter
405  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
406  **/
407 
409  socklen_t optlen)
410 {
411  int_t ret;
412 
413 #if (IPV4_SUPPORT == ENABLED)
414  //Check the length of the option
415  if(optlen >= (socklen_t) sizeof(int_t))
416  {
417  //Save ToS value
418  socket->tos = *optval & 0xFF;
419  //Successful processing
420  ret = SOCKET_SUCCESS;
421  }
422  else
423  {
424  //The option length is not valid
426  ret = SOCKET_ERROR;
427  }
428 #else
429  //IPv4 is not supported
431  ret = SOCKET_ERROR;
432 #endif
433 
434  //Return status code
435  return ret;
436 }
437 
438 
439 /**
440  * @brief Set IP_TTL option
441  * @param[in] socket Handle referencing the socket
442  * @param[in] optval A pointer to the buffer in which the value for the
443  * requested option is specified
444  * @param[in] optlen The size, in bytes, of the buffer pointed to by the optval
445  * parameter
446  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
447  **/
448 
450  socklen_t optlen)
451 {
452  int_t ret;
453 
454 #if (IPV4_SUPPORT == ENABLED)
455  //Check the length of the option
456  if(optlen >= (socklen_t) sizeof(int_t))
457  {
458  //This option specifies the TTL value associated with an IPv4 socket
459  //for unicast traffic
460  socket->ttl = *optval;
461 
462  //Successful processing
463  ret = SOCKET_SUCCESS;
464  }
465  else
466  {
467  //The option length is not valid
469  ret = SOCKET_ERROR;
470  }
471 #else
472  //IPv4 is not supported
474  ret = SOCKET_ERROR;
475 #endif
476 
477  //Return status code
478  return ret;
479 }
480 
481 
482 /**
483  * @brief Set IP_MULTICAST_IF option
484  * @param[in] socket Handle referencing the socket
485  * @param[in] optval A pointer to the buffer in which the value for the
486  * requested option is specified
487  * @param[in] optlen The size, in bytes, of the buffer pointed to by the optval
488  * parameter
489  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
490  **/
491 
493  const struct in_addr *optval, socklen_t optlen)
494 {
495  int_t ret;
496 
497 #if (IPV4_SUPPORT == ENABLED)
498  //Check the length of the option
499  if(optlen >= (socklen_t) sizeof(IN_ADDR))
500  {
501  //Successful processing
502  ret = SOCKET_SUCCESS;
503  }
504  else
505  {
506  //The option length is not valid
508  ret = SOCKET_ERROR;
509  }
510 #else
511  //IPv4 is not supported
513  ret = SOCKET_ERROR;
514 #endif
515 
516  //Return status code
517  return ret;
518 }
519 
520 
521 /**
522  * @brief Set IP_MULTICAST_TTL option
523  * @param[in] socket Handle referencing the socket
524  * @param[in] optval A pointer to the buffer in which the value for the
525  * requested option is specified
526  * @param[in] optlen The size, in bytes, of the buffer pointed to by the optval
527  * parameter
528  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
529  **/
530 
532  socklen_t optlen)
533 {
534  int_t ret;
535 
536 #if (IPV4_SUPPORT == ENABLED)
537  //Check the length of the option
538  if(optlen >= (socklen_t) sizeof(int_t))
539  {
540  //This option specifies the TTL value associated with an IPv4 socket
541  //for multicast traffic
542  socket->multicastTtl = *optval;
543 
544  //Successful processing
545  ret = SOCKET_SUCCESS;
546  }
547  else
548  {
549  //The option length is not valid
551  ret = SOCKET_ERROR;
552  }
553 #else
554  //IPv4 is not supported
556  ret = SOCKET_ERROR;
557 #endif
558 
559  //Return status code
560  return ret;
561 }
562 
563 
564 /**
565  * @brief Set IP_MULTICAST_LOOP option
566  * @param[in] socket Handle referencing the socket
567  * @param[in] optval A pointer to the buffer in which the value for the
568  * requested option is specified
569  * @param[in] optlen The size, in bytes, of the buffer pointed to by the optval
570  * parameter
571  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
572  **/
573 
575  socklen_t optlen)
576 {
577  int_t ret;
578 
579 #if (IPV4_SUPPORT == ENABLED)
580  //Check the length of the option
581  if(optlen >= (socklen_t) sizeof(int_t))
582  {
583  //Get exclusive access
585 
586  //For a socket that has joined one or more multicast groups, this option
587  //controls whether it will receive a copy of outgoing packets sent to
588  //those multicast groups
589  if(*optval != 0)
590  {
592  }
593  else
594  {
596  }
597 
598  //Release exclusive access
600 
601  //Successful processing
602  ret = SOCKET_SUCCESS;
603  }
604  else
605  {
606  //The option length is not valid
608  ret = SOCKET_ERROR;
609  }
610 #else
611  //IPv4 is not supported
613  ret = SOCKET_ERROR;
614 #endif
615 
616  //Return status code
617  return ret;
618 }
619 
620 
621 /**
622  * @brief Set IP_ADD_MEMBERSHIP option
623  * @param[in] socket Handle referencing the socket
624  * @param[in] optval A pointer to the buffer in which the value for the
625  * requested option is specified
626  * @param[in] optlen The size, in bytes, of the buffer pointed to by the optval
627  * parameter
628  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
629  **/
630 
632  const struct ip_mreq *optval, socklen_t optlen)
633 {
634  int_t ret;
635 
636 #if (IPV4_SUPPORT == ENABLED)
637  //Check the length of the option
638  if(optlen >= (socklen_t) sizeof(IP_MREQ))
639  {
640  error_t error;
642 
643  //Copy IPv4 address
644  groupAddr.length = sizeof(Ipv4Addr);
645  groupAddr.ipv4Addr = optval->imr_multiaddr.s_addr;
646 
647  //Join the specified multicast group
649 
650  //Check status code
651  if(!error)
652  {
653  //Successful processing
654  ret = SOCKET_SUCCESS;
655  }
656  else
657  {
658  //The multicast group cannot be joined
660  ret = SOCKET_ERROR;
661  }
662  }
663  else
664  {
665  //The option length is not valid
667  ret = SOCKET_ERROR;
668  }
669 #else
670  //IPv4 is not supported
672  ret = SOCKET_ERROR;
673 #endif
674 
675  //Return status code
676  return ret;
677 }
678 
679 
680 /**
681  * @brief Set IP_DROP_MEMBERSHIP option
682  * @param[in] socket Handle referencing the socket
683  * @param[in] optval A pointer to the buffer in which the value for the
684  * requested option is specified
685  * @param[in] optlen The size, in bytes, of the buffer pointed to by the optval
686  * parameter
687  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
688  **/
689 
691  const struct ip_mreq *optval, socklen_t optlen)
692 {
693  int_t ret;
694 
695 #if (IPV4_SUPPORT == ENABLED)
696  //Check the length of the option
697  if(optlen >= (socklen_t) sizeof(IP_MREQ))
698  {
700 
701  //Copy group address
702  groupAddr.length = sizeof(Ipv4Addr);
703  groupAddr.ipv4Addr = optval->imr_multiaddr.s_addr;
704 
705  //Leave the specified multicast group
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_BLOCK_SOURCE 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  const struct ip_mreq_source *optval, 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(IP_MREQ_SOURCE))
746  {
747  error_t error;
749  IpAddr srcAddr;
750 
751  //Copy group address
752  groupAddr.length = sizeof(Ipv4Addr);
753  groupAddr.ipv4Addr = optval->imr_multiaddr.s_addr;
754 
755  //Copy source address
756  srcAddr.length = sizeof(Ipv4Addr);
757  srcAddr.ipv4Addr = optval->imr_sourceaddr.s_addr;
758 
759  //Block specific source for specific group
761 
762  //Check status code
763  if(!error)
764  {
765  //Successful processing
766  ret = SOCKET_SUCCESS;
767  }
768  else
769  {
770  //The source address cannot be blocked
772  ret = SOCKET_ERROR;
773  }
774  }
775  else
776  {
777  //The option length is not valid
779  ret = SOCKET_ERROR;
780  }
781 #else
782  //IPv4 is not supported
784  ret = SOCKET_ERROR;
785 #endif
786 
787  //Return status code
788  return ret;
789 }
790 
791 
792 /**
793  * @brief Set IP_UNBLOCK_SOURCE option
794  * @param[in] socket Handle referencing the socket
795  * @param[in] optval A pointer to the buffer in which the value for the
796  * requested option is specified
797  * @param[in] optlen The size, in bytes, of the buffer pointed to by the optval
798  * parameter
799  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
800  **/
801 
803  const struct ip_mreq_source *optval, socklen_t optlen)
804 {
805  int_t ret;
806 
807 #if (IPV4_SUPPORT == ENABLED)
808  //Check the length of the option
809  if(optlen >= (socklen_t) sizeof(IP_MREQ_SOURCE))
810  {
812  IpAddr srcAddr;
813 
814  //Copy group address
815  groupAddr.length = sizeof(Ipv4Addr);
816  groupAddr.ipv4Addr = optval->imr_multiaddr.s_addr;
817 
818  //Copy source address
819  srcAddr.length = sizeof(Ipv4Addr);
820  srcAddr.ipv4Addr = optval->imr_sourceaddr.s_addr;
821 
822  //Unblock specific source for specific group
824 
825  //Successful processing
826  ret = SOCKET_SUCCESS;
827  }
828  else
829  {
830  //The option length is not valid
832  ret = SOCKET_ERROR;
833  }
834 #else
835  //IPv4 is not supported
837  ret = SOCKET_ERROR;
838 #endif
839 
840  //Return status code
841  return ret;
842 }
843 
844 
845 /**
846  * @brief Set IP_ADD_SOURCE_MEMBERSHIP option
847  * @param[in] socket Handle referencing the socket
848  * @param[in] optval A pointer to the buffer in which the value for the
849  * requested option is specified
850  * @param[in] optlen The size, in bytes, of the buffer pointed to by the optval
851  * parameter
852  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
853  **/
854 
856  const struct ip_mreq_source *optval, socklen_t optlen)
857 {
858  int_t ret;
859 
860 #if (IPV4_SUPPORT == ENABLED)
861  //Check the length of the option
862  if(optlen >= (socklen_t) sizeof(IP_MREQ_SOURCE))
863  {
864  error_t error;
866  IpAddr srcAddr;
867 
868  //Copy group address
869  groupAddr.length = sizeof(Ipv4Addr);
870  groupAddr.ipv4Addr = optval->imr_multiaddr.s_addr;
871 
872  //Copy source address
873  srcAddr.length = sizeof(Ipv4Addr);
874  srcAddr.ipv4Addr = optval->imr_sourceaddr.s_addr;
875 
876  //Accept specific source for specific group
878 
879  //Check status code
880  if(!error)
881  {
882  //Successful processing
883  ret = SOCKET_SUCCESS;
884  }
885  else
886  {
887  //The source address cannot be accepted
889  ret = SOCKET_ERROR;
890  }
891  }
892  else
893  {
894  //The option length is not valid
896  ret = SOCKET_ERROR;
897  }
898 #else
899  //IPv4 is not supported
901  ret = SOCKET_ERROR;
902 #endif
903 
904  //Return status code
905  return ret;
906 }
907 
908 
909 /**
910  * @brief Set IP_DROP_SOURCE_MEMBERSHIP option
911  * @param[in] socket Handle referencing the socket
912  * @param[in] optval A pointer to the buffer in which the value for the
913  * requested option is specified
914  * @param[in] optlen The size, in bytes, of the buffer pointed to by the optval
915  * parameter
916  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
917  **/
918 
920  const struct ip_mreq_source *optval, socklen_t optlen)
921 {
922  int_t ret;
923 
924 #if (IPV4_SUPPORT == ENABLED)
925  //Check the length of the option
926  if(optlen >= (socklen_t) sizeof(IP_MREQ_SOURCE))
927  {
929  IpAddr srcAddr;
930 
931  //Copy group address
932  groupAddr.length = sizeof(Ipv4Addr);
933  groupAddr.ipv4Addr = optval->imr_multiaddr.s_addr;
934 
935  //Copy source address
936  srcAddr.length = sizeof(Ipv4Addr);
937  srcAddr.ipv4Addr = optval->imr_sourceaddr.s_addr;
938 
939  //Drop specific source for specific group
941 
942  //Successful processing
943  ret = SOCKET_SUCCESS;
944  }
945  else
946  {
947  //The option length is not valid
949  ret = SOCKET_ERROR;
950  }
951 #else
952  //IPv4 is not supported
954  ret = SOCKET_ERROR;
955 #endif
956 
957  //Return status code
958  return ret;
959 }
960 
961 
962 /**
963  * @brief Set MCAST_JOIN_GROUP option
964  * @param[in] socket Handle referencing the socket
965  * @param[in] optval A pointer to the buffer in which the value for the
966  * requested option is specified
967  * @param[in] optlen The size, in bytes, of the buffer pointed to by the optval
968  * parameter
969  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
970  **/
971 
973  const struct group_req *optval, socklen_t optlen)
974 {
975  int_t ret;
976 
977  //Check the length of the option
978  if(optlen >= (socklen_t) sizeof(GROUP_REQ))
979  {
980  error_t error;
982 
983 #if (IPV4_SUPPORT == ENABLED)
984  //IPv4 address?
985  if(optval->gr_group.ss_family == AF_INET)
986  {
987  //Point to the IPv4 address information
988  SOCKADDR_IN *sa = (SOCKADDR_IN *) &optval->gr_group;
989 
990  //Copy group address
991  groupAddr.length = sizeof(Ipv4Addr);
992  groupAddr.ipv4Addr = sa->sin_addr.s_addr;
993  }
994  else
995 #endif
996 #if (IPV6_SUPPORT == ENABLED)
997  //IPv6 address?
998  if(optval->gr_group.ss_family == AF_INET6)
999  {
1000  //Point to the IPv6 address information
1001  SOCKADDR_IN6 *sa = (SOCKADDR_IN6 *) &optval->gr_group;
1002 
1003  //Copy group address
1004  groupAddr.length = sizeof(Ipv6Addr);
1005  ipv6CopyAddr(&groupAddr.ipv6Addr, sa->sin6_addr.s6_addr);
1006  }
1007  else
1008 #endif
1009  //Invalid address?
1010  {
1011  //Report an error
1013  return SOCKET_ERROR;
1014  }
1015 
1016  //Join the specified multicast group
1018 
1019  //Check status code
1020  if(!error)
1021  {
1022  //Successful processing
1023  ret = SOCKET_SUCCESS;
1024  }
1025  else
1026  {
1027  //The multicast group cannot be joined
1029  ret = SOCKET_ERROR;
1030  }
1031  }
1032  else
1033  {
1034  //The option length is not valid
1036  ret = SOCKET_ERROR;
1037  }
1038 
1039  //Return status code
1040  return ret;
1041 }
1042 
1043 
1044 /**
1045  * @brief Set MCAST_LEAVE_GROUP option
1046  * @param[in] socket Handle referencing the socket
1047  * @param[in] optval A pointer to the buffer in which the value for the
1048  * requested option is specified
1049  * @param[in] optlen The size, in bytes, of the buffer pointed to by the optval
1050  * parameter
1051  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
1052  **/
1053 
1055  const struct group_req *optval, socklen_t optlen)
1056 {
1057  int_t ret;
1058 
1059  //Check the length of the option
1060  if(optlen >= (socklen_t) sizeof(GROUP_REQ))
1061  {
1062  IpAddr groupAddr;
1063 
1064 #if (IPV4_SUPPORT == ENABLED)
1065  //IPv4 address?
1066  if(optval->gr_group.ss_family == AF_INET)
1067  {
1068  //Point to the IPv4 address information
1069  SOCKADDR_IN *sa = (SOCKADDR_IN *) &optval->gr_group;
1070 
1071  //Copy group address
1072  groupAddr.length = sizeof(Ipv4Addr);
1073  groupAddr.ipv4Addr = sa->sin_addr.s_addr;
1074  }
1075  else
1076 #endif
1077 #if (IPV6_SUPPORT == ENABLED)
1078  //IPv6 address?
1079  if(optval->gr_group.ss_family == AF_INET6)
1080  {
1081  //Point to the IPv6 address information
1082  SOCKADDR_IN6 *sa = (SOCKADDR_IN6 *) &optval->gr_group;
1083 
1084  //Copy group address
1085  groupAddr.length = sizeof(Ipv6Addr);
1086  ipv6CopyAddr(&groupAddr.ipv6Addr, sa->sin6_addr.s6_addr);
1087  }
1088  else
1089 #endif
1090  //Invalid address?
1091  {
1092  //Report an error
1094  return SOCKET_ERROR;
1095  }
1096 
1097  //Leave the specified multicast group
1099 
1100  //Successful processing
1101  ret = SOCKET_SUCCESS;
1102  }
1103  else
1104  {
1105  //The option length is not valid
1107  ret = SOCKET_ERROR;
1108  }
1109 
1110  //Return status code
1111  return ret;
1112 }
1113 
1114 
1115 /**
1116  * @brief Set MCAST_BLOCK_SOURCE option
1117  * @param[in] socket Handle referencing the socket
1118  * @param[in] optval A pointer to the buffer in which the value for the
1119  * requested option is specified
1120  * @param[in] optlen The size, in bytes, of the buffer pointed to by the optval
1121  * parameter
1122  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
1123  **/
1124 
1126  const struct group_source_req *optval, socklen_t optlen)
1127 {
1128  int_t ret;
1129 
1130  //Check the length of the option
1131  if(optlen >= (socklen_t) sizeof(GROUP_SOURCE_REQ))
1132  {
1133  error_t error;
1134  IpAddr groupAddr;
1135  IpAddr srcAddr;
1136 
1137 #if (IPV4_SUPPORT == ENABLED)
1138  //IPv4 address?
1139  if(optval->gsr_group.ss_family == AF_INET &&
1140  optval->gsr_source.ss_family == AF_INET)
1141  {
1142  //Point to the IPv4 address information
1143  SOCKADDR_IN *sa1 = (SOCKADDR_IN *) &optval->gsr_group;
1144  SOCKADDR_IN *sa2 = (SOCKADDR_IN *) &optval->gsr_source;
1145 
1146  //Copy group address
1147  groupAddr.length = sizeof(Ipv4Addr);
1148  groupAddr.ipv4Addr = sa1->sin_addr.s_addr;
1149 
1150  //Copy source address
1151  srcAddr.length = sizeof(Ipv4Addr);
1152  srcAddr.ipv4Addr = sa2->sin_addr.s_addr;
1153  }
1154  else
1155 #endif
1156 #if (IPV6_SUPPORT == ENABLED)
1157  //IPv6 address?
1158  if(optval->gsr_group.ss_family == AF_INET6 &&
1159  optval->gsr_source.ss_family == AF_INET6)
1160  {
1161  //Point to the IPv6 address information
1162  SOCKADDR_IN6 *sa1 = (SOCKADDR_IN6 *) &optval->gsr_group;
1163  SOCKADDR_IN6 *sa2 = (SOCKADDR_IN6 *) &optval->gsr_source;
1164 
1165  //Copy group address
1166  groupAddr.length = sizeof(Ipv6Addr);
1167  ipv6CopyAddr(&groupAddr.ipv6Addr, sa1->sin6_addr.s6_addr);
1168 
1169  //Copy source address
1170  srcAddr.length = sizeof(Ipv6Addr);
1171  ipv6CopyAddr(&srcAddr.ipv6Addr, sa2->sin6_addr.s6_addr);
1172  }
1173  else
1174 #endif
1175  //Invalid address?
1176  {
1177  //Report an error
1179  return SOCKET_ERROR;
1180  }
1181 
1182  //Block specific source for specific group
1184 
1185  //Check status code
1186  if(!error)
1187  {
1188  //Successful processing
1189  ret = SOCKET_SUCCESS;
1190  }
1191  else
1192  {
1193  //The source address cannot be blocked
1195  ret = SOCKET_ERROR;
1196  }
1197  }
1198  else
1199  {
1200  //The option length is not valid
1202  ret = SOCKET_ERROR;
1203  }
1204 
1205  //Return status code
1206  return ret;
1207 }
1208 
1209 /**
1210  * @brief Set MCAST_UNBLOCK_SOURCE option
1211  * @param[in] socket Handle referencing the socket
1212  * @param[in] optval A pointer to the buffer in which the value for the
1213  * requested option is specified
1214  * @param[in] optlen The size, in bytes, of the buffer pointed to by the optval
1215  * parameter
1216  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
1217  **/
1218 
1220  const struct group_source_req *optval, socklen_t optlen)
1221 {
1222  int_t ret;
1223 
1224  //Check the length of the option
1225  if(optlen >= (socklen_t) sizeof(GROUP_SOURCE_REQ))
1226  {
1227  IpAddr groupAddr;
1228  IpAddr srcAddr;
1229 
1230 #if (IPV4_SUPPORT == ENABLED)
1231  //IPv4 address?
1232  if(optval->gsr_group.ss_family == AF_INET &&
1233  optval->gsr_source.ss_family == AF_INET)
1234  {
1235  //Point to the IPv4 address information
1236  SOCKADDR_IN *sa1 = (SOCKADDR_IN *) &optval->gsr_group;
1237  SOCKADDR_IN *sa2 = (SOCKADDR_IN *) &optval->gsr_source;
1238 
1239  //Copy group address
1240  groupAddr.length = sizeof(Ipv4Addr);
1241  groupAddr.ipv4Addr = sa1->sin_addr.s_addr;
1242 
1243  //Copy source address
1244  srcAddr.length = sizeof(Ipv4Addr);
1245  srcAddr.ipv4Addr = sa2->sin_addr.s_addr;
1246  }
1247  else
1248 #endif
1249 #if (IPV6_SUPPORT == ENABLED)
1250  //IPv6 address?
1251  if(optval->gsr_group.ss_family == AF_INET6 &&
1252  optval->gsr_source.ss_family == AF_INET6)
1253  {
1254  //Point to the IPv6 address information
1255  SOCKADDR_IN6 *sa1 = (SOCKADDR_IN6 *) &optval->gsr_group;
1256  SOCKADDR_IN6 *sa2 = (SOCKADDR_IN6 *) &optval->gsr_source;
1257 
1258  //Copy group address
1259  groupAddr.length = sizeof(Ipv6Addr);
1260  ipv6CopyAddr(&groupAddr.ipv6Addr, sa1->sin6_addr.s6_addr);
1261 
1262  //Copy source address
1263  srcAddr.length = sizeof(Ipv6Addr);
1264  ipv6CopyAddr(&srcAddr.ipv6Addr, sa2->sin6_addr.s6_addr);
1265  }
1266  else
1267 #endif
1268  //Invalid address?
1269  {
1270  //Report an error
1272  return SOCKET_ERROR;
1273  }
1274 
1275  //Unblock specific source for specific group
1277 
1278  //Successful processing
1279  ret = SOCKET_SUCCESS;
1280  }
1281  else
1282  {
1283  //The option length is not valid
1285  ret = SOCKET_ERROR;
1286  }
1287 
1288  //Return status code
1289  return ret;
1290 }
1291 
1292 
1293 /**
1294  * @brief Set MCAST_JOIN_SOURCE_GROUP option
1295  * @param[in] socket Handle referencing the socket
1296  * @param[in] optval A pointer to the buffer in which the value for the
1297  * requested option is specified
1298  * @param[in] optlen The size, in bytes, of the buffer pointed to by the optval
1299  * parameter
1300  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
1301  **/
1302 
1304  const struct group_source_req *optval, socklen_t optlen)
1305 {
1306  int_t ret;
1307 
1308  //Check the length of the option
1309  if(optlen >= (socklen_t) sizeof(GROUP_SOURCE_REQ))
1310  {
1311  error_t error;
1312  IpAddr groupAddr;
1313  IpAddr srcAddr;
1314 
1315 #if (IPV4_SUPPORT == ENABLED)
1316  //IPv4 address?
1317  if(optval->gsr_group.ss_family == AF_INET &&
1318  optval->gsr_source.ss_family == AF_INET)
1319  {
1320  //Point to the IPv4 address information
1321  SOCKADDR_IN *sa1 = (SOCKADDR_IN *) &optval->gsr_group;
1322  SOCKADDR_IN *sa2 = (SOCKADDR_IN *) &optval->gsr_source;
1323 
1324  //Copy group address
1325  groupAddr.length = sizeof(Ipv4Addr);
1326  groupAddr.ipv4Addr = sa1->sin_addr.s_addr;
1327 
1328  //Copy source address
1329  srcAddr.length = sizeof(Ipv4Addr);
1330  srcAddr.ipv4Addr = sa2->sin_addr.s_addr;
1331  }
1332  else
1333 #endif
1334 #if (IPV6_SUPPORT == ENABLED)
1335  //IPv6 address?
1336  if(optval->gsr_group.ss_family == AF_INET6 &&
1337  optval->gsr_source.ss_family == AF_INET6)
1338  {
1339  //Point to the IPv6 address information
1340  SOCKADDR_IN6 *sa1 = (SOCKADDR_IN6 *) &optval->gsr_group;
1341  SOCKADDR_IN6 *sa2 = (SOCKADDR_IN6 *) &optval->gsr_source;
1342 
1343  //Copy group address
1344  groupAddr.length = sizeof(Ipv6Addr);
1345  ipv6CopyAddr(&groupAddr.ipv6Addr, sa1->sin6_addr.s6_addr);
1346 
1347  //Copy source address
1348  srcAddr.length = sizeof(Ipv6Addr);
1349  ipv6CopyAddr(&srcAddr.ipv6Addr, sa2->sin6_addr.s6_addr);
1350  }
1351  else
1352 #endif
1353  //Invalid address?
1354  {
1355  //Report an error
1357  return SOCKET_ERROR;
1358  }
1359 
1360  //Accept specific source for specific group
1362 
1363  //Check status code
1364  if(!error)
1365  {
1366  //Successful processing
1367  ret = SOCKET_SUCCESS;
1368  }
1369  else
1370  {
1371  //The source address cannot be accepted
1373  ret = SOCKET_ERROR;
1374  }
1375  }
1376  else
1377  {
1378  //The option length is not valid
1380  ret = SOCKET_ERROR;
1381  }
1382 
1383  //Return status code
1384  return ret;
1385 }
1386 
1387 
1388 /**
1389  * @brief Set MCAST_LEAVE_SOURCE_GROUP option
1390  * @param[in] socket Handle referencing the socket
1391  * @param[in] optval A pointer to the buffer in which the value for the
1392  * requested option is specified
1393  * @param[in] optlen The size, in bytes, of the buffer pointed to by the optval
1394  * parameter
1395  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
1396  **/
1397 
1399  const struct group_source_req *optval, socklen_t optlen)
1400 {
1401  int_t ret;
1402 
1403  //Check the length of the option
1404  if(optlen >= (socklen_t) sizeof(GROUP_SOURCE_REQ))
1405  {
1406  IpAddr groupAddr;
1407  IpAddr srcAddr;
1408 
1409 #if (IPV4_SUPPORT == ENABLED)
1410  //IPv4 address?
1411  if(optval->gsr_group.ss_family == AF_INET &&
1412  optval->gsr_source.ss_family == AF_INET)
1413  {
1414  //Point to the IPv4 address information
1415  SOCKADDR_IN *sa1 = (SOCKADDR_IN *) &optval->gsr_group;
1416  SOCKADDR_IN *sa2 = (SOCKADDR_IN *) &optval->gsr_source;
1417 
1418  //Copy group address
1419  groupAddr.length = sizeof(Ipv4Addr);
1420  groupAddr.ipv4Addr = sa1->sin_addr.s_addr;
1421 
1422  //Copy source address
1423  srcAddr.length = sizeof(Ipv4Addr);
1424  srcAddr.ipv4Addr = sa2->sin_addr.s_addr;
1425  }
1426  else
1427 #endif
1428 #if (IPV6_SUPPORT == ENABLED)
1429  //IPv6 address?
1430  if(optval->gsr_group.ss_family == AF_INET6 &&
1431  optval->gsr_source.ss_family == AF_INET6)
1432  {
1433  //Point to the IPv6 address information
1434  SOCKADDR_IN6 *sa1 = (SOCKADDR_IN6 *) &optval->gsr_group;
1435  SOCKADDR_IN6 *sa2 = (SOCKADDR_IN6 *) &optval->gsr_source;
1436 
1437  //Copy group address
1438  groupAddr.length = sizeof(Ipv6Addr);
1439  ipv6CopyAddr(&groupAddr.ipv6Addr, sa1->sin6_addr.s6_addr);
1440 
1441  //Copy source address
1442  srcAddr.length = sizeof(Ipv6Addr);
1443  ipv6CopyAddr(&srcAddr.ipv6Addr, sa2->sin6_addr.s6_addr);
1444  }
1445  else
1446 #endif
1447  //Invalid address?
1448  {
1449  //Report an error
1451  return SOCKET_ERROR;
1452  }
1453 
1454  //Drop specific source for specific group
1456 
1457  //Successful processing
1458  ret = SOCKET_SUCCESS;
1459  }
1460  else
1461  {
1462  //The option length is not valid
1464  ret = SOCKET_ERROR;
1465  }
1466 
1467  //Return status code
1468  return ret;
1469 }
1470 
1471 
1472 /**
1473  * @brief Set IP_DONTFRAG option
1474  * @param[in] socket Handle referencing the socket
1475  * @param[in] optval A pointer to the buffer in which the value for the
1476  * requested option is specified
1477  * @param[in] optlen The size, in bytes, of the buffer pointed to by the optval
1478  * parameter
1479  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
1480  **/
1481 
1483  socklen_t optlen)
1484 {
1485  int_t ret;
1486 
1487 #if (IPV4_SUPPORT == ENABLED)
1488  //Check the length of the option
1489  if(optlen >= (socklen_t) sizeof(int_t))
1490  {
1491  //Get exclusive access
1493 
1494  //This option can be used to set the "don't fragment" flag on IP packets
1495  if(*optval != 0)
1496  {
1498  }
1499  else
1500  {
1501  socket->options &= ~SOCKET_OPTION_IPV4_DONT_FRAG;
1502  }
1503 
1504  //Release exclusive access
1506 
1507  //Successful processing
1508  ret = SOCKET_SUCCESS;
1509  }
1510  else
1511  {
1512  //The option length is not valid
1514  ret = SOCKET_ERROR;
1515  }
1516 #else
1517  //IPv4 is not supported
1519  ret = SOCKET_ERROR;
1520 #endif
1521 
1522  //Return status code
1523  return ret;
1524 }
1525 
1526 
1527 /**
1528  * @brief Set IP_PKTINFO option
1529  * @param[in] socket Handle referencing the socket
1530  * @param[in] optval A pointer to the buffer in which the value for the
1531  * requested option is specified
1532  * @param[in] optlen The size, in bytes, of the buffer pointed to by the optval
1533  * parameter
1534  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
1535  **/
1536 
1538  socklen_t optlen)
1539 {
1540  int_t ret;
1541 
1542 #if (IPV4_SUPPORT == ENABLED)
1543  //Check the length of the option
1544  if(optlen >= (socklen_t) sizeof(int_t))
1545  {
1546  //Get exclusive access
1548 
1549  //This option allows an application to enable or disable the return of
1550  //packet information
1551  if(*optval != 0)
1552  {
1553  socket->options |= SOCKET_OPTION_IPV4_PKT_INFO;
1554  }
1555  else
1556  {
1557  socket->options &= ~SOCKET_OPTION_IPV4_PKT_INFO;
1558  }
1559 
1560  //Release exclusive access
1562 
1563  //Successful processing
1564  ret = SOCKET_SUCCESS;
1565  }
1566  else
1567  {
1568  //The option length is not valid
1570  ret = SOCKET_ERROR;
1571  }
1572 #else
1573  //IPv4 is not supported
1575  ret = SOCKET_ERROR;
1576 #endif
1577 
1578  //Return status code
1579  return ret;
1580 }
1581 
1582 
1583 /**
1584  * @brief Set IP_RECVTOS option
1585  * @param[in] socket Handle referencing the socket
1586  * @param[in] optval A pointer to the buffer in which the value for the
1587  * requested option is specified
1588  * @param[in] optlen The size, in bytes, of the buffer pointed to by the optval
1589  * parameter
1590  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
1591  **/
1592 
1594  socklen_t optlen)
1595 {
1596  int_t ret;
1597 
1598 #if (IPV4_SUPPORT == ENABLED)
1599  //Check the length of the option
1600  if(optlen >= (socklen_t) sizeof(int_t))
1601  {
1602  //Get exclusive access
1604 
1605  //This option allows an application to enable or disable the return of
1606  //ToS header field on received datagrams
1607  if(*optval != 0)
1608  {
1609  socket->options |= SOCKET_OPTION_IPV4_RECV_TOS;
1610  }
1611  else
1612  {
1613  socket->options &= ~SOCKET_OPTION_IPV4_RECV_TOS;
1614  }
1615 
1616  //Release exclusive access
1618 
1619  //Successful processing
1620  ret = SOCKET_SUCCESS;
1621  }
1622  else
1623  {
1624  //The option length is not valid
1626  ret = SOCKET_ERROR;
1627  }
1628 #else
1629  //IPv4 is not supported
1631  ret = SOCKET_ERROR;
1632 #endif
1633 
1634  //Return status code
1635  return ret;
1636 }
1637 
1638 
1639 /**
1640  * @brief Set IP_RECVTTL option
1641  * @param[in] socket Handle referencing the socket
1642  * @param[in] optval A pointer to the buffer in which the value for the
1643  * requested option is specified
1644  * @param[in] optlen The size, in bytes, of the buffer pointed to by the optval
1645  * parameter
1646  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
1647  **/
1648 
1650  socklen_t optlen)
1651 {
1652  int_t ret;
1653 
1654 #if (IPV4_SUPPORT == ENABLED)
1655  //Check the length of the option
1656  if(optlen >= (socklen_t) sizeof(int_t))
1657  {
1658  //Get exclusive access
1660 
1661  //This option allows an application to enable or disable the return of
1662  //TTL header field on received datagrams
1663  if(*optval != 0)
1664  {
1665  socket->options |= SOCKET_OPTION_IPV4_RECV_TTL;
1666  }
1667  else
1668  {
1669  socket->options &= ~SOCKET_OPTION_IPV4_RECV_TTL;
1670  }
1671 
1672  //Release exclusive access
1674 
1675  //Successful processing
1676  ret = SOCKET_SUCCESS;
1677  }
1678  else
1679  {
1680  //The option length is not valid
1682  ret = SOCKET_ERROR;
1683  }
1684 #else
1685  //IPv4 is not supported
1687  ret = SOCKET_ERROR;
1688 #endif
1689 
1690  //Return status code
1691  return ret;
1692 }
1693 
1694 
1695 /**
1696  * @brief Set IPV6_TCLASS option
1697  * @param[in] socket Handle referencing the socket
1698  * @param[in] optval A pointer to the buffer in which the value for the
1699  * requested option is specified
1700  * @param[in] optlen The size, in bytes, of the buffer pointed to by the optval
1701  * parameter
1702  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
1703  **/
1704 
1706  socklen_t optlen)
1707 {
1708  int_t ret;
1709 
1710 #if (IPV6_SUPPORT == ENABLED)
1711  //Check the length of the option
1712  if(optlen >= (socklen_t) sizeof(int_t))
1713  {
1714  //Save Traffic Class value
1715  socket->tos = *optval & 0xFF;
1716  //Successful processing
1717  ret = SOCKET_SUCCESS;
1718  }
1719  else
1720  {
1721  //The option length is not valid
1723  ret = SOCKET_ERROR;
1724  }
1725 #else
1726  //IPv6 is not supported
1728  ret = SOCKET_ERROR;
1729 #endif
1730 
1731  //Return status code
1732  return ret;
1733 }
1734 
1735 
1736 /**
1737  * @brief Set IPV6_UNICAST_HOPS option
1738  * @param[in] socket Handle referencing the socket
1739  * @param[in] optval A pointer to the buffer in which the value for the
1740  * requested option is specified
1741  * @param[in] optlen The size, in bytes, of the buffer pointed to by the optval
1742  * parameter
1743  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
1744  **/
1745 
1747  socklen_t optlen)
1748 {
1749  int_t ret;
1750 
1751 #if (IPV6_SUPPORT == ENABLED)
1752  //Check the length of the option
1753  if(optlen >= (socklen_t) sizeof(int_t))
1754  {
1755  //This option specifies the TTL value associated with an IPv6 socket
1756  //for unicast traffic
1757  socket->ttl = *optval;
1758 
1759  //Successful processing
1760  ret = SOCKET_SUCCESS;
1761  }
1762  else
1763  {
1764  //The option length is not valid
1766  ret = SOCKET_ERROR;
1767  }
1768 #else
1769  //IPv6 is not supported
1771  ret = SOCKET_ERROR;
1772 #endif
1773 
1774  //Return status code
1775  return ret;
1776 }
1777 
1778 
1779 /**
1780  * @brief Set IPV6_MULTICAST_IF option
1781  * @param[in] socket Handle referencing the socket
1782  * @param[in] optval A pointer to the buffer in which the value for the
1783  * requested option is specified
1784  * @param[in] optlen The size, in bytes, of the buffer pointed to by the optval
1785  * parameter
1786  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
1787  **/
1788 
1790  const struct in_addr *optval, socklen_t optlen)
1791 {
1792  int_t ret;
1793 
1794 #if (IPV6_SUPPORT == ENABLED)
1795  //Check the length of the option
1796  if(optlen >= (socklen_t) sizeof(IN_ADDR))
1797  {
1798  //Successful processing
1799  ret = SOCKET_SUCCESS;
1800  }
1801  else
1802  {
1803  //The option length is not valid
1805  ret = SOCKET_ERROR;
1806  }
1807 #else
1808  //IPv6 is not supported
1810  ret = SOCKET_ERROR;
1811 #endif
1812 
1813  //Return status code
1814  return ret;
1815 }
1816 
1817 
1818 /**
1819  * @brief Set IPV6_MULTICAST_HOPS option
1820  * @param[in] socket Handle referencing the socket
1821  * @param[in] optval A pointer to the buffer in which the value for the
1822  * requested option is specified
1823  * @param[in] optlen The size, in bytes, of the buffer pointed to by the optval
1824  * parameter
1825  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
1826  **/
1827 
1829  socklen_t optlen)
1830 {
1831  int_t ret;
1832 
1833 #if (IPV6_SUPPORT == ENABLED)
1834  //Check the length of the option
1835  if(optlen >= (socklen_t) sizeof(int_t))
1836  {
1837  //This option specifies the TTL value associated with an IPv6 socket
1838  //for multicast traffic
1839  socket->multicastTtl = *optval;
1840 
1841  //Successful processing
1842  ret = SOCKET_SUCCESS;
1843  }
1844  else
1845  {
1846  //The option length is not valid
1848  ret = SOCKET_ERROR;
1849  }
1850 #else
1851  //IPv6 is not supported
1853  ret = SOCKET_ERROR;
1854 #endif
1855 
1856  //Return status code
1857  return ret;
1858 }
1859 
1860 
1861 /**
1862  * @brief Set IPV6_MULTICAST_LOOP option
1863  * @param[in] socket Handle referencing the socket
1864  * @param[in] optval A pointer to the buffer in which the value for the
1865  * requested option is specified
1866  * @param[in] optlen The size, in bytes, of the buffer pointed to by the optval
1867  * parameter
1868  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
1869  **/
1870 
1872  socklen_t optlen)
1873 {
1874  int_t ret;
1875 
1876 #if (IPV6_SUPPORT == ENABLED)
1877  //Check the length of the option
1878  if(optlen >= (socklen_t) sizeof(int_t))
1879  {
1880  //Get exclusive access
1882 
1883  //For a socket that has joined one or more multicast groups, this option
1884  //controls whether it will receive a copy of outgoing packets sent to
1885  //those multicast groups
1886  if(*optval != 0)
1887  {
1889  }
1890  else
1891  {
1893  }
1894 
1895  //Release exclusive access
1897 
1898  //Successful processing
1899  ret = SOCKET_SUCCESS;
1900  }
1901  else
1902  {
1903  //The option length is not valid
1905  ret = SOCKET_ERROR;
1906  }
1907 #else
1908  //IPv6 is not supported
1910  ret = SOCKET_ERROR;
1911 #endif
1912 
1913  //Return status code
1914  return ret;
1915 }
1916 
1917 
1918 /**
1919  * @brief Set IPV6_ADD_MEMBERSHIP option
1920  * @param[in] socket Handle referencing the socket
1921  * @param[in] optval A pointer to the buffer in which the value for the
1922  * requested option is specified
1923  * @param[in] optlen The size, in bytes, of the buffer pointed to by the optval
1924  * parameter
1925  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
1926  **/
1927 
1929  const struct ipv6_mreq *optval, socklen_t optlen)
1930 {
1931  int_t ret;
1932 
1933 #if (IPV6_SUPPORT == ENABLED)
1934  //Check the length of the option
1935  if(optlen >= (socklen_t) sizeof(IPV6_MREQ))
1936  {
1937  error_t error;
1938  IpAddr groupAddr;
1939 
1940  //Copy group address
1941  groupAddr.length = sizeof(Ipv6Addr);
1942  ipv6CopyAddr(&groupAddr.ipv6Addr, optval->ipv6mr_multiaddr.s6_addr);
1943 
1944  //Join the specified multicast group
1946 
1947  //Check status code
1948  if(!error)
1949  {
1950  //Successful processing
1951  ret = SOCKET_SUCCESS;
1952  }
1953  else
1954  {
1955  //The multicast group cannot be joined
1957  ret = SOCKET_ERROR;
1958  }
1959  }
1960  else
1961  {
1962  //The option length is not valid
1964  ret = SOCKET_ERROR;
1965  }
1966 #else
1967  //IPv6 is not supported
1969  ret = SOCKET_ERROR;
1970 #endif
1971 
1972  //Return status code
1973  return ret;
1974 }
1975 
1976 
1977 /**
1978  * @brief Set IPV6_DROP_MEMBERSHIP option
1979  * @param[in] socket Handle referencing the socket
1980  * @param[in] optval A pointer to the buffer in which the value for the
1981  * requested option is specified
1982  * @param[in] optlen The size, in bytes, of the buffer pointed to by the optval
1983  * parameter
1984  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
1985  **/
1986 
1988  const struct ipv6_mreq *optval, socklen_t optlen)
1989 {
1990  int_t ret;
1991 
1992 #if (IPV6_SUPPORT == ENABLED)
1993  //Check the length of the option
1994  if(optlen >= (socklen_t) sizeof(IPV6_MREQ))
1995  {
1996  IpAddr groupAddr;
1997 
1998  //Copy group address
1999  groupAddr.length = sizeof(Ipv6Addr);
2000  ipv6CopyAddr(&groupAddr.ipv6Addr, optval->ipv6mr_multiaddr.s6_addr);
2001 
2002  //Leave the specified multicast group
2004 
2005  //Successful processing
2006  ret = SOCKET_SUCCESS;
2007  }
2008  else
2009  {
2010  //The option length is not valid
2012  ret = SOCKET_ERROR;
2013  }
2014 #else
2015  //IPv6 is not supported
2017  ret = SOCKET_ERROR;
2018 #endif
2019 
2020  //Return status code
2021  return ret;
2022 }
2023 
2024 
2025 /**
2026  * @brief Set IPV6_V6ONLY option
2027  * @param[in] socket Handle referencing the socket
2028  * @param[in] optval A pointer to the buffer in which the value for the
2029  * requested option is specified
2030  * @param[in] optlen The size, in bytes, of the buffer pointed to by the optval
2031  * parameter
2032  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
2033  **/
2034 
2036  socklen_t optlen)
2037 {
2038  int_t ret;
2039 
2040 #if (IPV6_SUPPORT == ENABLED)
2041  //Check the length of the option
2042  if(optlen >= (socklen_t) sizeof(int_t))
2043  {
2044  //Get exclusive access
2046 
2047  //This option indicates if a socket created for the AF_INET6 address
2048  //family is restricted to IPv6 communications only
2049  if(*optval != 0)
2050  {
2051  socket->options |= SOCKET_OPTION_IPV6_ONLY;
2052  }
2053  else
2054  {
2055  socket->options &= ~SOCKET_OPTION_IPV6_ONLY;
2056  }
2057 
2058  //Release exclusive access
2060 
2061  //Successful processing
2062  ret = SOCKET_SUCCESS;
2063  }
2064  else
2065  {
2066  //The option length is not valid
2068  ret = SOCKET_ERROR;
2069  }
2070 #else
2071  //IPv6 is not supported
2073  ret = SOCKET_ERROR;
2074 #endif
2075 
2076  //Return status code
2077  return ret;
2078 }
2079 
2080 
2081 /**
2082  * @brief Set IPV6_DONTFRAG option
2083  * @param[in] socket Handle referencing the socket
2084  * @param[in] optval A pointer to the buffer in which the value for the
2085  * requested option is specified
2086  * @param[in] optlen The size, in bytes, of the buffer pointed to by the optval
2087  * parameter
2088  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
2089  **/
2090 
2092  socklen_t optlen)
2093 {
2094  int_t ret;
2095 
2096 #if (IPV6_SUPPORT == ENABLED)
2097  //Check the length of the option
2098  if(optlen >= (socklen_t) sizeof(int_t))
2099  {
2100  //This option defines a mechanism to turn off the automatic inserting
2101  //of a fragment header for UDP and raw sockets (refer to RFC 3542,
2102  //section 11.2)
2103  if(*optval != 0)
2104  {
2106  }
2107  else
2108  {
2109  socket->options &= ~SOCKET_OPTION_IPV6_DONT_FRAG;
2110  }
2111  }
2112  else
2113  {
2114  //The option length is not valid
2116  ret = SOCKET_ERROR;
2117  }
2118 #else
2119  //IPv6 is not supported
2121  ret = SOCKET_ERROR;
2122 #endif
2123 
2124  //Return status code
2125  return ret;
2126 }
2127 
2128 
2129 /**
2130  * @brief Set IPV6_PKTINFO option
2131  * @param[in] socket Handle referencing the socket
2132  * @param[in] optval A pointer to the buffer in which the value for the
2133  * requested option is specified
2134  * @param[in] optlen The size, in bytes, of the buffer pointed to by the optval
2135  * parameter
2136  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
2137  **/
2138 
2140  socklen_t optlen)
2141 {
2142  int_t ret;
2143 
2144 #if (IPV6_SUPPORT == ENABLED)
2145  //Check the length of the option
2146  if(optlen >= (socklen_t) sizeof(int_t))
2147  {
2148  //Get exclusive access
2150 
2151  //This option allows an application to enable or disable the return of
2152  //packet information
2153  if(*optval != 0)
2154  {
2155  socket->options |= SOCKET_OPTION_IPV6_PKT_INFO;
2156  }
2157  else
2158  {
2159  socket->options &= ~SOCKET_OPTION_IPV6_PKT_INFO;
2160  }
2161 
2162  //Release exclusive access
2164 
2165  //Successful processing
2166  ret = SOCKET_SUCCESS;
2167  }
2168  else
2169  {
2170  //The option length is not valid
2172  ret = SOCKET_ERROR;
2173  }
2174 #else
2175  //IPv6 is not supported
2177  ret = SOCKET_ERROR;
2178 #endif
2179 
2180  //Return status code
2181  return ret;
2182 }
2183 
2184 
2185 /**
2186  * @brief Set IPV6_RECVTCLASS option
2187  * @param[in] socket Handle referencing the socket
2188  * @param[in] optval A pointer to the buffer in which the value for the
2189  * requested option is specified
2190  * @param[in] optlen The size, in bytes, of the buffer pointed to by the optval
2191  * parameter
2192  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
2193  **/
2194 
2196  socklen_t optlen)
2197 {
2198  int_t ret;
2199 
2200 #if (IPV6_SUPPORT == ENABLED)
2201  //Check the length of the option
2202  if(optlen >= (socklen_t) sizeof(int_t))
2203  {
2204  //Get exclusive access
2206 
2207  //This option allows an application to enable or disable the return of
2208  //Traffic Class header field on received datagrams
2209  if(*optval != 0)
2210  {
2212  }
2213  else
2214  {
2216  }
2217 
2218  //Release exclusive access
2220 
2221  //Successful processing
2222  ret = SOCKET_SUCCESS;
2223  }
2224  else
2225  {
2226  //The option length is not valid
2228  ret = SOCKET_ERROR;
2229  }
2230 #else
2231  //IPv6 is not supported
2233  ret = SOCKET_ERROR;
2234 #endif
2235 
2236  //Return status code
2237  return ret;
2238 }
2239 
2240 
2241 /**
2242  * @brief Set IPV6_RECVHOPLIMIT option
2243  * @param[in] socket Handle referencing the socket
2244  * @param[in] optval A pointer to the buffer in which the value for the
2245  * requested option is specified
2246  * @param[in] optlen The size, in bytes, of the buffer pointed to by the optval
2247  * parameter
2248  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
2249  **/
2250 
2252  socklen_t optlen)
2253 {
2254  int_t ret;
2255 
2256 #if (IPV6_SUPPORT == ENABLED)
2257  //Check the length of the option
2258  if(optlen >= (socklen_t) sizeof(int_t))
2259  {
2260  //Get exclusive access
2262 
2263  //This option allows an application to enable or disable the return of
2264  //Hop Limit header field on received datagrams
2265  if(*optval != 0)
2266  {
2268  }
2269  else
2270  {
2272  }
2273 
2274  //Release exclusive access
2276 
2277  //Successful processing
2278  ret = SOCKET_SUCCESS;
2279  }
2280  else
2281  {
2282  //The option length is not valid
2284  ret = SOCKET_ERROR;
2285  }
2286 #else
2287  //IPv6 is not supported
2289  ret = SOCKET_ERROR;
2290 #endif
2291 
2292  //Return status code
2293  return ret;
2294 }
2295 
2296 
2297 /**
2298  * @brief Set TCP_NODELAY option
2299  * @param[in] socket Handle referencing the socket
2300  * @param[in] optval A pointer to the buffer in which the value for the
2301  * requested option is specified
2302  * @param[in] optlen The size, in bytes, of the buffer pointed to by the optval
2303  * parameter
2304  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
2305  **/
2306 
2308  socklen_t optlen)
2309 {
2310  int_t ret;
2311 
2312 #if (TCP_SUPPORT == ENABLED)
2313  //Check the length of the option
2314  if(optlen >= (socklen_t) sizeof(int_t))
2315  {
2316  //Get exclusive access
2318 
2319  //The option enables or disables the Nagle algorithm for TCP sockets
2320  if(*optval != 0)
2321  {
2322  socket->options |= SOCKET_OPTION_TCP_NO_DELAY;
2323  }
2324  else
2325  {
2326  socket->options &= ~SOCKET_OPTION_TCP_NO_DELAY;
2327  }
2328 
2329  //Release exclusive access
2331 
2332  //Successful processing
2333  ret = SOCKET_SUCCESS;
2334  }
2335  else
2336  {
2337  //The option length is not valid
2339  ret = SOCKET_ERROR;
2340  }
2341 #else
2342  //TCP is not supported
2344  ret = SOCKET_ERROR;
2345 #endif
2346 
2347  //Return status code
2348  return ret;
2349 }
2350 
2351 
2352 /**
2353  * @brief Set TCP_MAXSEG option
2354  * @param[in] socket Handle referencing the socket
2355  * @param[in] optval A pointer to the buffer in which the value for the
2356  * requested option is specified
2357  * @param[in] optlen The size, in bytes, of the buffer pointed to by the optval
2358  * parameter
2359  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
2360  **/
2361 
2363  socklen_t optlen)
2364 {
2365  int_t ret;
2366 
2367 #if (TCP_SUPPORT == ENABLED)
2368  //Check the length of the option
2369  if(optlen >= (socklen_t) sizeof(int_t))
2370  {
2371  //Set the maximum segment size for outgoing TCP packets. If this option
2372  //is set before connection establishment, it also change the MSS value
2373  //announced to the other end in the initial SYN packet
2374  socketSetMaxSegmentSize(socket, *optval);
2375 
2376  //Successful processing
2377  ret = SOCKET_SUCCESS;
2378  }
2379  else
2380  {
2381  //The option length is not valid
2383  ret = SOCKET_ERROR;
2384  }
2385 #else
2386  //TCP is not supported
2388  ret = SOCKET_ERROR;
2389 #endif
2390 
2391  //Return status code
2392  return ret;
2393 }
2394 
2395 
2396 /**
2397  * @brief Set TCP_KEEPIDLE option
2398  * @param[in] socket Handle referencing the socket
2399  * @param[in] optval A pointer to the buffer in which the value for the
2400  * requested option is specified
2401  * @param[in] optlen The size, in bytes, of the buffer pointed to by the optval
2402  * parameter
2403  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
2404  **/
2405 
2407  socklen_t optlen)
2408 {
2409  int_t ret;
2410 
2411 #if (TCP_SUPPORT == ENABLED && TCP_KEEP_ALIVE_SUPPORT == ENABLED)
2412  //Check the length of the option
2413  if(optlen >= (socklen_t) sizeof(int_t))
2414  {
2415  //Convert the time interval to milliseconds
2416  socket->keepAliveIdle = *optval * 1000;
2417  //Successful processing
2418  ret = SOCKET_SUCCESS;
2419  }
2420  else
2421  {
2422  //The option length is not valid
2424  ret = SOCKET_ERROR;
2425  }
2426 #else
2427  //TCP keep-alive is not supported
2429  ret = SOCKET_ERROR;
2430 #endif
2431 
2432  //Return status code
2433  return ret;
2434 }
2435 
2436 
2437 /**
2438  * @brief Set TCP_KEEPINTVL option
2439  * @param[in] socket Handle referencing the socket
2440  * @param[in] optval A pointer to the buffer in which the value for the
2441  * requested option is specified
2442  * @param[in] optlen The size, in bytes, of the buffer pointed to by the optval
2443  * parameter
2444  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
2445  **/
2446 
2448  socklen_t optlen)
2449 {
2450  int_t ret;
2451 
2452 #if (TCP_SUPPORT == ENABLED && TCP_KEEP_ALIVE_SUPPORT == ENABLED)
2453  //Check the length of the option
2454  if(optlen >= (socklen_t) sizeof(int_t))
2455  {
2456  //Convert the time interval to milliseconds
2457  socket->keepAliveInterval = *optval * 1000;
2458  //Successful processing
2459  ret = SOCKET_SUCCESS;
2460  }
2461  else
2462  {
2463  //The option length is not valid
2465  ret = SOCKET_ERROR;
2466  }
2467 #else
2468  //TCP keep-alive is not supported
2470  ret = SOCKET_ERROR;
2471 #endif
2472 
2473  //Return status code
2474  return ret;
2475 }
2476 
2477 
2478 /**
2479  * @brief Set TCP_KEEPCNT option
2480  * @param[in] socket Handle referencing the socket
2481  * @param[in] optval A pointer to the buffer in which the value for the
2482  * requested option is specified
2483  * @param[in] optlen The size, in bytes, of the buffer pointed to by the optval
2484  * parameter
2485  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
2486  **/
2487 
2489  socklen_t optlen)
2490 {
2491  int_t ret;
2492 
2493 #if (TCP_SUPPORT == ENABLED && TCP_KEEP_ALIVE_SUPPORT == ENABLED)
2494  //Check the length of the option
2495  if(optlen >= (socklen_t) sizeof(int_t))
2496  {
2497  //Save parameter value
2498  socket->keepAliveMaxProbes = *optval;
2499  //Successful processing
2500  ret = SOCKET_SUCCESS;
2501  }
2502  else
2503  {
2504  //The option length is not valid
2506  ret = SOCKET_ERROR;
2507  }
2508 #else
2509  //TCP keep-alive is not supported
2511  ret = SOCKET_ERROR;
2512 #endif
2513 
2514  //Return status code
2515  return ret;
2516 }
2517 
2518 
2519 /**
2520  * @brief Get SO_REUSEADDR option
2521  * @param[in] socket Handle referencing the socket
2522  * @param[out] optval A pointer to the buffer in which the value for the
2523  * requested option is to be returned
2524  * @param[in,out] optlen The size, in bytes, of the buffer pointed to by the
2525  * optval parameter
2526  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
2527  **/
2528 
2530  socklen_t *optlen)
2531 {
2532  int_t ret;
2533 
2534  //Check the length of the option
2535  if(*optlen >= (socklen_t) sizeof(int_t))
2536  {
2537  //This option specifies whether the socket can be bound to an address
2538  //which is already in use
2539  if((socket->options & SOCKET_OPTION_REUSE_ADDR) != 0)
2540  {
2541  *optval = TRUE;
2542  }
2543  else
2544  {
2545  *optval = FALSE;
2546  }
2547 
2548  //Return the actual length of the option
2549  *optlen = sizeof(int_t);
2550 
2551  //Successful processing
2552  ret = SOCKET_SUCCESS;
2553  }
2554  else
2555  {
2556  //The option length is not valid
2558  ret = SOCKET_ERROR;
2559  }
2560 
2561  //Return status code
2562  return ret;
2563 }
2564 
2565 
2566 /**
2567  * @brief Get SO_TYPE option
2568  * @param[in] socket Handle referencing the socket
2569  * @param[out] optval A pointer to the buffer in which the value for the
2570  * requested option is to be returned
2571  * @param[in,out] optlen The size, in bytes, of the buffer pointed to by the
2572  * optval parameter
2573  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
2574  **/
2575 
2577  socklen_t *optlen)
2578 {
2579  int_t ret;
2580 
2581  //Check the length of the option
2582  if(*optlen >= (socklen_t) sizeof(int_t))
2583  {
2584  //Return the type of the socket
2585  if(socket->type == SOCKET_TYPE_STREAM)
2586  {
2587  *optval = SOCK_STREAM;
2588  }
2589  else if(socket->type == SOCKET_TYPE_DGRAM)
2590  {
2591  *optval = SOCK_DGRAM;
2592  }
2593  else
2594  {
2595  *optval = SOCK_RAW;
2596  }
2597 
2598  //Return the actual length of the option
2599  *optlen = sizeof(int_t);
2600 
2601  //Successful processing
2602  ret = SOCKET_SUCCESS;
2603  }
2604  else
2605  {
2606  //The option length is not valid
2608  ret = SOCKET_ERROR;
2609  }
2610 
2611  //Return status code
2612  return ret;
2613 }
2614 
2615 
2616 /**
2617  * @brief Get SO_ERROR option
2618  * @param[in] socket Handle referencing the socket
2619  * @param[out] optval A pointer to the buffer in which the value for the
2620  * requested option is to be returned
2621  * @param[in,out] optlen The size, in bytes, of the buffer pointed to by the
2622  * optval parameter
2623  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
2624  **/
2625 
2627  socklen_t *optlen)
2628 {
2629  int_t ret;
2630 
2631  //Check the length of the option
2632  if(*optlen >= (socklen_t) sizeof(int_t))
2633  {
2634  //Return the error code
2635  *optval = socket->errnoCode;
2636  //Return the actual length of the option
2637  *optlen = sizeof(int_t);
2638 
2639  //Clear error status
2640  socket->errnoCode = 0;
2641 
2642  //Successful processing
2643  ret = SOCKET_SUCCESS;
2644  }
2645  else
2646  {
2647  //The option length is not valid
2649  ret = SOCKET_ERROR;
2650  }
2651 
2652  //Return status code
2653  return ret;
2654 }
2655 
2656 
2657 /**
2658  * @brief Get SO_BROADCAST option
2659  * @param[in] socket Handle referencing the socket
2660  * @param[out] optval A pointer to the buffer in which the value for the
2661  * requested option is to be returned
2662  * @param[in,out] optlen The size, in bytes, of the buffer pointed to by the
2663  * optval parameter
2664  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
2665  **/
2666 
2668  socklen_t *optlen)
2669 {
2670  int_t ret;
2671 
2672  //Check the length of the option
2673  if(*optlen >= (socklen_t) sizeof(int_t))
2674  {
2675  //This option specifies whether transmission and receipt of broadcast
2676  //messages are allowed
2677  if((socket->options & SOCKET_OPTION_BROADCAST) != 0)
2678  {
2679  *optval = TRUE;
2680  }
2681  else
2682  {
2683  *optval = FALSE;
2684  }
2685 
2686  //Return the actual length of the option
2687  *optlen = sizeof(int_t);
2688 
2689  //Successful processing
2690  ret = SOCKET_SUCCESS;
2691  }
2692  else
2693  {
2694  //The option length is not valid
2696  ret = SOCKET_ERROR;
2697  }
2698 
2699  //Return status code
2700  return ret;
2701 }
2702 
2703 
2704 /**
2705  * @brief Get SO_SNDTIMEO option
2706  * @param[in] socket Handle referencing the socket
2707  * @param[out] optval A pointer to the buffer in which the value for the
2708  * requested option is to be returned
2709  * @param[in,out] optlen The size, in bytes, of the buffer pointed to by the
2710  * optval parameter
2711  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
2712  **/
2713 
2715  socklen_t *optlen)
2716 {
2717  int_t ret;
2718 
2719  //Check the length of the option
2720  if(*optlen >= (socklen_t) sizeof(struct timeval))
2721  {
2722  //Return the timeout value
2723  if(socket->timeout == INFINITE_DELAY)
2724  {
2725  optval->tv_sec = 0;
2726  optval->tv_usec = 0;
2727  }
2728  else
2729  {
2730  optval->tv_sec = socket->timeout / 1000;
2731  optval->tv_usec = (socket->timeout % 1000) * 1000;
2732  }
2733 
2734  //Return the actual length of the option
2735  *optlen = sizeof(struct timeval);
2736  //Successful processing
2737  ret = SOCKET_SUCCESS;
2738  }
2739  else
2740  {
2741  //The option length is not valid
2743  ret = SOCKET_ERROR;
2744  }
2745 
2746  //Return status code
2747  return ret;
2748 }
2749 
2750 
2751 /**
2752  * @brief Get SO_RCVTIMEO option
2753  * @param[in] socket Handle referencing the socket
2754  * @param[out] optval A pointer to the buffer in which the value for the
2755  * requested option is to be returned
2756  * @param[in,out] optlen The size, in bytes, of the buffer pointed to by the
2757  * optval parameter
2758  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
2759  **/
2760 
2762  socklen_t *optlen)
2763 {
2764  int_t ret;
2765 
2766  //Check the length of the option
2767  if(*optlen >= (socklen_t) sizeof(struct timeval))
2768  {
2769  //Return the timeout value
2770  if(socket->timeout == INFINITE_DELAY)
2771  {
2772  optval->tv_sec = 0;
2773  optval->tv_usec = 0;
2774  }
2775  else
2776  {
2777  optval->tv_sec = socket->timeout / 1000;
2778  optval->tv_usec = (socket->timeout % 1000) * 1000;
2779  }
2780 
2781  //Return the actual length of the option
2782  *optlen = sizeof(struct timeval);
2783  //Successful processing
2784  ret = SOCKET_SUCCESS;
2785  }
2786  else
2787  {
2788  //The option length is not valid
2790  ret = SOCKET_ERROR;
2791  }
2792 
2793  //Return status code
2794  return ret;
2795 }
2796 
2797 
2798 /**
2799  * @brief Get SO_SNDBUF option
2800  * @param[in] socket Handle referencing the socket
2801  * @param[out] optval A pointer to the buffer in which the value for the
2802  * requested option is to be returned
2803  * @param[in,out] optlen The size, in bytes, of the buffer pointed to by the
2804  * optval parameter
2805  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
2806  **/
2807 
2809  socklen_t *optlen)
2810 {
2811  int_t ret;
2812 
2813 #if (TCP_SUPPORT == ENABLED)
2814  //Check the length of the option
2815  if(*optlen >= (socklen_t) sizeof(int_t))
2816  {
2817  //Return the size of the send buffer
2818  *optval = socket->txBufferSize;
2819  //Return the actual length of the option
2820  *optlen = sizeof(int_t);
2821  //Successful processing
2822  ret = SOCKET_SUCCESS;
2823  }
2824  else
2825  {
2826  //The option length is not valid
2828  ret = SOCKET_ERROR;
2829  }
2830 #else
2831  //TCP is not supported
2833  ret = SOCKET_ERROR;
2834 #endif
2835 
2836  //Return status code
2837  return ret;
2838 }
2839 
2840 
2841 /**
2842  * @brief Get SO_RCVBUF option
2843  * @param[in] socket Handle referencing the socket
2844  * @param[out] optval A pointer to the buffer in which the value for the
2845  * requested option is to be returned
2846  * @param[in,out] optlen The size, in bytes, of the buffer pointed to by the
2847  * optval parameter
2848  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
2849  **/
2850 
2852  socklen_t *optlen)
2853 {
2854  int_t ret;
2855 
2856 #if (TCP_SUPPORT == ENABLED)
2857  //Check the length of the option
2858  if(*optlen >= (socklen_t) sizeof(int_t))
2859  {
2860  //Return the size of the receive buffer
2861  *optval = socket->rxBufferSize;
2862  //Return the actual length of the option
2863  *optlen = sizeof(int_t);
2864  //Successful processing
2865  ret = SOCKET_SUCCESS;
2866  }
2867  else
2868  {
2869  //The option length is not valid
2871  ret = SOCKET_ERROR;
2872  }
2873 #else
2874  //TCP is not supported
2876  ret = SOCKET_ERROR;
2877 #endif
2878 
2879  //Return status code
2880  return ret;
2881 }
2882 
2883 
2884 /**
2885  * @brief Get SO_KEEPALIVE option
2886  * @param[in] socket Handle referencing the socket
2887  * @param[out] optval A pointer to the buffer in which the value for the
2888  * requested option is to be returned
2889  * @param[in,out] optlen The size, in bytes, of the buffer pointed to by the
2890  * optval parameter
2891  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
2892  **/
2893 
2895  socklen_t *optlen)
2896 {
2897  int_t ret;
2898 
2899 #if (TCP_SUPPORT == ENABLED && TCP_KEEP_ALIVE_SUPPORT == ENABLED)
2900  //Check the length of the option
2901  if(*optlen >= (socklen_t) sizeof(int_t))
2902  {
2903  //This option specifies whether TCP keep-alive is enabled
2904  *optval = socket->keepAliveEnabled;
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  //TCP keep-alive is not supported
2917  ret = SOCKET_ERROR;
2918 #endif
2919 
2920  //Return status code
2921  return ret;
2922 }
2923 
2924 
2925 /**
2926  * @brief Get SO_NO_CHECK 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 (UDP_SUPPORT == ENABLED)
2941  //Check the length of the option
2942  if(*optlen >= (socklen_t) sizeof(int_t))
2943  {
2944  //This option allows UDP checksum generation to be bypassed
2945  if((socket->options & SOCKET_OPTION_UDP_NO_CHECKSUM) != 0)
2946  {
2947  *optval = TRUE;
2948  }
2949  else
2950  {
2951  *optval = FALSE;
2952  }
2953 
2954  //Return the actual length of the option
2955  *optlen = sizeof(int_t);
2956 
2957  //Successful processing
2958  ret = SOCKET_SUCCESS;
2959  }
2960  else
2961  {
2962  //The option length is not valid
2964  ret = SOCKET_ERROR;
2965  }
2966 #else
2967  //IPv4 is not supported
2969  ret = SOCKET_ERROR;
2970 #endif
2971 
2972  //Return status code
2973  return ret;
2974 }
2975 
2976 
2977 /**
2978  * @brief Get IP_TOS option
2979  * @param[in] socket Handle referencing the socket
2980  * @param[out] optval A pointer to the buffer in which the value for the
2981  * requested option is to be returned
2982  * @param[in,out] optlen The size, in bytes, of the buffer pointed to by the
2983  * optval parameter
2984  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
2985  **/
2986 
2988  socklen_t *optlen)
2989 {
2990  int_t ret;
2991 
2992 #if (IPV4_SUPPORT == ENABLED)
2993  //Check the length of the option
2994  if(*optlen >= (socklen_t) sizeof(int_t))
2995  {
2996  //Return ToS value
2997  *optval = socket->tos;
2998  //Return the actual length of the option
2999  *optlen = sizeof(int_t);
3000 
3001  //Successful processing
3002  ret = SOCKET_SUCCESS;
3003  }
3004  else
3005  {
3006  //The option length is not valid
3008  ret = SOCKET_ERROR;
3009  }
3010 #else
3011  //IPv4 is not supported
3013  ret = SOCKET_ERROR;
3014 #endif
3015 
3016  //Return status code
3017  return ret;
3018 }
3019 
3020 
3021 /**
3022  * @brief Get IP_TTL option
3023  * @param[in] socket Handle referencing the socket
3024  * @param[out] optval A pointer to the buffer in which the value for the
3025  * requested option is to be returned
3026  * @param[in,out] optlen The size, in bytes, of the buffer pointed to by the
3027  * optval parameter
3028  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
3029  **/
3030 
3032  socklen_t *optlen)
3033 {
3034  int_t ret;
3035 
3036 #if (IPV4_SUPPORT == ENABLED)
3037  //Check the length of the option
3038  if(*optlen >= (socklen_t) sizeof(int_t))
3039  {
3040  //Return TTL value
3041  *optval = socket->ttl;
3042  //Return the actual length of the option
3043  *optlen = sizeof(int_t);
3044 
3045  //Successful processing
3046  ret = SOCKET_SUCCESS;
3047  }
3048  else
3049  {
3050  //The option length is not valid
3052  ret = SOCKET_ERROR;
3053  }
3054 #else
3055  //IPv4 is not supported
3057  ret = SOCKET_ERROR;
3058 #endif
3059 
3060  //Return status code
3061  return ret;
3062 }
3063 
3064 
3065 /**
3066  * @brief Get IP_MULTICAST_TTL option
3067  * @param[in] socket Handle referencing the socket
3068  * @param[out] optval A pointer to the buffer in which the value for the
3069  * requested option is to be returned
3070  * @param[in,out] optlen The size, in bytes, of the buffer pointed to by the
3071  * optval parameter
3072  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
3073  **/
3074 
3076  socklen_t *optlen)
3077 {
3078  int_t ret;
3079 
3080 #if (IPV4_SUPPORT == ENABLED)
3081  //Check the length of the option
3082  if(*optlen >= (socklen_t) sizeof(int_t))
3083  {
3084  //Return TTL value for multicast packets
3085  *optval = socket->multicastTtl;
3086  //Return the actual length of the option
3087  *optlen = sizeof(int_t);
3088 
3089  //Successful processing
3090  ret = SOCKET_SUCCESS;
3091  }
3092  else
3093  {
3094  //The option length is not valid
3096  ret = SOCKET_ERROR;
3097  }
3098 #else
3099  //IPv4 is not supported
3101  ret = SOCKET_ERROR;
3102 #endif
3103 
3104  //Return status code
3105  return ret;
3106 }
3107 
3108 
3109 /**
3110  * @brief Get IP_MULTICAST_LOOP option
3111  * @param[in] socket Handle referencing the socket
3112  * @param[out] optval A pointer to the buffer in which the value for the
3113  * requested option is to be returned
3114  * @param[in,out] optlen The size, in bytes, of the buffer pointed to by the
3115  * optval parameter
3116  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
3117  **/
3118 
3120  socklen_t *optlen)
3121 {
3122  int_t ret;
3123 
3124 #if (IPV4_SUPPORT == ENABLED)
3125  //Check the length of the option
3126  if(*optlen >= (socklen_t) sizeof(int_t))
3127  {
3128  //For a socket that has joined one or more multicast groups, this option
3129  //controls whether it will receive a copy of outgoing packets sent to
3130  //those multicast groups
3131  if((socket->options & SOCKET_OPTION_IPV4_MULTICAST_LOOP) != 0)
3132  {
3133  *optval = TRUE;
3134  }
3135  else
3136  {
3137  *optval = FALSE;
3138  }
3139 
3140  //Return the actual length of the option
3141  *optlen = sizeof(int_t);
3142 
3143  //Successful processing
3144  ret = SOCKET_SUCCESS;
3145  }
3146  else
3147  {
3148  //The option length is not valid
3150  ret = SOCKET_ERROR;
3151  }
3152 #else
3153  //IPv4 is not supported
3155  ret = SOCKET_ERROR;
3156 #endif
3157 
3158  //Return status code
3159  return ret;
3160 }
3161 
3162 
3163 /**
3164  * @brief Get IP_DONTFRAG option
3165  * @param[in] socket Handle referencing the socket
3166  * @param[out] optval A pointer to the buffer in which the value for the
3167  * requested option is to be returned
3168  * @param[in,out] optlen The size, in bytes, of the buffer pointed to by the
3169  * optval parameter
3170  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
3171  **/
3172 
3174  socklen_t *optlen)
3175 {
3176  int_t ret;
3177 
3178 #if (IPV4_SUPPORT == ENABLED)
3179  //Check the length of the option
3180  if(*optlen >= (socklen_t) sizeof(int_t))
3181  {
3182  //This option can be used to set the "don't fragment" flag on IP packets
3183  if((socket->options & SOCKET_OPTION_IPV4_DONT_FRAG) != 0)
3184  {
3185  *optval = TRUE;
3186  }
3187  else
3188  {
3189  *optval = FALSE;
3190  }
3191 
3192  //Return the actual length of the option
3193  *optlen = sizeof(int_t);
3194 
3195  //Successful processing
3196  ret = SOCKET_SUCCESS;
3197  }
3198  else
3199  {
3200  //The option length is not valid
3202  ret = SOCKET_ERROR;
3203  }
3204 #else
3205  //IPv4 is not supported
3207  ret = SOCKET_ERROR;
3208 #endif
3209 
3210  //Return status code
3211  return ret;
3212 }
3213 
3214 
3215 /**
3216  * @brief Get IP_PKTINFO option
3217  * @param[in] socket Handle referencing the socket
3218  * @param[out] optval A pointer to the buffer in which the value for the
3219  * requested option is to be returned
3220  * @param[in,out] optlen The size, in bytes, of the buffer pointed to by the
3221  * optval parameter
3222  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
3223  **/
3224 
3226  socklen_t *optlen)
3227 {
3228  int_t ret;
3229 
3230 #if (IPV4_SUPPORT == ENABLED)
3231  //Check the length of the option
3232  if(*optlen >= (socklen_t) sizeof(int_t))
3233  {
3234  //This option allows an application to enable or disable the return of
3235  //packet information
3236  if((socket->options & SOCKET_OPTION_IPV4_PKT_INFO) != 0)
3237  {
3238  *optval = TRUE;
3239  }
3240  else
3241  {
3242  *optval = FALSE;
3243  }
3244 
3245  //Return the actual length of the option
3246  *optlen = sizeof(int_t);
3247 
3248  //Successful processing
3249  ret = SOCKET_SUCCESS;
3250  }
3251  else
3252  {
3253  //The option length is not valid
3255  ret = SOCKET_ERROR;
3256  }
3257 #else
3258  //IPv4 is not supported
3260  ret = SOCKET_ERROR;
3261 #endif
3262 
3263  //Return status code
3264  return ret;
3265 }
3266 
3267 
3268 /**
3269  * @brief Get IP_RECVTOS option
3270  * @param[in] socket Handle referencing the socket
3271  * @param[out] optval A pointer to the buffer in which the value for the
3272  * requested option is to be returned
3273  * @param[in,out] optlen The size, in bytes, of the buffer pointed to by the
3274  * optval parameter
3275  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
3276  **/
3277 
3279  socklen_t *optlen)
3280 {
3281  int_t ret;
3282 
3283 #if (IPV4_SUPPORT == ENABLED)
3284  //Check the length of the option
3285  if(*optlen >= (socklen_t) sizeof(int_t))
3286  {
3287  //This option allows an application to enable or disable the return of
3288  //ToS header field on received datagrams
3289  if((socket->options & SOCKET_OPTION_IPV4_RECV_TOS) != 0)
3290  {
3291  *optval = TRUE;
3292  }
3293  else
3294  {
3295  *optval = FALSE;
3296  }
3297 
3298  //Return the actual length of the option
3299  *optlen = sizeof(int_t);
3300 
3301  //Successful processing
3302  ret = SOCKET_SUCCESS;
3303  }
3304  else
3305  {
3306  //The option length is not valid
3308  ret = SOCKET_ERROR;
3309  }
3310 #else
3311  //IPv4 is not supported
3313  ret = SOCKET_ERROR;
3314 #endif
3315 
3316  //Return status code
3317  return ret;
3318 }
3319 
3320 
3321 /**
3322  * @brief Get IP_RECVTTL option
3323  * @param[in] socket Handle referencing the socket
3324  * @param[out] optval A pointer to the buffer in which the value for the
3325  * requested option is to be returned
3326  * @param[in,out] optlen The size, in bytes, of the buffer pointed to by the
3327  * optval parameter
3328  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
3329  **/
3330 
3332  socklen_t *optlen)
3333 {
3334  int_t ret;
3335 
3336 #if (IPV4_SUPPORT == ENABLED)
3337  //Check the length of the option
3338  if(*optlen >= (socklen_t) sizeof(int_t))
3339  {
3340  //This option allows an application to enable or disable the return of
3341  //TTL header field on received datagrams
3342  if((socket->options & SOCKET_OPTION_IPV4_RECV_TTL) != 0)
3343  {
3344  *optval = TRUE;
3345  }
3346  else
3347  {
3348  *optval = FALSE;
3349  }
3350 
3351  //Return the actual length of the option
3352  *optlen = sizeof(int_t);
3353 
3354  //Successful processing
3355  ret = SOCKET_SUCCESS;
3356  }
3357  else
3358  {
3359  //The option length is not valid
3361  ret = SOCKET_ERROR;
3362  }
3363 #else
3364  //IPv4 is not supported
3366  ret = SOCKET_ERROR;
3367 #endif
3368 
3369  //Return status code
3370  return ret;
3371 }
3372 
3373 
3374 /**
3375  * @brief Get IPV6_TCLASS option
3376  * @param[in] socket Handle referencing the socket
3377  * @param[out] optval A pointer to the buffer in which the value for the
3378  * requested option is to be returned
3379  * @param[in,out] optlen The size, in bytes, of the buffer pointed to by the
3380  * optval parameter
3381  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
3382  **/
3383 
3385  socklen_t *optlen)
3386 {
3387  int_t ret;
3388 
3389 #if (IPV6_SUPPORT == ENABLED)
3390  //Check the length of the option
3391  if(*optlen >= (socklen_t) sizeof(int_t))
3392  {
3393  //Return Traffic Class value
3394  *optval = socket->tos;
3395  //Return the actual length of the option
3396  *optlen = sizeof(int_t);
3397 
3398  //Successful processing
3399  ret = SOCKET_SUCCESS;
3400  }
3401  else
3402  {
3403  //The option length is not valid
3405  ret = SOCKET_ERROR;
3406  }
3407 #else
3408  //IPv6 is not supported
3410  ret = SOCKET_ERROR;
3411 #endif
3412 
3413  //Return status code
3414  return ret;
3415 }
3416 
3417 
3418 /**
3419  * @brief Get IPV6_UNICAST_HOPS option
3420  * @param[in] socket Handle referencing the socket
3421  * @param[out] optval A pointer to the buffer in which the value for the
3422  * requested option is to be returned
3423  * @param[in,out] optlen The size, in bytes, of the buffer pointed to by the
3424  * optval parameter
3425  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
3426  **/
3427 
3429  socklen_t *optlen)
3430 {
3431  int_t ret;
3432 
3433 #if (IPV6_SUPPORT == ENABLED)
3434  //Check the length of the option
3435  if(*optlen >= (socklen_t) sizeof(int_t))
3436  {
3437  //This option specifies the TTL value associated with an IPv6 socket
3438  //for unicast traffic
3439  *optval = socket->ttl;
3440 
3441  //Return the actual length of the option
3442  *optlen = sizeof(int_t);
3443 
3444  //Successful processing
3445  ret = SOCKET_SUCCESS;
3446  }
3447  else
3448  {
3449  //The option length is not valid
3451  ret = SOCKET_ERROR;
3452  }
3453 #else
3454  //IPv6 is not supported
3456  ret = SOCKET_ERROR;
3457 #endif
3458 
3459  //Return status code
3460  return ret;
3461 }
3462 
3463 
3464 /**
3465  * @brief Get IPV6_MULTICAST_HOPS option
3466  * @param[in] socket Handle referencing the socket
3467  * @param[out] optval A pointer to the buffer in which the value for the
3468  * requested option is to be returned
3469  * @param[in,out] optlen The size, in bytes, of the buffer pointed to by the
3470  * optval parameter
3471  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
3472  **/
3473 
3475  socklen_t *optlen)
3476 {
3477  int_t ret;
3478 
3479 #if (IPV6_SUPPORT == ENABLED)
3480  //Check the length of the option
3481  if(*optlen >= (socklen_t) sizeof(int_t))
3482  {
3483  //This option specifies the TTL value associated with an IPv6 socket
3484  //for multicast traffic
3485  *optval = socket->multicastTtl;
3486 
3487  //Return the actual length of the option
3488  *optlen = sizeof(int_t);
3489 
3490  //Successful processing
3491  ret = SOCKET_SUCCESS;
3492  }
3493  else
3494  {
3495  //The option length is not valid
3497  ret = SOCKET_ERROR;
3498  }
3499 #else
3500  //IPv6 is not supported
3502  ret = SOCKET_ERROR;
3503 #endif
3504 
3505  //Return status code
3506  return ret;
3507 }
3508 
3509 
3510 /**
3511  * @brief Get IPV6_MULTICAST_LOOP option
3512  * @param[in] socket Handle referencing the socket
3513  * @param[out] optval A pointer to the buffer in which the value for the
3514  * requested option is to be returned
3515  * @param[in,out] optlen The size, in bytes, of the buffer pointed to by the
3516  * optval parameter
3517  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
3518  **/
3519 
3521  socklen_t *optlen)
3522 {
3523  int_t ret;
3524 
3525 #if (IPV6_SUPPORT == ENABLED)
3526  //Check the length of the option
3527  if(*optlen >= (socklen_t) sizeof(int_t))
3528  {
3529  //For a socket that has joined one or more multicast groups, this option
3530  //controls whether it will receive a copy of outgoing packets sent to
3531  //those multicast groups
3532  if((socket->options & SOCKET_OPTION_IPV6_MULTICAST_LOOP) != 0)
3533  {
3534  *optval = TRUE;
3535  }
3536  else
3537  {
3538  *optval = FALSE;
3539  }
3540 
3541  //Return the actual length of the option
3542  *optlen = sizeof(int_t);
3543 
3544  //Successful processing
3545  ret = SOCKET_SUCCESS;
3546  }
3547  else
3548  {
3549  //The option length is not valid
3551  ret = SOCKET_ERROR;
3552  }
3553 #else
3554  //IPv6 is not supported
3556  ret = SOCKET_ERROR;
3557 #endif
3558 
3559  //Return status code
3560  return ret;
3561 }
3562 
3563 /**
3564  * @brief Get IPV6_V6ONLY option
3565  * @param[in] socket Handle referencing the socket
3566  * @param[out] optval A pointer to the buffer in which the value for the
3567  * requested option is to be returned
3568  * @param[in,out] optlen The size, in bytes, of the buffer pointed to by the
3569  * optval parameter
3570  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
3571  **/
3572 
3574  socklen_t *optlen)
3575 {
3576  int_t ret;
3577 
3578 #if (IPV6_SUPPORT == ENABLED)
3579  //Check the length of the option
3580  if(*optlen >= (socklen_t) sizeof(int_t))
3581  {
3582  //This option indicates if a socket created for the AF_INET6 address
3583  //family is restricted to IPv6 communications only
3584  if((socket->options & SOCKET_OPTION_IPV6_ONLY) != 0)
3585  {
3586  *optval = TRUE;
3587  }
3588  else
3589  {
3590  *optval = FALSE;
3591  }
3592 
3593  //Return the actual length of the option
3594  *optlen = sizeof(int_t);
3595 
3596  //Successful processing
3597  ret = SOCKET_SUCCESS;
3598  }
3599  else
3600  {
3601  //The option length is not valid
3603  ret = SOCKET_ERROR;
3604  }
3605 #else
3606  //IPv6 is not supported
3608  ret = SOCKET_ERROR;
3609 #endif
3610 
3611  //Return status code
3612  return ret;
3613 }
3614 
3615 
3616 /**
3617  * @brief Get IPV6_DONTFRAG option
3618  * @param[in] socket Handle referencing the socket
3619  * @param[out] optval A pointer to the buffer in which the value for the
3620  * requested option is to be returned
3621  * @param[in,out] optlen The size, in bytes, of the buffer pointed to by the
3622  * optval parameter
3623  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
3624  **/
3625 
3627  socklen_t *optlen)
3628 {
3629  int_t ret;
3630 
3631 #if (IPV6_SUPPORT == ENABLED)
3632  //Check the length of the option
3633  if(*optlen >= (socklen_t) sizeof(int_t))
3634  {
3635  //This option defines a mechanism to turn off the automatic inserting
3636  //of a fragment header for UDP and raw sockets (refer to RFC 3542,
3637  //section 11.2)
3638  if((socket->options & SOCKET_OPTION_IPV6_DONT_FRAG) != 0)
3639  {
3640  *optval = TRUE;
3641  }
3642  else
3643  {
3644  *optval = FALSE;
3645  }
3646 
3647  //Return the actual length of the option
3648  *optlen = sizeof(int_t);
3649 
3650  //Successful processing
3651  ret = SOCKET_SUCCESS;
3652  }
3653  else
3654  {
3655  //The option length is not valid
3657  ret = SOCKET_ERROR;
3658  }
3659 #else
3660  //IPv6 is not supported
3662  ret = SOCKET_ERROR;
3663 #endif
3664 
3665  //Return status code
3666  return ret;
3667 }
3668 
3669 
3670 /**
3671  * @brief Get IPV6_PKTINFO option
3672  * @param[in] socket Handle referencing the socket
3673  * @param[out] optval A pointer to the buffer in which the value for the
3674  * requested option is to be returned
3675  * @param[in,out] optlen The size, in bytes, of the buffer pointed to by the
3676  * optval parameter
3677  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
3678  **/
3679 
3681  socklen_t *optlen)
3682 {
3683  int_t ret;
3684 
3685 #if (IPV6_SUPPORT == ENABLED)
3686  //Check the length of the option
3687  if(*optlen >= (socklen_t) sizeof(int_t))
3688  {
3689  //This option allows an application to enable or disable the return of
3690  //packet information
3691  if((socket->options & SOCKET_OPTION_IPV6_PKT_INFO) != 0)
3692  {
3693  *optval = TRUE;
3694  }
3695  else
3696  {
3697  *optval = FALSE;
3698  }
3699 
3700  //Return the actual length of the option
3701  *optlen = sizeof(int_t);
3702 
3703  //Successful processing
3704  ret = SOCKET_SUCCESS;
3705  }
3706  else
3707  {
3708  //The option length is not valid
3710  ret = SOCKET_ERROR;
3711  }
3712 #else
3713  //IPv6 is not supported
3715  ret = SOCKET_ERROR;
3716 #endif
3717 
3718  //Return status code
3719  return ret;
3720 }
3721 
3722 
3723 /**
3724  * @brief Get IPV6_RECVTCLASS option
3725  * @param[in] socket Handle referencing the socket
3726  * @param[out] optval A pointer to the buffer in which the value for the
3727  * requested option is to be returned
3728  * @param[in,out] optlen The size, in bytes, of the buffer pointed to by the
3729  * optval parameter
3730  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
3731  **/
3732 
3734  socklen_t *optlen)
3735 {
3736  int_t ret;
3737 
3738 #if (IPV6_SUPPORT == ENABLED)
3739  //Check the length of the option
3740  if(*optlen >= (socklen_t) sizeof(int_t))
3741  {
3742  //This option allows an application to enable or disable the return of
3743  //Traffic Class header field on received datagrams
3744  if((socket->options & SOCKET_OPTION_IPV6_RECV_TRAFFIC_CLASS) != 0)
3745  {
3746  *optval = TRUE;
3747  }
3748  else
3749  {
3750  *optval = FALSE;
3751  }
3752 
3753  //Return the actual length of the option
3754  *optlen = sizeof(int_t);
3755 
3756  //Successful processing
3757  ret = SOCKET_SUCCESS;
3758  }
3759  else
3760  {
3761  //The option length is not valid
3763  ret = SOCKET_ERROR;
3764  }
3765 #else
3766  //IPv6 is not supported
3768  ret = SOCKET_ERROR;
3769 #endif
3770 
3771  //Return status code
3772  return ret;
3773 }
3774 
3775 
3776 /**
3777  * @brief Get IPV6_RECVHOPLIMIT option
3778  * @param[in] socket Handle referencing the socket
3779  * @param[out] optval A pointer to the buffer in which the value for the
3780  * requested option is to be returned
3781  * @param[in,out] optlen The size, in bytes, of the buffer pointed to by the
3782  * optval parameter
3783  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
3784  **/
3785 
3787  socklen_t *optlen)
3788 {
3789  int_t ret;
3790 
3791 #if (IPV6_SUPPORT == ENABLED)
3792  //Check the length of the option
3793  if(*optlen >= (socklen_t) sizeof(int_t))
3794  {
3795  //This option allows an application to enable or disable the return of
3796  //Hop Limit header field on received datagrams
3797  if((socket->options & SOCKET_OPTION_IPV6_RECV_HOP_LIMIT) != 0)
3798  {
3799  *optval = TRUE;
3800  }
3801  else
3802  {
3803  *optval = FALSE;
3804  }
3805 
3806  //Return the actual length of the option
3807  *optlen = sizeof(int_t);
3808 
3809  //Successful processing
3810  ret = SOCKET_SUCCESS;
3811  }
3812  else
3813  {
3814  //The option length is not valid
3816  ret = SOCKET_ERROR;
3817  }
3818 #else
3819  //IPv6 is not supported
3821  ret = SOCKET_ERROR;
3822 #endif
3823 
3824  //Return status code
3825  return ret;
3826 }
3827 
3828 
3829 /**
3830  * @brief Get TCP_NODELAY option
3831  * @param[in] socket Handle referencing the socket
3832  * @param[out] optval A pointer to the buffer in which the value for the
3833  * requested option is to be returned
3834  * @param[in,out] optlen The size, in bytes, of the buffer pointed to by the
3835  * optval parameter
3836  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
3837  **/
3838 
3840  socklen_t *optlen)
3841 {
3842  int_t ret;
3843 
3844 #if (TCP_SUPPORT == ENABLED)
3845  //Check the length of the option
3846  if(*optlen >= (socklen_t) sizeof(int_t))
3847  {
3848  //The option enables or disables the Nagle algorithm for TCP sockets
3849  if((socket->options & SOCKET_OPTION_TCP_NO_DELAY) != 0)
3850  {
3851  *optval = TRUE;
3852  }
3853  else
3854  {
3855  *optval = FALSE;
3856  }
3857 
3858  //Return the actual length of the option
3859  *optlen = sizeof(int_t);
3860 
3861  //Successful processing
3862  ret = SOCKET_SUCCESS;
3863  }
3864  else
3865  {
3866  //The option length is not valid
3868  ret = SOCKET_ERROR;
3869  }
3870 #else
3871  //TCP is not supported
3873  ret = SOCKET_ERROR;
3874 #endif
3875 
3876  //Return status code
3877  return ret;
3878 }
3879 
3880 
3881 /**
3882  * @brief Get TCP_MAXSEG option
3883  * @param[in] socket Handle referencing the socket
3884  * @param[out] optval A pointer to the buffer in which the value for the
3885  * requested option is to be returned
3886  * @param[in,out] optlen The size, in bytes, of the buffer pointed to by the
3887  * optval parameter
3888  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
3889  **/
3890 
3892  socklen_t *optlen)
3893 {
3894  int_t ret;
3895 
3896 #if (TCP_SUPPORT == ENABLED)
3897  //Check the length of the option
3898  if(*optlen >= (socklen_t) sizeof(int_t))
3899  {
3900  //Get exclusive access
3902 
3903  //Return the maximum segment size for outgoing TCP packets
3904  if(socket->state == TCP_STATE_CLOSED ||
3905  socket->state == TCP_STATE_LISTEN)
3906  {
3907  *optval = socket->mss;
3908  }
3909  else
3910  {
3911  *optval = socket->smss;
3912  }
3913 
3914  //Release exclusive access
3916 
3917  //Successful processing
3918  ret = SOCKET_SUCCESS;
3919  }
3920  else
3921  {
3922  //The option length is not valid
3924  ret = SOCKET_ERROR;
3925  }
3926 #else
3927  //TCP is not supported
3929  ret = SOCKET_ERROR;
3930 #endif
3931 
3932  //Return status code
3933  return ret;
3934 }
3935 
3936 
3937 /**
3938  * @brief Get TCP_KEEPIDLE option
3939  * @param[in] socket Handle referencing the socket
3940  * @param[out] optval A pointer to the buffer in which the value for the
3941  * requested option is to be returned
3942  * @param[in,out] optlen The size, in bytes, of the buffer pointed to by the
3943  * optval parameter
3944  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
3945  **/
3946 
3948  socklen_t *optlen)
3949 {
3950  int_t ret;
3951 
3952 #if (TCP_SUPPORT == ENABLED && TCP_KEEP_ALIVE_SUPPORT == ENABLED)
3953  //Check the length of the option
3954  if(*optlen >= (socklen_t) sizeof(int_t))
3955  {
3956  //Convert the time interval to seconds
3957  *optval = socket->keepAliveIdle / 1000;
3958  //Successful processing
3959  ret = SOCKET_SUCCESS;
3960  }
3961  else
3962  {
3963  //The option length is not valid
3965  ret = SOCKET_ERROR;
3966  }
3967 #else
3968  //TCP keep-alive is not supported
3970  ret = SOCKET_ERROR;
3971 #endif
3972 
3973  //Return status code
3974  return ret;
3975 }
3976 
3977 
3978 /**
3979  * @brief Get TCP_KEEPINTVL option
3980  * @param[in] socket Handle referencing the socket
3981  * @param[out] optval A pointer to the buffer in which the value for the
3982  * requested option is to be returned
3983  * @param[in,out] optlen The size, in bytes, of the buffer pointed to by the
3984  * optval parameter
3985  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
3986  **/
3987 
3989  socklen_t *optlen)
3990 {
3991  int_t ret;
3992 
3993 #if (TCP_SUPPORT == ENABLED && TCP_KEEP_ALIVE_SUPPORT == ENABLED)
3994  //Check the length of the option
3995  if(*optlen >= (socklen_t) sizeof(int_t))
3996  {
3997  //Convert the time interval to seconds
3998  *optval = socket->keepAliveInterval / 1000;
3999  //Successful processing
4000  ret = SOCKET_SUCCESS;
4001  }
4002  else
4003  {
4004  //The option length is not valid
4006  ret = SOCKET_ERROR;
4007  }
4008 #else
4009  //TCP keep-alive is not supported
4011  ret = SOCKET_ERROR;
4012 #endif
4013 
4014 
4015  //Return status code
4016  return ret;
4017 }
4018 
4019 
4020 /**
4021  * @brief Get TCP_KEEPCNT option
4022  * @param[in] socket Handle referencing the socket
4023  * @param[out] optval A pointer to the buffer in which the value for the
4024  * requested option is to be returned
4025  * @param[in,out] optlen The size, in bytes, of the buffer pointed to by the
4026  * optval parameter
4027  * @return Error code (SOCKET_SUCCESS or SOCKET_ERROR)
4028  **/
4029 
4031  socklen_t *optlen)
4032 {
4033  int_t ret;
4034 
4035 #if (TCP_SUPPORT == ENABLED && TCP_KEEP_ALIVE_SUPPORT == ENABLED)
4036  //Check the length of the option
4037  if(*optlen >= (socklen_t) sizeof(int_t))
4038  {
4039  //Return parameter value
4040  *optval = socket->keepAliveMaxProbes;
4041  //Successful processing
4042  ret = SOCKET_SUCCESS;
4043  }
4044  else
4045  {
4046  //The option length is not valid
4048  ret = SOCKET_ERROR;
4049  }
4050 #else
4051  //TCP keep-alive is not supported
4053  ret = SOCKET_ERROR;
4054 #endif
4055 
4056 
4057  //Return status code
4058  return ret;
4059 }
4060 
4061 #endif
struct in_addr imr_sourceaddr
Definition: bsd_socket.h:414
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:303
int_t socketSetTcpKeepIdleOption(Socket *socket, const int_t *optval, socklen_t optlen)
Set TCP_KEEPIDLE option.
#define AF_INET6
Definition: bsd_socket.h:80
@ SOCKET_OPTION_IPV4_RECV_TOS
Definition: socket.h:197
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.
int_t socketSetSoNoCheckOption(Socket *socket, const int_t *optval, socklen_t optlen)
Set SO_NO_CHECK option.
#define ENOPROTOOPT
Definition: bsd_socket.h:264
Helper function for BSD socket API.
int_t socketSetMcastLeaveGroupOption(Socket *socket, const struct group_req *optval, socklen_t optlen)
Set MCAST_LEAVE_GROUP option.
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:90
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.
Source-specific multicast group information (for IPv4/IPv6)
Definition: bsd_socket.h:446
int_t socketSetMcastLeaveSourceGroupOption(Socket *socket, const struct group_source_req *optval, socklen_t optlen)
Set MCAST_LEAVE_SOURCE_GROUP option.
int_t socketGetIpv6MulticastHopsOption(Socket *socket, int_t *optval, socklen_t *optlen)
Get IPV6_MULTICAST_HOPS option.
struct in_addr imr_multiaddr
Definition: bsd_socket.h:413
#define SOCK_DGRAM
Definition: bsd_socket.h:91
#define SOCKET_ERROR
Definition: bsd_socket.h:238
#define TRUE
Definition: os_port.h:50
@ SOCKET_OPTION_REUSE_ADDR
Definition: socket.h:192
int_t socketSetIpv6MulticastHopsOption(Socket *socket, const int_t *optval, socklen_t optlen)
Set IPV6_MULTICAST_HOPS option.
struct in6_addr sin6_addr
Definition: bsd_socket.h:391
#define AF_INET
Definition: bsd_socket.h:79
error_t socketJoinMulticastGroup(Socket *socket, const IpAddr *groupAddr)
Join the specified host group.
Definition: socket.c:426
Ipv6Addr
Definition: ipv6.h:260
@ SOCKET_TYPE_DGRAM
Definition: socket.h:93
int_t socketGetSoRcvTimeoOption(Socket *socket, struct timeval *optval, socklen_t *optlen)
Get SO_RCVTIMEO option.
@ SOCKET_OPTION_IPV6_ONLY
Definition: socket.h:200
int_t socketGetIpTosOption(Socket *socket, int_t *optval, socklen_t *optlen)
Get IP_TOS option.
#define EINVAL
Definition: bsd_socket.h:259
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:201
IPv4 address information.
Definition: bsd_socket.h:364
Any-source multicast group information (for IPv4 only)
Definition: bsd_socket.h:401
@ SOCKET_TYPE_STREAM
Definition: socket.h:92
uint32_t Ipv4Addr
IPv4 network address.
Definition: ipv4.h:297
int_t socketGetIpRecvTtlOption(Socket *socket, int_t *optval, socklen_t *optlen)
Get IP_RECVTTL option.
sa_family_t ss_family
Definition: bsd_socket.h:344
int_t socketGetTcpKeepIdleOption(Socket *socket, int_t *optval, socklen_t *optlen)
Get TCP_KEEPIDLE option.
@ SOCKET_OPTION_IPV6_RECV_TRAFFIC_CLASS
Definition: socket.h:203
error_t socketSetTxBufferSize(Socket *socket, size_t size)
Specify the size of the TCP send buffer.
Definition: socket.c:1201
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.
struct sockaddr_storage gsr_source
Definition: bsd_socket.h:449
int_t socketSetIpDropSourceMembershipOption(Socket *socket, const struct ip_mreq_source *optval, socklen_t optlen)
Set IP_DROP_SOURCE_MEMBERSHIP option.
int_t socketGetTcpKeepCntOption(Socket *socket, int_t *optval, socklen_t *optlen)
Get TCP_KEEPCNT option.
@ SOCKET_OPTION_IPV4_RECV_TTL
Definition: socket.h:198
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:573
error_t socketSetRxBufferSize(Socket *socket, size_t size)
Specify the size of the TCP receive buffer.
Definition: socket.c:1237
int_t socketSetMcastJoinSourceGroupOption(Socket *socket, const struct group_source_req *optval, socklen_t optlen)
Set MCAST_JOIN_SOURCE_GROUP option.
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:1073
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 socketSetMcastUnblockSourceOption(Socket *socket, const struct group_source_req *optval, socklen_t optlen)
Set MCAST_UNBLOCK_SOURCE option.
IPv6 address information.
Definition: bsd_socket.h:387
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:354
@ SOCKET_OPTION_IPV6_RECV_HOP_LIMIT
Definition: socket.h:204
error_t socketAddMulticastSource(Socket *socket, const IpAddr *groupAddr, const IpAddr *srcAddr)
Accept specific source for specific group (delta-based API)
Definition: socket.c:753
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:425
#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:195
int_t socketSetIpTtlOption(Socket *socket, const int_t *optval, socklen_t optlen)
Set IP_TTL option.
#define SOCKET_SUCCESS
Definition: bsd_socket.h:237
@ SOCKET_OPTION_BROADCAST
Definition: socket.h:193
int_t socketSetIpAddSourceMembershipOption(Socket *socket, const struct ip_mreq_source *optval, socklen_t optlen)
Set IP_ADD_SOURCE_MEMBERSHIP option.
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.
int_t socketGetSoNoCheckOption(Socket *socket, int_t *optval, socklen_t *optlen)
Get SO_NO_CHECK option.
error_t socketSetMaxSegmentSize(Socket *socket, size_t mss)
Specify the maximum segment size for outgoing TCP packets.
Definition: socket.c:1164
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:402
int32_t tv_usec
Definition: bsd_socket.h:574
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:355
@ TCP_STATE_LISTEN
Definition: tcp.h:269
struct sockaddr_storage gr_group
Definition: bsd_socket.h:437
#define EFAULT
Definition: bsd_socket.h:258
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:123
@ SOCKET_OPTION_IPV4_MULTICAST_LOOP
Definition: socket.h:194
error_t socketBlockMulticastSource(Socket *socket, const IpAddr *groupAddr, const IpAddr *srcAddr)
Block specific source for specific group (delta-based API)
Definition: socket.c:917
Timeout structure.
Definition: bsd_socket.h:572
void osAcquireMutex(OsMutex *mutex)
Acquire ownership of the specified mutex object.
int_t socketSetIpUnblockSourceOption(Socket *socket, const struct ip_mreq_source *optval, socklen_t optlen)
Set IP_UNBLOCK_SOURCE option.
Ipv4Addr groupAddr
Definition: igmp_common.h:214
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.
struct in_addr sin_addr
Definition: bsd_socket.h:367
#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:202
MacAddr srcAddr
Definition: ethernet.h:220
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:199
int_t socketGetSoKeepAliveOption(Socket *socket, int_t *optval, socklen_t *optlen)
Get SO_KEEPALIVE option.
struct sockaddr_storage gsr_group
Definition: bsd_socket.h:448
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.
error_t socketUnblockMulticastSource(Socket *socket, const IpAddr *groupAddr, const IpAddr *srcAddr)
Unblock specific source for specific group (delta-based API)
Definition: socket.c:1004
int_t socketSetIpMulticastLoopOption(Socket *socket, const int_t *optval, socklen_t optlen)
Set IP_MULTICAST_LOOP option.
Any-source multicast group information (for IPv6 only)
Definition: bsd_socket.h:424
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 socketSetMcastBlockSourceOption(Socket *socket, const struct group_source_req *optval, socklen_t optlen)
Set MCAST_BLOCK_SOURCE option.
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.
Source-specific multicast group information (for IPv4 only)
Definition: bsd_socket.h:412
int_t socketGetTcpNoDelayOption(Socket *socket, int_t *optval, socklen_t *optlen)
Get TCP_NODELAY option.
error_t socketDropMulticastSource(Socket *socket, const IpAddr *groupAddr, const IpAddr *srcAddr)
Drop specific source for specific group (delta-based API)
Definition: socket.c:840
error_t socketLeaveMulticastGroup(Socket *socket, const IpAddr *groupAddr)
Leave the specified host group.
Definition: socket.c:494
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 socketSetMcastJoinGroupOption(Socket *socket, const struct group_req *optval, socklen_t optlen)
Set MCAST_JOIN_GROUP option.
int_t socketSetIpMulticastIfOption(Socket *socket, const struct in_addr *optval, socklen_t optlen)
Set IP_MULTICAST_IF option.
int_t socketSetIpBlockSourceOption(Socket *socket, const struct ip_mreq_source *optval, socklen_t optlen)
Set IP_BLOCK_SOURCE option.
@ SOCKET_OPTION_UDP_NO_CHECKSUM
Definition: socket.h:206
Debugging facilities.
@ SOCKET_OPTION_TCP_NO_DELAY
Definition: socket.h:205
uint8_t s6_addr[16]
Definition: bsd_socket.h:378
Any-source multicast group information (for IPv4/IPv6)
Definition: bsd_socket.h:435
#define INFINITE_DELAY
Definition: os_port.h:75
@ SOCKET_OPTION_IPV4_PKT_INFO
Definition: socket.h:196