Subversion Repositories Kolibri OS

Rev

Rev 4282 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. #ifndef __MENUET_NET_H
  2. #define __MENUET_NET_H
  3.  
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7.  
  8. #include<menuet/os.h>
  9.  
  10.  
  11. // System functions
  12. #define _SOCKETF 75
  13.  
  14. // Socket subfunctions
  15. #define _OPENSF    0
  16. #define _CLOSESF   1
  17. #define _BINDSF    2
  18. #define _LISTENSF  3
  19. #define _CONNECTSF 4
  20. #define _ACCEPTSF  5
  21. #define _SENDSF    6
  22. #define _RECEIVESF 7
  23.  
  24. // Socket types
  25. #define SOCK_STREAM 1
  26. #define SOCK_DGRAM  2
  27. #define SOCK_RAW    3
  28.  
  29. // Socket options
  30. #define SO_NONBLOCK 1 << 31
  31.  
  32. // IP protocols
  33. #define IPPROTO_IP   0
  34. #define IPPROTO_ICMP 1
  35. #define IPPROTO_TCP  6
  36. #define IPPROTO_UDP  17
  37.  
  38. // Address families
  39. #define AF_UNSPEC 0
  40. #define AF_LOCAL  1
  41. #define AF_INET   2  // IPv4
  42. #define AF_INET6  28 // IPv6 (not supported yet)
  43.  
  44. #define PF_UNSPEC AF_UNSPEC
  45. #define PF_LOCAL  AF_LOCAL
  46. #define PF_INET  AF_INET
  47. #define PF_INET6  AF_INET6
  48.  
  49. // Flags for addrinfo
  50. #define AI_PASSIVE     1
  51. #define AI_CANONNAME   2
  52. #define AI_NUMERICHOST 4
  53. #define AI_NUMERICSERV 8
  54. #define AI_ADDRCONFIG  0x400  
  55.  
  56. // Internal definition
  57. #define AI_SUPPORTED 0x40F
  58.  
  59. // For system function 76
  60. #define API_ETH   0 << 16
  61. #define API_IPv4  1 << 16
  62. #define API_ICMP  2 << 16
  63. #define API_UDP   3 << 16
  64. #define API_TCP   4 << 16
  65. #define API_ARP   5 << 16
  66. #define API_PPPOE 6 << 16
  67.  
  68. // Socket flags for user calls
  69. #define MSG_PEEK     0x02
  70. #define MSG_DONTWAIT 0x40
  71.  
  72.  
  73. struct in_addr {
  74.     unsigned int s_addr;
  75. };
  76.  
  77. struct sockaddr {
  78.     unsigned short    sa_family;    // address family, AF_xxx
  79.     char              sa_data[14];  // 14 bytes of protocol address
  80. };
  81.  
  82. struct sockaddr_in { // IPv4 only, we need sockaddr_in6 for IPv6
  83.     short int          sin_family;  // Address family, AF_INET
  84.     unsigned short int sin_port;    // Port number
  85.     struct in_addr     sin_addr;    // Internet address
  86.     unsigned char      sin_zero[8]; // Same size as struct sockaddr
  87. };
  88.  
  89. struct addrinfo {
  90.     int              ai_flags;     // AI_PASSIVE, AI_CANONNAME, etc.
  91.     int              ai_family;    // AF_INET, AF_INET6, AF_UNSPEC
  92.     int              ai_socktype;  // SOCK_STREAM, SOCK_DGRAM
  93.     int              ai_protocol;  // use 0 for "any"
  94.     int              ai_addrlen;   // size of ai_addr in bytes
  95.     struct sockaddr *ai_addr;      // struct sockaddr_in or _in6
  96.     char            *ai_canonname; // full canonical hostname
  97.     struct addrinfo *ai_next;      // linked list, next node
  98. };
  99.  
  100. #define EAI_ADDRFAMILY 1
  101. #define EAI_AGAIN      2
  102. #define EAI_BADFLAGS   3
  103. #define EAI_FAIL       4
  104. #define EAI_FAMILY     5
  105. #define EAI_MEMORY     6
  106. #define EAI_NONAME     8
  107. #define EAI_SERVICE    9
  108. #define EAI_SOCKTYPE   10
  109. #define EAI_BADHINTS   12
  110. #define EAI_PROTOCOL   13
  111. #define EAI_OVERFLOW   14  
  112.  
  113. // Socket error codes
  114. // Error Codes
  115. #define ENOBUFS       1
  116. #define EINPROGRESS   2
  117. #define EOPNOTSUPP    4
  118. #define EWOULDBLOCK   6
  119. #define ENOTCONN      9
  120. #define EALREADY      10
  121. #define EINVAL        11
  122. #define EMSGSIZE      12
  123. #define ENOMEM        18
  124. #define EADDRINUSE    20
  125. #define ECONNREFUSED  61
  126. #define ECONNRESET    52
  127. #define EISCONN       56
  128. #define ETIMEDOUT     60
  129. #define ECONNABORTED  53
  130.  
  131.  
  132. int socket(int domain, int type, int protocol);
  133. int closesocket(int s);
  134. int bind(int sockfd, struct sockaddr *my_addr, int addrlen);
  135. int listen(int s, int backlog);
  136. int connect(int sockfd, const struct sockaddr *serv_addr, int addrlen);
  137. int accept(int s, struct sockaddr *addr, int *addrlen);
  138. int send(int s, const void *buf, int len, int flags);
  139. int recv(int sockfd, void *buf, int len, int flags);
  140.  
  141. // extern from src/libc/menuetos/netowrk.c
  142. #define __stdcall __attribute__((stdcall))
  143. extern void NETWORK_INIT();
  144. extern void (* __stdcall freeaddrinfo)(struct addrinfo* ai);
  145. extern int (* __stdcall getaddrinfo)( const char* hostname, const char* servname, const struct addrinfo* hints, struct addrinfo **res);
  146. extern char * (* __stdcall inet_ntoa)(struct in_addr in);
  147. extern unsigned long (* __stdcall inet_addr)( const char* hostname);
  148.  
  149.  
  150. // Old stuff
  151. //---------------------------------------------  
  152.  
  153. #define __NET_stack_rd_cfg_word 0
  154. #define __NET_stack_get_ip      1
  155. #define __NET_stack_wr_cfg_word 2
  156. #define __NET_stack_put_ip      3
  157.  
  158. #define __NET_sock_open_UDP     0
  159. #define __NET_sock_open_TCP     5
  160. #define __NET_sock_close_UDP    1
  161. #define __NET_sock_close_TCP    8
  162. #define __NET_sock_poll         2
  163. #define __NET_sock_read         3
  164. #define __NET_sock_write_UDP    4
  165. #define __NET_sock_get_status   6
  166. #define __NET_sock_write_TCP    7
  167. #define __NET_sock_check_port   9
  168.  
  169. #define __NET_socket            53
  170. #define __NET_stack             52
  171.  
  172. int __menuet__get_stack_config_word(void);
  173. __u32 __menuet__get_my_IP(void);
  174. void __menuet__set_stack_config_word(int cfg);
  175. void __menuet__set_my_IP(__u32 my_IP);
  176.  
  177. __u32 __menuet__open_UDP_socket(__u32 local_port,__u32 remote_port,__u32 remote_ip);
  178. __u32 __menuet__open_TCP_socket(__u32 local_port,__u32 remote_port,__u32 remote_ip,int mode);
  179. int __menuet__close_UDP_socket(int socket);
  180. int __menuet__close_TCP_socket(int socket);
  181. int __menuet__poll_socket(int sock);
  182. int __menuet__read_socket(int sock,__u8 * return_data);
  183. int __menuet__get_TCP_socket_status(int sock);
  184. int __menuet__write_UDP_socket(int sock,int count,void * buffer);
  185. int __menuet__write_TCP_socket(int sock,int count,void * buffer);
  186. int __menuet__check_net_port_availability(int port);
  187.  
  188. /* Values returned by __menuet__check_net_port_availability */
  189. #define PORT_AVAILABLE          (1)
  190. #define PORT_UNAVAILABLE        (0)
  191.  
  192. #define NET_OP_OK               ((int)(0))
  193. #define NET_OP_ERR              ((int)(-1))
  194.  
  195. /* These are socket modes */
  196. #define SOCKET_PASSIVE          0
  197. #define SOCKET_ACTIVE           1
  198.  
  199. /* These belong to socket status */
  200. #define TCB_LISTEN              1
  201. #define TCB_SYN_SENT            2
  202. #define TCB_SYN_RECEIVED        3
  203. #define TCB_ESTABLISHED         4
  204. #define TCB_FIN_WAIT_1          5
  205. #define TCB_FIN_WAIT_2          6
  206. #define TCB_CLOSE_WAIT          7
  207. #define TCB_CLOSING             8
  208. #define TCB_LAST_ACK            9
  209. #define TCB_TIME_AWAIT          10
  210. #define TCB_CLOSED              11
  211.  
  212. #ifdef __cplusplus
  213. }
  214. #endif
  215.  
  216. #endif
  217.