]> git.proxmox.com Git - mirror_edk2.git/blob - StdLib/BsdSocketLib/getsockopt.c
IntelFsp2WrapperPkg: Update gFspWrapperTokenSpaceGuid to gIntelFsp2WrapperTokenSpaceGuid.
[mirror_edk2.git] / StdLib / BsdSocketLib / getsockopt.c
1 /** @file
2 Implement the getsockopt 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 /** Get the socket options
17
18 The
19 <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockopt.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 [out] option_value Buffer to receive the option value
26 @param [in,out] option_len Length of the buffer in bytes,
27 upon return length of the option value in bytes
28
29 @return This routine returns zero (0) if successful or -1 when an error occurs.
30 In the case of an error, ::errno contains more details.
31 **/
32 int
33 getsockopt (
34 IN int s,
35 IN int level,
36 IN int option_name,
37 OUT void * __restrict option_value,
38 IN OUT socklen_t * __restrict option_len
39 )
40 {
41 int OptionStatus;
42 EFI_SOCKET_PROTOCOL * pSocketProtocol;
43
44 // Locate the context for this socket
45 pSocketProtocol = BslFdToSocketProtocol ( s, NULL, &errno );
46 if ( NULL != pSocketProtocol ) {
47 // Get the socket option
48 (void) pSocketProtocol->pfnOptionGet ( pSocketProtocol,
49 level,
50 option_name,
51 option_value,
52 option_len,
53 &errno );
54 }
55 // Return the operation stauts
56 OptionStatus = ( 0 == errno ) ? 0 : -1;
57 return OptionStatus;
58 }