Skip to content
Newer
Older
100644 82 lines (65 sloc) 1.94 KB
7257579 @antirez Git repository created from hping3-clockskew-0.tar.gz
authored
1 /*
2 * $smu-mark$
3 * $name: sendudp.c$
4 * $author: Salvatore Sanfilippo <antirez@invece.org>$
5 * $copyright: Copyright (C) 1999 by Salvatore Sanfilippo$
6 * $license: This software is under GPL version 2 of license$
7 * $date: Fri Nov 5 11:55:49 MET 1999$
8 * $rev: 8$
9 */
10
11 /* $Id: sendudp.c,v 1.2 2003/09/01 00:22:06 antirez Exp $ */
12
13 #include <stdio.h>
14 #include <string.h>
15 #include <stdlib.h>
16 #include <time.h>
17 #include <sys/time.h>
18 #include <unistd.h>
19 #include <signal.h>
20
21 #include "hping2.h"
22 #include "globals.h"
23
24 /* void hexdumper(unsigned char *packet, int size); */
25
26 void send_udp(void)
27 {
28 int packet_size;
29 char *packet, *data;
30 struct myudphdr *udp;
31 struct pseudohdr *pseudoheader;
32
33 packet_size = UDPHDR_SIZE + data_size;
34 packet = malloc(PSEUDOHDR_SIZE + packet_size);
35 if (packet == NULL) {
36 perror("[send_udphdr] malloc()");
37 return;
38 }
39 pseudoheader = (struct pseudohdr*) packet;
40 udp = (struct myudphdr*) (packet+PSEUDOHDR_SIZE);
41 data = (char*) (packet+PSEUDOHDR_SIZE+UDPHDR_SIZE);
42
43 memset(packet, 0, PSEUDOHDR_SIZE+packet_size);
44
45 /* udp pseudo header */
46 memcpy(&pseudoheader->saddr, &local.sin_addr.s_addr, 4);
47 memcpy(&pseudoheader->daddr, &remote.sin_addr.s_addr, 4);
48 pseudoheader->protocol = 17; /* udp */
49 pseudoheader->lenght = htons(packet_size);
50
51 /* udp header */
52 udp->uh_dport = htons(dst_port);
53 udp->uh_sport = htons(src_port);
54 udp->uh_ulen = htons(packet_size);
55
56 /* data */
57 data_handler(data, data_size);
58
59 /* compute checksum */
60 #ifdef STUPID_SOLARIS_CHECKSUM_BUG
61 udp->uh_sum = packet_size;
62 #else
63 udp->uh_sum = cksum((__u16*) packet, PSEUDOHDR_SIZE +
64 packet_size);
65 #endif
66
67 /* adds this pkt in delaytable */
68 delaytable_add(sequence, src_port, time(NULL), get_usec(), S_SENT);
69
70 /* send packet */
71 send_ip_handler(packet+PSEUDOHDR_SIZE, packet_size);
72 free(packet);
73
74 sequence++; /* next sequence number */
75
76 if (!opt_keepstill)
77 src_port = (sequence + initsport) % 65536;
78
79 if (opt_force_incdport)
80 dst_port++;
81 }
Something went wrong with that request. Please try again.