-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy patheaddrinuse.c
More file actions
44 lines (34 loc) · 778 Bytes
/
Copy patheaddrinuse.c
File metadata and controls
44 lines (34 loc) · 778 Bytes
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
#include <stdio.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <errno.h>
#include <unistd.h>
#include <string.h>
int main()
{
int fd;
int ret;
fd = socket(AF_INET, SOCK_DGRAM, 0);
if (fd < 0) {
return -1;
}
struct sockaddr_in addr;
addr.sin_addr.s_addr = INADDR_ANY;
addr.sin_family = AF_INET;
addr.sin_port = htons(4444);
ret = bind(fd, (struct sockaddr *)&addr, sizeof(addr));
if (ret < 0) {
fprintf(stderr, "failed to bind : %s\n", strerror(errno));
close(fd);
return -1;
}
while (1) {
char buf[100];
ret = recvfrom(fd, buf, sizeof(buf), 0, NULL, NULL);
if (ret < 0) {
break;
}
}
close(fd);
}