1 | #include <stdio.h> |
---|
2 | #include <sys/socket.h> |
---|
3 | #include <arpa/inet.h> |
---|
4 | #include <errno.h> |
---|
5 | #include <stdlib.h> |
---|
6 | #include <string.h> |
---|
7 | #include <fcntl.h> |
---|
8 | #include <signal.h> |
---|
9 | #include <unistd.h> |
---|
10 | #include <netinet/in.h> |
---|
11 | |
---|
12 | void Die(char *mess) |
---|
13 | { |
---|
14 | perror(mess); |
---|
15 | exit(1); |
---|
16 | } |
---|
17 | |
---|
18 | int main(int argc, char *argv[]) |
---|
19 | { |
---|
20 | struct sockaddr_in send_sockopt; |
---|
21 | int send_sock; |
---|
22 | int send_length = sizeof(send_sockopt); |
---|
23 | char BLACK_LIST[256]; |
---|
24 | |
---|
25 | if (argc <= 2) |
---|
26 | { |
---|
27 | fprintf(stderr, "USAGE: %s <RECV_IP> <RECV_PORT>\n", argv[0]); |
---|
28 | exit(1); |
---|
29 | } |
---|
30 | |
---|
31 | /* Create the UDP socket to send response to icas_recv */ |
---|
32 | if ((send_sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) |
---|
33 | { |
---|
34 | Die("Failed to create socket for sending black list."); |
---|
35 | } |
---|
36 | |
---|
37 | /* Construct the server sockaddr_in structure */ |
---|
38 | memset(&send_sockopt, 0, sizeof(send_sockopt)); /* Clear struct */ |
---|
39 | memset(&BLACK_LIST, 0, sizeof(BLACK_LIST)); /* Clear string */ |
---|
40 | sprintf(BLACK_LIST,"This is a test!"); |
---|
41 | |
---|
42 | // socket option of icas_send socket |
---|
43 | send_sockopt.sin_family = AF_INET; /* Internet/IP */ |
---|
44 | send_sockopt.sin_addr.s_addr = inet_addr(argv[1]); /* IP address */ |
---|
45 | send_sockopt.sin_port = htons(atoi(argv[2])); /* server port */ |
---|
46 | |
---|
47 | if (sendto(send_sock, BLACK_LIST, sizeof(BLACK_LIST), 0, |
---|
48 | (struct sockaddr *) &send_sockopt, |
---|
49 | sizeof(send_sockopt)) != sizeof(BLACK_LIST)) { |
---|
50 | Die("1: Mismatch in number of sent bytes"); |
---|
51 | } |
---|
52 | |
---|
53 | close(send_sock); |
---|
54 | exit(0); |
---|
55 | } |
---|