#include <iostream>
#include <arpa/inet.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
using namespace std;
int main()
{
char buf[255];
struct sockaddr_in si_other;
int s, slen=sizeof(si_other);
if ((s=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP))==-1)
cout << "socket\n";
memset((char *) &si_other, 0, sizeof(si_other));
si_other.sin_family = AF_INET;
si_other.sin_port = htons(3478);
if (inet_aton("217.10.68.152", &si_other.sin_addr)==0) // stun adres
{
fprintf(stderr, "inet_aton() failed\n");
exit(1);
}
while (1)
{
usleep(10000);
cout << "input_mess >>>";
cin >> buf;
if (sendto(s, buf, strlen(buf), 0, (struct sockaddr *)&si_other, slen)==-1)
cout << "sendto()\n";
for(int i = 0; i < 255; i++)
buf[i] = 0;
if (recvfrom(s, buf, 255, 0, (struct sockaddr *) &si_other,(socklen_t*) &slen) == -1)
{
cout << "recvfrom()\n";
}
cout << buf << endl;
}
close(s);
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8YXJwYS9pbmV0Lmg+CiNpbmNsdWRlIDx1bmlzdGQuaD4KI2luY2x1ZGUgPHN5cy9zb2NrZXQuaD4KI2luY2x1ZGUgPHN5cy90eXBlcy5oPgojaW5jbHVkZSA8c3RkaW8uaD4KI2luY2x1ZGUgPHN0cmluZy5oPgojaW5jbHVkZSA8c3RkbGliLmg+CgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmludCBtYWluKCkKewoJY2hhciBidWZbMjU1XTsKCXN0cnVjdCBzb2NrYWRkcl9pbiBzaV9vdGhlcjsKCWludCBzLCBzbGVuPXNpemVvZihzaV9vdGhlcik7CglpZiAoKHM9c29ja2V0KEFGX0lORVQsIFNPQ0tfREdSQU0sIElQUFJPVE9fVURQKSk9PS0xKQoJCWNvdXQgPDwgInNvY2tldFxuIjsKCW1lbXNldCgoY2hhciAqKSAmc2lfb3RoZXIsIDAsIHNpemVvZihzaV9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