My Project
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules
soc_gethostbyname.c
Go to the documentation of this file.
1 #include "soc_common.h"
2 #include <netdb.h>
3 
4 #define MAX_HOSTENT_RESULTS 16
5 static struct hostent SOC_hostent;
6 static char *SOC_hostent_results[MAX_HOSTENT_RESULTS+1];
7 static char *SOC_hostent_alias = NULL;
8 
9 int h_errno = 0;
10 
11 struct hostent* gethostbyname(const char *name)
12 {
13  int ret=0;
14  u32 *cmdbuf = getThreadCommandBuffer();
15  u32 saved_threadstorage[2];
16  static u8 outbuf[0x1A88];
17 
18  cmdbuf[0] = 0x000D0082;
19  cmdbuf[1] = strlen(name)+1;
20  cmdbuf[2] = sizeof(outbuf);
21  cmdbuf[3] = ((strlen(name)+1) << 14) | 0xC02;
22  cmdbuf[4] = (u32)name;
23 
24  saved_threadstorage[0] = cmdbuf[0x100>>2];
25  saved_threadstorage[1] = cmdbuf[0x104>>2];
26 
27  cmdbuf[0x100>>2] = (sizeof(outbuf) << 14) | 2;
28  cmdbuf[0x104>>2] = (u32)outbuf;
29 
30  if(( ret = svcSendSyncRequest(SOCU_handle))!=0)return NULL;
31 
32  cmdbuf[0x100>>2] = saved_threadstorage[0];
33  cmdbuf[0x104>>2] = saved_threadstorage[1];
34 
35  ret = (int)cmdbuf[1];
36  if(ret==0)ret = _net_convert_error(cmdbuf[2]);
37  if(ret<0)SOCU_errno = ret;
38  /* TODO: set h_errno based on SOCU_errno */
39 
40  if(ret<0)return NULL;
41 
42  u32 num_results, i;
43  memcpy(&num_results, (char*)outbuf+4, sizeof(num_results));
44  if(num_results > MAX_HOSTENT_RESULTS)
45  num_results = MAX_HOSTENT_RESULTS;
46 
47  SOC_hostent.h_name = (char*)outbuf + 8;
48  SOC_hostent.h_aliases = &SOC_hostent_alias;
49  SOC_hostent.h_addrtype = AF_INET;
50  SOC_hostent.h_length = 4;
51  SOC_hostent.h_addr_list = SOC_hostent_results;
52 
53  SOC_hostent_alias = NULL;
54 
55  for(i = 0; i < num_results; ++i)
56  SOC_hostent_results[i] = (char*)outbuf + 0x1908 + i*0x10;
57  SOC_hostent_results[num_results] = NULL;
58 
59  return &SOC_hostent;
60 }
Definition: netdb.h:11
u32 * getThreadCommandBuffer(void)
uint8_t u8
Definition: types.h:21
int SOCU_errno
Definition: soc_common.c:5
uint32_t u32
Definition: types.h:23
#define AF_INET
Definition: socket.h:13
int h_errno
struct hostent * gethostbyname(const char *name)
char ** h_addr_list
Definition: netdb.h:16
s32 _net_convert_error(s32 sock_retval)
Definition: soc_common.c:92
char * h_name
Definition: netdb.h:12
int h_length
Definition: netdb.h:15
s32 svcSendSyncRequest(Handle session)
char ** h_aliases
Definition: netdb.h:13
Handle SOCU_handle
Definition: soc_common.c:4
int h_addrtype
Definition: netdb.h:14
#define MAX_HOSTENT_RESULTS