-
Notifications
You must be signed in to change notification settings - Fork 0
/
client_udp.c
35 lines (33 loc) · 1 KB
/
client_udp.c
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
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "restart.h"
#include "uiciudp.h"
#define BUFSIZE 1024
int main(int argc, char *argv[]) {
ssize_t byteswritten;
char request[BUFSIZE];
int requestfd;
int rlen;
u_port_t serverport;
if (argc != 3) {
fprintf(stderr, "Usage: %s servername serverport\n", argv[0]);
return 1;
}
serverport = (u_port_t) atoi(argv[2]);
if ((requestfd = u_openudp(0)) == -1) { /* create unbound UDP endpoint */
perror("Failed to create UDP endpoint");
return 1;
}
sprintf(request, "[%ld]\n", (long)getpid()); /* create a request */
rlen = strlen(request);
/* use simple-request protocol to send a request to (server, serverport) */
byteswritten = u_sendtohost(requestfd, request, rlen, argv[1], serverport);
if (byteswritten == -1)
perror("Failed to send");
if (r_close(requestfd) == -1 || byteswritten == -1)
return 1;
return 0;
}