1 |
#include <stdio.h> |
2 |
#include <stdlib.h> |
3 |
#include <string.h> |
4 |
#include <stdarg.h> |
5 |
#include <unistd.h> |
6 |
#include <fcntl.h> |
7 |
#include <errno.h> |
8 |
#include <assert.h> |
9 |
|
10 |
#include "utils.h" |
11 |
#include "net.h" |
12 |
|
13 |
#define MAX_PKT_SIZE 2048 |
14 |
|
15 |
int main(int argc,char *argv[]) |
16 |
{ |
17 |
char pkt[MAX_PKT_SIZE]; |
18 |
size_t pkt_size; |
19 |
int sck; |
20 |
FILE *fd; |
21 |
|
22 |
if (!(fd = fopen(argv[1],"r"))) { |
23 |
perror("fopen"); |
24 |
exit(EXIT_FAILURE); |
25 |
} |
26 |
|
27 |
/* Read packet from file */ |
28 |
pkt_size = fread(pkt,1,MAX_PKT_SIZE,fd); |
29 |
|
30 |
/* Connect to remote port */ |
31 |
if ((sck = udp_connect(atoi(argv[2]),argv[3],atoi(argv[4]))) < 0) |
32 |
exit(EXIT_FAILURE); |
33 |
|
34 |
/* Send it */ |
35 |
if (send(sck,pkt,pkt_size,0) < 0) |
36 |
exit(EXIT_FAILURE); |
37 |
|
38 |
close(sck); |
39 |
return(0); |
40 |
} |