Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h> //printf
- #include<string.h> //memset
- #include<stdlib.h> //exit(0);
- #include<arpa/inet.h>
- #include<sys/socket.h>
- #define SERVER "150.254.78.29"
- #define BUFLEN 11 //Max length of buffer
- #define PORT 12345 //The port on which to send data
- #define ATTEMPS 10
- void die(char *s)
- {
- perror(s);
- exit(1);
- }
- int main(void)
- {
- struct sockaddr_in si_other;
- int s, i, slen=sizeof(si_other);
- char buf[BUFLEN];
- char message[BUFLEN];
- struct timeval time_b, time_e;
- if ( (s=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1)
- {
- die("socket");
- }
- memset((char *) &si_other, 0, sizeof(si_other));
- si_other.sin_family = AF_INET;
- si_other.sin_port = htons(PORT);
- if (inet_aton(SERVER , &si_other.sin_addr) == 0)
- {
- fprintf(stderr, "inet_aton() failed\n");
- exit(1);
- }
- /*
- int j;
- for(j=0;j<BUFLEN;j++)
- buf[j]=j;
- */
- buf[0] = 0x34;
- buf[1] = 0x32;
- buf[2] = 0x36;
- buf[3] = 0x32;
- buf[4] = 0x35;
- buf[5] = 0x33;
- buf[6] = 0x0A;
- buf[7] = 0x00;
- buf[8] = 0x06;
- buf[9] = 0x81;
- buf[10] = 0x0D;
- int x = ATTEMPS;
- //send the message
- sendto(s, buf, BUFLEN , 0 , (struct sockaddr *) &si_other, slen);
- //recvfrom(s, buf, BUFLEN, 0, (struct sockaddr *) &si_other, &slen);
- /*
- printf("czas: %.6f s\n",
- (((double) (time_e.tv_sec - time_b.tv_sec) * 1000000) +
- ((double) (time_e.tv_usec - time_b.tv_usec)))
- / (100000.0 * ATTEMPS));
- */
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement