Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. #include "kosnet/socket.h"
  2.  
  3. int err_code = 0;
  4.  
  5. int socket(int domain, int type, int protocol)
  6. {
  7.     int socket;
  8.     asm volatile(
  9.     "int $0x40"
  10.     :"=b"(err_code), "=a"(socket)
  11.     :"a"(75), "b"(0), "c"(domain), "d"(type), "S"(protocol)
  12.     );
  13.     return socket;
  14. }
  15.  
  16. int closesocket(int socket)
  17. {
  18.     int status;
  19.     asm volatile(
  20.     "int $0x40"
  21.     :"=b"(err_code), "=a"(status)
  22.     :"a"(75), "b"(1), "c"(socket)
  23.     );
  24.     return status;
  25. }
  26.  
  27. int bind(int socket, const sockaddr *addres, int addres_len)
  28. {
  29.     int status;
  30.     asm volatile(
  31.     "int $0x40"
  32.     :"=b"(err_code), "=a"(status)
  33.     :"a"(75), "b"(2), "c"(socket), "d"(addres), "S"(addres_len)
  34.     );
  35.     return status;
  36. }
  37.  
  38. int listen(int socket, int backlog)
  39. {
  40.     int status;
  41.     asm volatile(
  42.     "int $0x40"
  43.     :"=b"(err_code), "=a"(status)
  44.     :"a"(75), "b"(3), "c"(socket), "d"(backlog)
  45.     );
  46.     return status;
  47. }
  48.  
  49. int connect(int socket,const sockaddr* address, int socket_len)
  50. {
  51.     int status;
  52.     asm volatile(
  53.     "int $0x40"
  54.     :"=b"(err_code), "=a"(status)
  55.     :"a"(75), "b"(4), "c"(socket), "d"(address), "S"(socket_len)
  56.     );
  57.     return status;
  58. }
  59.  
  60. int accept(int socket, const sockaddr *address, int address_len)
  61. {
  62.     int new_socket;
  63.     asm volatile(
  64.     "int $0x40"
  65.     :"=b"(err_code), "=a"(new_socket)
  66.     :"a"(75), "b"(5), "c"(socket), "d"(address), "S"(address_len)
  67.     );
  68.     return new_socket;
  69. }
  70.  
  71. int send(int socket, const void *message, size_t msg_len, int flag)
  72. {
  73.     int status;
  74.     asm volatile(
  75.     "int $0x40"
  76.     :"=b"(err_code), "=a"(status)
  77.     :"a"(75), "b"(6), "c"(socket), "d"(message), "S"(msg_len), "D"(flag)
  78.     );
  79.     return status;
  80. }
  81.  
  82. int recv(int socket, void *buffer, size_t buff_len, int flag)
  83. {
  84.     int status;
  85.     asm volatile(
  86.     "int $0x40"
  87.     :"=b"(err_code), "=a"(status)
  88.     :"a"(75), "b"(7), "c"(socket), "d"(buffer), "S"(buff_len), "D"(flag)
  89.     );
  90.     return status;
  91. }
  92.  
  93. int setsockopt(int socket,const optstruct* opt)
  94. {
  95.     int status;
  96.     asm volatile(
  97.         "int $0x40"
  98.         :"=b"(err_code), "=a"(status)
  99.         :"a"(75), "b"(8), "c"(socket),"d"(opt)
  100.     );
  101.     return status;
  102. }
  103.  
  104. int getsockopt(int socket, optstruct* opt)
  105. {
  106.     int status;
  107.     asm volatile(
  108.         "int $0x40"
  109.         :"=b"(err_code), "=a"(status)
  110.         :"a"(75), "b"(9), "c"(socket),"d"(opt)
  111.     );
  112.     return status;
  113. }
  114.  
  115. int socketpair(int *socket1, int *socket2)
  116. {
  117.     asm volatile(
  118.         "int $0x40"
  119.         :"=b"(*socket2), "=a"(*socket1)
  120.         :"a"(75), "b"(10)
  121.     );
  122.     err_code=*socket2;
  123.     return *socket1;
  124. }