]> git.proxmox.com Git - mirror_edk2.git/blob - StdLib/BsdSocketLib/getsockopt.c
Fix a bug about the iSCSI DHCP dependency issue.
[mirror_edk2.git] / StdLib / BsdSocketLib / getsockopt.c
1 /** @file
2 Implement the getsockopt API.
3
4 Copyright (c) 2011, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. 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 **/
14
15 #include <SocketInternals.h>
16
17
18 /**
19 Get the socket options
20
21 The
22 <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockopt.html#">POSIX</a>
23 documentation is available online.
24
25 @param [in] s Socket file descriptor returned from ::socket.
26 @param [in] level Option protocol level
27 @param [in] option_name Name of the option
28 @param [out] option_value Buffer to receive the option value
29 @param [in,out] option_len Length of the buffer in bytes,
30 upon return length of the option value in bytes
31
32 @return This routine returns zero (0) if successful or -1 when an error occurs.
33 In the case of an error, ::errno contains more details.
34
35 **/
36 int
37 getsockopt (
38 IN int s,
39 IN int level,
40 IN int option_name,
41 OUT void * __restrict option_value,
42 IN OUT socklen_t * __restrict option_len
43 )
44 {
45 int OptionStatus;
46 EFI_SOCKET_PROTOCOL * pSocketProtocol;
47 EFI_STATUS Status;
48
49 //
50 // Locate the context for this socket
51 //
52 pSocketProtocol = BslFdToSocketProtocol ( s, NULL, &errno );
53 if ( NULL != pSocketProtocol ) {
54 //
55 // Get the socket option
56 //
57 Status = pSocketProtocol->pfnOptionGet ( pSocketProtocol,
58 level,
59 option_name,
60 option_value,
61 option_len,
62 &errno );
63 }
64
65 //
66 // Return the operation stauts
67 //
68 OptionStatus = ( 0 == errno ) ? 0 : -1;
69 return OptionStatus;
70 }