Annotation of embedaddon/hping2/ip_opt_build.c, revision 1.1.1.1
1.1 misho 1: /*
2: * $smu-mark$
3: * $name: memunlock.c$
4: * $other_author: Mika <mika@qualys.com>
5: * $other_copyright: Copyright (C) 1999 Mika <mika@qualys.com>
6: * $license: This software is under GPL version 2 of license$
7: * $date: Fri Nov 5 11:55:48 MET 1999$
8: * $rev: 2$
9: */
10:
11: #include <stdio.h>
12: #include <string.h>
13: #include <sys/types.h>
14: #include <netinet/in.h>
15: #include <sys/socket.h>
16: #include <arpa/inet.h>
17:
18: #include "hping2.h"
19: #include "globals.h"
20:
21: unsigned char ip_opt_build(char* ip_opt)
22: {
23: unsigned char optlen = 0;
24: unsigned long ip;
25:
26: memset(ip_opt, 1, sizeof(ip_opt));
27:
28: if (opt_lsrr)
29: {
30: if (lsr_length<=39)
31: {
32: memcpy(ip_opt, &lsr, lsr_length);
33: optlen += lsr_length;
34: }
35: else
36: {
37: printf("Warning: loose source route is too long, discarding it");
38: opt_lsrr=0;
39: }
40: }
41:
42: if (opt_ssrr)
43: {
44: if (ssr_length+optlen<=39)
45: {
46: memcpy(ip_opt + optlen, &ssr, ssr_length);
47: optlen += ssr_length;
48: }
49: else
50: {
51: printf("Warning: strict source route is too long, discarding it");
52: opt_ssrr=0;
53: }
54: }
55:
56: if (opt_rroute)
57: {
58: if (optlen<=33)
59: {
60: ip_opt[optlen]=IPOPT_RR;
61: ip_opt[optlen+1]=39-optlen;
62: ip_opt[optlen+2]=8;
63: ip=inet_addr("1.2.3.4");
64: memcpy(ip_opt+optlen+3,&ip,4);
65: optlen=39;
66: }
67: else
68: {
69: printf("Warning: no room for record route, discarding option\n");
70: opt_rroute=0;
71: }
72: }
73:
74: if (optlen)
75: {
76: optlen = (optlen + 3) & ~3;
77: ip_opt[optlen-1] = 0;
78: return optlen;
79: }
80: else
81: return 0;
82: }
83:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>