Annotation of embedaddon/hping2/sendudp.c, revision 1.1.1.1
1.1 misho 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: #include <stdio.h>
12: #include <string.h>
13: #include <stdlib.h>
14: #include <time.h>
15: #include <sys/time.h>
16: #include <unistd.h>
17: #include <signal.h>
18:
19: #include "hping2.h"
20: #include "globals.h"
21:
22: /* void hexdumper(unsigned char *packet, int size); */
23:
24: void send_udp(void)
25: {
26: int packet_size;
27: char *packet, *data;
28: struct myudphdr *udp;
29: struct pseudohdr *pseudoheader;
30:
31: packet_size = UDPHDR_SIZE + data_size;
32: packet = malloc(PSEUDOHDR_SIZE + packet_size);
33: if (packet == NULL) {
34: perror("[send_udphdr] malloc()");
35: return;
36: }
37: pseudoheader = (struct pseudohdr*) packet;
38: udp = (struct myudphdr*) (packet+PSEUDOHDR_SIZE);
39: data = (char*) (packet+PSEUDOHDR_SIZE+UDPHDR_SIZE);
40:
41: memset(packet, 0, PSEUDOHDR_SIZE+packet_size);
42:
43: /* udp pseudo header */
44: memcpy(&pseudoheader->saddr, &local.sin_addr.s_addr, 4);
45: memcpy(&pseudoheader->daddr, &remote.sin_addr.s_addr, 4);
46: pseudoheader->protocol = 17; /* udp */
47: pseudoheader->lenght = htons(packet_size);
48:
49: /* udp header */
50: udp->uh_dport = htons(dst_port);
51: udp->uh_sport = htons(src_port);
52: udp->uh_ulen = htons(packet_size);
53:
54: /* data */
55: data_handler(data, data_size);
56:
57: /* compute checksum */
58: #ifdef STUPID_SOLARIS_CHECKSUM_BUG
59: udp->uh_sum = packet_size;
60: #else
61: udp->uh_sum = cksum((__u16*) packet, PSEUDOHDR_SIZE +
62: packet_size);
63: #endif
64:
65: /* adds this pkt in delaytable */
66: delaytable_add(sequence, src_port, time(NULL), get_usec(), S_SENT);
67:
68: /* send packet */
69: send_ip_handler(packet+PSEUDOHDR_SIZE, packet_size);
70: free(packet);
71:
72: sequence++; /* next sequence number */
73:
74: if (!opt_keepstill)
75: src_port = (sequence + initsport) % 65536;
76:
77: if (opt_force_incdport)
78: dst_port++;
79: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>