Advertisement
tyler569

sending a packet!

Sep 8th, 2018
424
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. // sending code
  2.  
  3. int main() {
  4.  
  5. strace(1);
  6.  
  7. int sock_fd = socket(AF_INET, SOCK_DGRAM, PROTO_UDP);
  8. bind0(sock_fd, 0x0a00020f /* 10.0.2.15 */, 4);
  9. connect0(sock_fd, 0x0a000202 /* 10.0.2.2 */, 1330);
  10.  
  11. write(sock_fd, "Hello World\n", 12);
  12. printf("data sent\n");
  13. char recv[128] = {0};
  14. read(sock_fd, recv, 128);
  15. printf("received: '%s'\n", recv);
  16.  
  17. }
  18.  
  19. // trace of execution
  20.  
  21. $ net
  22. strace(true) -> { value = 0, error = 0 };
  23. socket(0, 0, 17) -> { value = 3, error = 0 };
  24. bind0(3, 0xa00020f, 4) -> { value = 0, error = 0 };
  25. connect0(3, 0xa000202, 1330) -> { value = 0, error = 0 };
  26. write(3, 401800, c)sending packet at vma:0xffffffff801cc458, pma:0x193458, len:54
  27. -> { value = c, error = 0 };
  28. write(1, 7ffffefffbf8, a)data sent
  29. -> { value = a, error = 0 };
  30. <quit>
  31.  
  32. // listening on port 1330
  33.  
  34. tyler@xps:~/nightingale/kernel/net$ nc -u -l 1330
  35. Hello World
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement