Subversion Repositories Kolibri OS

Rev

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

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