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