My Project
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules
soc_getsockopt.c
Go to the documentation of this file.
1 #include "soc_common.h"
2 #include <sys/socket.h>
3 
4 int getsockopt(int sockfd, int level, int optname, void *optval, socklen_t *optlen)
5 {
6  int ret=0;
7  u32 *cmdbuf = getThreadCommandBuffer();
8  u32 saved_threadstorage[2];
9 
10  cmdbuf[0] = 0x00110102;
11  cmdbuf[1] = (u32)sockfd;
12  cmdbuf[2] = (u32)level;
13  cmdbuf[3] = (u32)optname;
14  cmdbuf[4] = (u32)*optlen;
15  cmdbuf[5] = 0x20;
16 
17  saved_threadstorage[0] = cmdbuf[0x100>>2];
18  saved_threadstorage[1] = cmdbuf[0x104>>2];
19 
20  cmdbuf[0x100>>2] = ((*optlen)<<14) | 2;
21  cmdbuf[0x104>>2] = (u32)optval;
22 
23  if((ret = svcSendSyncRequest(SOCU_handle))!=0)return ret;
24 
25  cmdbuf[0x100>>2] = saved_threadstorage[0];
26  cmdbuf[0x104>>2] = saved_threadstorage[1];
27 
28  ret = (int)cmdbuf[1];
29  if(ret==0)ret = _net_convert_error(cmdbuf[2]);
30  if(ret<0)SOCU_errno = ret;
31 
32  if(ret==0)*optlen = cmdbuf[3];
33 
34  if(ret<0)return -1;
35  return ret;
36 }
int getsockopt(int sockfd, int level, int optname, void *optval, socklen_t *optlen)
Definition: soc_getsockopt.c:4
u32 * getThreadCommandBuffer(void)
uint32_t socklen_t
Definition: socket.h:50
int SOCU_errno
Definition: soc_common.c:5
uint32_t u32
Definition: types.h:23
s32 _net_convert_error(s32 sock_retval)
Definition: soc_common.c:92
s32 svcSendSyncRequest(Handle session)
Handle SOCU_handle
Definition: soc_common.c:4