1 /*------------------------------------------------------------------------------
2  *
3  * File:        so_init.h
4  * Description: socket api public header file
5  *
6  * Copyright (C) Nintendo.  All rights reserved.
7  * These coded instructions, statements, and computer programs contain
8  * proprietary information of Nintendo of America Inc. and/or Nintendo
9  * Company Ltd., and are protected by Federal copyright law.  They may
10  * not be disclosed to third parties or copied or duplicated in any form,
11  * in whole or in part, without the prior written consent of Nintendo.
12  *
13  *------------------------------------------------------------------------------
14  */
15 #ifndef __SOCKET_INIT_H__
16 #define __SOCKET_INIT_H__
17 
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21 
22 #include <types.h>
23 #include <cafe/net/net_types.h>
24 
25 #define     SOCKET_ERROR	  (-1)
26 
27 /*
28  * "how" parameter to shutdown() call
29  */
30 #define SHUT_RD         0 /* No more read, but can write */
31 #define SHUT_WR         1 /* No more write but can read */
32 #define SHUT_RDWR       2 /* No more read or write */
33 
34 /*
35  * Generic structure used by kernel to store most
36  * addresses.
37  */
38 struct sockaddr
39 {
40    unsigned short    sa_family;     /* address family */
41 #ifdef IP_V6   /* V6 only or dual stacks */
42    char     sa_data[32];      /* big enough for extracted sockaddr_in6 */
43 #else          /* Ancient IPv4 only version */
44    char     sa_data[14];      /* up to 14 bytes of direct address */
45 #endif
46 };
47 
48 #define INADDR_ANY 0L
49 
50 /*
51  * IPv4 Internet Address
52  */
53 struct in_addr
54 {
55     unsigned long s_addr;
56 };
57 
58 /*
59  * IPv4 socket address
60  */
61 struct sockaddr_in
62 {
63     unsigned short     sin_family;
64     unsigned short     sin_port;
65     struct   in_addr   sin_addr;
66     char               sin_zero[8];
67 };
68 
69 typedef int           socklen_t;
70 
71 #ifndef NPTYPES_H
72 typedef unsigned long ip_addr;
73 #endif
74 
75 
76 /*
77  * Socket API
78  */
79 #define SOInit          socket_lib_init
80 #define SOFinish        socket_lib_finish
81 #define SOLastError     socketlasterr
82 #define SOInetNtoA      inet_ntoa
83 
84 #define SOResolverRegisterAllocator  set_resolver_allocator
85 
86 
87 /*
88  * Socket API (BSD-style)
89  */
90 extern int socket_lib_init(void);
91 extern int socket_lib_finish(void);
92 extern char *inet_ntoa(struct in_addr in);
93 extern int socketlasterr(void);
94 
95 int set_resolver_allocator(void * (*new_alloc) (u32), void (*new_free) (void *));
96 
97 #ifdef __cplusplus
98 }
99 #endif
100 
101 #endif /* __SOCKET_PUB_H__ */
102