Home | History | Annotate | Download | only in BsdSocketLib
      1 /** @file
      2   Implement the setsockopt API.
      3 
      4   Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.<BR>
      5   This program and the accompanying materials are licensed and made available under
      6   the terms and conditions of the BSD License that accompanies this distribution.
      7   The full text of the license may be found at
      8   http://opensource.org/licenses/bsd-license.php.
      9 
     10   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
     11   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
     12 **/
     13 #include <SocketInternals.h>
     14 
     15 
     16 /** Set the socket options
     17 
     18   The
     19   <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/setsockopt.html">POSIX</a>
     20   documentation is available online.
     21 
     22   @param [in] s               Socket file descriptor returned from ::socket.
     23   @param [in] level           Option protocol level
     24   @param [in] option_name     Name of the option
     25   @param [in] option_value    Buffer containing the option value
     26   @param [in] option_len      Length of the value in bytes
     27 
     28   @return   This routine returns zero (0) upon success and -1 when an error occurs.
     29             In the case of an error, ::errno contains more details.
     30 **/
     31 int
     32 setsockopt (
     33   IN int s,
     34   IN int level,
     35   IN int option_name,
     36   IN CONST void * option_value,
     37   IN socklen_t option_len
     38   )
     39 {
     40   int OptionStatus;
     41   EFI_SOCKET_PROTOCOL * pSocketProtocol;
     42 
     43   //  Locate the context for this socket
     44   pSocketProtocol = BslFdToSocketProtocol ( s, NULL, &errno );
     45   if ( NULL != pSocketProtocol ) {
     46     //  Set the socket option
     47     (void) pSocketProtocol->pfnOptionSet (pSocketProtocol,
     48                                           level,
     49                                           option_name,
     50                                           option_value,
     51                                           option_len,
     52                                           &errno );
     53   }
     54   //  Return the operation stauts
     55   OptionStatus = ( 0 == errno ) ? 0 : -1;
     56   return OptionStatus;
     57 }
     58