00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef SYS_SOCKET_H
00029 #define SYS_SOCKET_H
00030
00031 #include <sys/time.h>
00032
00033
00034
00035
00036 #define SOL_SOCKET 0xfff
00037 # define SOL_TCP 6
00038
00039 #define PF_UNSPEC 0
00040 #define PF_INET 2
00041 #define PF_INET6 10
00042
00043 #define AF_UNSPEC PF_UNSPEC
00044 #define AF_INET PF_INET
00045 #define AF_INET6 PF_INET6
00046
00047 #define SOCK_STREAM 1
00048 #define SOCK_DGRAM 2
00049
00050
00051 #define FIONBIO 1
00052 #define FIONREAD 2
00053
00054 #define SOCKET_ERROR -1
00055
00056
00057
00058 #define MSG_WAITALL 0x40000000
00059 #define MSG_TRUNC 0x20000000
00060 #define MSG_PEEK 0x10000000
00061 #define MSG_OOB 0x08000000
00062 #define MSG_EOR 0x04000000
00063 #define MSG_DONTROUTE 0x02000000
00064 #define MSG_CTRUNC 0x01000000
00065
00066
00067 #define SHUT_RD 1
00068 #define SHUT_WR 2
00069 #define SHUT_RDWR 3
00070
00071
00072
00073
00074 #define SO_DEBUG 0x0001
00075 #define SO_ACCEPTCONN 0x0002
00076 #define SO_REUSEADDR 0x0004
00077 #define SO_KEEPALIVE 0x0008
00078 #define SO_DONTROUTE 0x0010
00079 #define SO_BROADCAST 0x0020
00080 #define SO_USELOOPBACK 0x0040
00081 #define SO_LINGER 0x0080
00082 #define SO_OOBINLINE 0x0100
00083 #define SO_REUSEPORT 0x0200
00084
00085 #define SO_DONTLINGER (int)(~SO_LINGER)
00086
00087
00088
00089
00090 #define SO_SNDBUF 0x1001
00091 #define SO_RCVBUF 0x1002
00092 #define SO_SNDLOWAT 0x1003
00093 #define SO_RCVLOWAT 0x1004
00094 #define SO_SNDTIMEO 0x1005
00095 #define SO_RCVTIMEO 0x1006
00096 #define SO_ERROR 0x1007
00097 #define SO_TYPE 0x1008
00098
00099 struct sockaddr {
00100 unsigned short sa_family;
00101 char sa_data[14];
00102 };
00103
00104 #ifndef ntohs
00105 #define ntohs(num) htons(num)
00106 #define ntohl(num) htonl(num)
00107 #endif
00108
00109 #ifdef __cplusplus
00110 extern "C" {
00111 #endif
00112
00113 extern int socket(int domain, int type, int protocol);
00114 extern int bind(int socket, const struct sockaddr * addr, int addr_len);
00115 extern int connect(int socket, const struct sockaddr * addr, int addr_len);
00116 extern int send(int socket, const void * data, int sendlength, int flags);
00117 extern int recv(int socket, void * data, int recvlength, int flags);
00118 extern int sendto(int socket, const void * data, int sendlength, int flags, const struct sockaddr * addr, int addr_len);
00119 extern int recvfrom(int socket, void * data, int recvlength, int flags, struct sockaddr * addr, int * addr_len);
00120 extern int listen(int socket, int max_connections);
00121 extern int accept(int socket, struct sockaddr * addr, int * addr_len);
00122 extern int shutdown(int socket, int shutdown_type);
00123 extern int closesocket(int socket);
00124
00125 extern int ioctl(int socket, long cmd, void * arg);
00126
00127 extern int setsockopt(int socket, int level, int option_name, const void * data, int data_len);
00128 extern int getsockopt(int socket, int level, int option_name, void * data, int * data_len);
00129
00130 extern int getpeername(int socket, struct sockaddr *addr, int * addr_len);
00131 extern int getsockname(int socket, struct sockaddr *addr, int * addr_len);
00132
00133 extern int gethostname(char *name, size_t len);
00134 extern int sethostname(const char *name, size_t len);
00135
00136 unsigned short htons(unsigned short num);
00137 unsigned long htonl(unsigned long num);
00138
00139
00140 extern int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds, struct timeval *timeout);
00141
00142
00143 #ifdef __cplusplus
00144 };
00145 #endif
00146
00147
00148 #endif