?login_element?

Subversion Repositories NedoOS

Rev

Blame | Last modification | View Log | Download

  1. #ifndef SOCKET_H
  2. #define SOCKET_H
  3.  
  4. typedef signed char SOCKET;
  5. struct in_addr {
  6.         union {
  7.                 struct {unsigned char s_b1; unsigned char s_b2;
  8.                         unsigned char s_b3; unsigned char s_b4;} S_un_b;
  9.                 struct {unsigned short s_w1; unsigned short s_w2;} S_un_w;
  10.                 unsigned long S_addr;
  11.         } S_un;
  12. };
  13.  
  14. struct sockaddr_in {
  15.         unsigned char   sin_family;
  16.         unsigned short sin_port;
  17.         struct  in_addr sin_addr;
  18.         char    sin_zero[8];
  19. };
  20.  
  21.  
  22. SOCKET  OS_NETSOCKET(unsigned int);
  23. #define socket(domain, type, protocol) OS_NETSOCKET((domain<<8)+type)
  24.  
  25. int OS_NETRECV(unsigned char * buffer, SOCKET socket, unsigned int buf_size);
  26. #define recv(socket, buffer, buf_size, flags) OS_NETRECV(buffer, socket, buf_size)
  27.  
  28. int OS_NETSEND(unsigned char * buffer, SOCKET socket, unsigned int length);
  29. #define send(socket, buffer, length, flags) OS_NETSEND(buffer, socket, length)
  30.  
  31. int OS_NETRECVFROM(const struct sockaddr_in * addr,
  32.         SOCKET socket, unsigned int buf_size, unsigned char * buffer);
  33. #define recvfrom(socket, buffer, buf_size, flags, sain, sain_cnt) \
  34. OS_NETRECVFROM(sain, socket, buf_size, buffer)
  35.  
  36. int OS_NETSENDTO(const struct sockaddr_in * addr,
  37.         SOCKET socket, unsigned int buf_size, unsigned char * buffer);
  38. #define sendto(socket, buffer, buf_size, flags, sain, sain_cnt) \
  39. OS_NETSENDTO(sain, socket, buf_size, buffer)
  40.  
  41. signed char  OS_NETCLOSE(unsigned char,SOCKET);
  42. #define closesocket(socket,how) OS_NETCLOSE(how,socket)
  43.  
  44. signed char OS_NETCONNECT(const struct sockaddr_in * addr, SOCKET socket);
  45. #define connect(socket, addr, address_len) OS_NETCONNECT(addr,socket)
  46.  
  47. signed char OS_LISTEN(int, SOCKET socket);
  48. #define listen(socket, backlog) OS_LISTEN(backlog,socket)
  49.  
  50. signed char OS_BIND(const struct sockaddr_in * addr, SOCKET socket);
  51. #define bind(socket, addr, address_len) OS_BIND(addr,socket)
  52.  
  53. SOCKET OS_ACCEPT(const struct sockaddr_in * addr, SOCKET socket);
  54. #define accept(socket, addr, address_len) OS_ACCEPT(addr,socket)
  55.  
  56. void os_setdns(void * addr);
  57.  
  58. void os_getdns(void * addr);
  59.  
  60. unsigned short htons(unsigned short hostshort);
  61.  
  62. struct in_addr * dns_resolver(char *);
  63.  
  64. #define IPPROTO_TCP 6
  65. #define IPPROTO_UDP 17
  66.  
  67. #define AF_UNSPEC 0
  68. #define AF_INET 2
  69. #define AF_INET6 23
  70.  
  71. #define SOCK_STREAM 0x01        //tcp/ip
  72. #define SOCK_DGRAM      0x03    //udp/ip
  73.  
  74. #define ERR_INTR                 4
  75. #define ERR_NFILE                23
  76. #define ERR_ALREADY      37
  77. #define ERR_NOTSOCK      38
  78. #define ERR_EAGAIN               35                     /* Try again */
  79. #define ERR_EWOULDBLOCK  ERR_EAGAIN             /* Operation would block */
  80. #define ERR_EMSGSIZE     40             /* Message too long */
  81. #define ERR_PROTOTYPE    41
  82. #define ERR_AFNOSUPPORT  47
  83. #define ERR_HOSTUNREACH  65
  84. #define ECONNABORTED    53      /* Software caused connection abort */
  85. #define ERR_CONNRESET    54
  86. #define ERR_NOTCONN      57
  87.  
  88. #endif