Advertisement
Guest User

DLA INDEXU 426253

a guest
Mar 20th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. #include<stdio.h> //printf
  2. #include<string.h> //memset
  3. #include<stdlib.h> //exit(0);
  4. #include<arpa/inet.h>
  5. #include<sys/socket.h>
  6.  
  7. #define SERVER "150.254.78.29"
  8. #define BUFLEN 11 //Max length of buffer
  9. #define PORT 12345 //The port on which to send data
  10. #define ATTEMPS 10
  11. void die(char *s)
  12. {
  13. perror(s);
  14. exit(1);
  15. }
  16.  
  17. int main(void)
  18. {
  19. struct sockaddr_in si_other;
  20. int s, i, slen=sizeof(si_other);
  21. char buf[BUFLEN];
  22. char message[BUFLEN];
  23. struct timeval time_b, time_e;
  24.  
  25. if ( (s=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1)
  26. {
  27. die("socket");
  28. }
  29.  
  30. memset((char *) &si_other, 0, sizeof(si_other));
  31. si_other.sin_family = AF_INET;
  32. si_other.sin_port = htons(PORT);
  33.  
  34. if (inet_aton(SERVER , &si_other.sin_addr) == 0)
  35. {
  36. fprintf(stderr, "inet_aton() failed\n");
  37. exit(1);
  38. }
  39. /*
  40. int j;
  41. for(j=0;j<BUFLEN;j++)
  42. buf[j]=j;
  43. */
  44. buf[0] = 0x34;
  45. buf[1] = 0x32;
  46. buf[2] = 0x36;
  47. buf[3] = 0x32;
  48. buf[4] = 0x35;
  49. buf[5] = 0x33;
  50. buf[6] = 0x0A;
  51. buf[7] = 0x00;
  52. buf[8] = 0x06;
  53. buf[9] = 0x81;
  54. buf[10] = 0x0D;
  55.  
  56. int x = ATTEMPS;
  57.  
  58. //send the message
  59. sendto(s, buf, BUFLEN , 0 , (struct sockaddr *) &si_other, slen);
  60. //recvfrom(s, buf, BUFLEN, 0, (struct sockaddr *) &si_other, &slen);
  61.  
  62.  
  63. /*
  64. printf("czas: %.6f s\n",
  65. (((double) (time_e.tv_sec - time_b.tv_sec) * 1000000) +
  66. ((double) (time_e.tv_usec - time_b.tv_usec)))
  67. / (100000.0 * ATTEMPS));
  68. */
  69. return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement