Advertisement
Guest User

Untitled

a guest
Jan 19th, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. #include "types.h"
  2. #include "defs.h"
  3. #include "param.h"
  4. #include "memlayout.h"
  5. #include "mmu.h"
  6. #include "x86.h"
  7. #include "proc.h"
  8.  
  9. int
  10. sys_listen(void)
  11. {
  12. int port = 0;
  13.  
  14. if(argint(0,&port) < 0) return -1;
  15.  
  16. return listen(port);
  17. }
  18.  
  19. int
  20. sys_connect(void)
  21. {
  22. int port = 0;
  23. char *host = 0;
  24.  
  25. if(argint(0, &port) < 0) return -1;
  26. if(argstr(1, &host) < 0) return -1;
  27.  
  28. if(strncmp(host,"127.0.0.1",strlen(host))!=0 && strncmp(host,"localhost",strlen(host)) != 0)
  29. {
  30. return E_INVALID_ARG; // error in port or host
  31. }
  32. return connect(port, host);
  33. }
  34.  
  35. int
  36. sys_send(void)
  37. {
  38. int port = 0;
  39. char* buf = 0;
  40. int n = 0;
  41.  
  42. if(argint(0, &port)<0 || argint(2, &n) < 0 || argstr(1, &buf) < 0)
  43. return -1;
  44.  
  45. return send(port, buf, n);
  46. }
  47.  
  48. int
  49. sys_recv(void)
  50. {
  51. int port = 0;
  52. char* buf = 0;
  53. int n = 0;
  54.  
  55. if(argint(0, &port) < 0 || argint(2, &n) < 0 || argstr(1, &buf) < 0)
  56. return -1;
  57.  
  58. return recv(port, buf, n);
  59. }
  60.  
  61. int
  62. sys_disconnect(void)
  63. {
  64. int port = 0;
  65.  
  66. if(argint(0, &port) < 0) return -1;
  67.  
  68. return disconnect(port);
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement