-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathciphertext.c
More file actions
44 lines (43 loc) · 1.26 KB
/
Copy pathciphertext.c
File metadata and controls
44 lines (43 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <poll.h>
int main(int argc,char **argv)
{
struct sockaddr_in server;
int s;
char packet[40];
char response[40];
struct pollfd p;
int j;
if (!argv[1]) return 100;
if (!inet_aton(argv[1],&server.sin_addr)) return 100;
server.sin_family = AF_INET;
server.sin_port = htons(10000);
while ((s = socket(AF_INET,SOCK_DGRAM,0)) == -1) sleep(1);
while (connect(s,(struct sockaddr *) &server,sizeof server
) == -1) sleep(1);
for (;;) {
for (j = 0;j < sizeof packet;++j) packet[j] = random();
send(s,packet,sizeof packet,0);
p.fd = s;
p.events = POLLIN;
if (poll(&p,1,100) <= 0) continue;
while (p.revents & POLLIN) {
if (recv(s,response,sizeof response,0) == sizeof response) {
if (!memcmp(packet,response,16)) {
for (j = 0;j < 16;++j)
printf("%02x ",255 & (unsigned int) response[j + 16]);
printf("\n");
return 0;
}
}
if (poll(&p,1,0) <= 0) break;
}
}
}