-
Notifications
You must be signed in to change notification settings - Fork 0
/
7.1.c
37 lines (29 loc) · 788 Bytes
/
7.1.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
36
37
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#define SIZE 1024
int main(int argc, char *argv [])
{
int sock, i ;
char msg[SIZE];
struct sockaddr_in addr; // Internet socket
addr.sin_family = AF_INET; // Internet socket
inet_aton(argv[1], &addr.sin_addr);
addr.sin_port = htons(6000);
sock = socket(AF_INET, SOCK_DGRAM, 0); // Datagram socket
strcpy(msg, ””) ;
for ( i = 3; i < argc; i++) {
strcat (msg, argv[i ]) ;
strcat (msg, ” ”) ;
}
msg[strlen(msg)−1] = ’\0’; // Remove the last space
printf (”sending command : %s\n”, msg);
sendto(sock, msg, strlen (msg) + 1, 0,( struct sockaddr *)&addr, sizeof(addr));
close(sock);
return 0;
}