-
Notifications
You must be signed in to change notification settings - Fork 333
/
ip_opt_build.c
85 lines (75 loc) · 1.76 KB
/
ip_opt_build.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
* $smu-mark$
* $name: memunlock.c$
* $other_author: Mika <[email protected]>
* $other_copyright: Copyright (C) 1999 Mika <[email protected]>
* $license: This software is under GPL version 2 of license$
* $date: Fri Nov 5 11:55:48 MET 1999$
* $rev: 2$
*/
/* $Id: ip_opt_build.c,v 1.2 2003/09/01 00:22:06 antirez Exp $ */
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include "hping2.h"
#include "globals.h"
unsigned char ip_opt_build(char* ip_opt)
{
unsigned char optlen = 0;
unsigned long ip;
memset(ip_opt, 1, 40);
if (opt_lsrr)
{
if (lsr_length<=39)
{
memcpy(ip_opt, &lsr, lsr_length);
optlen += lsr_length;
}
else
{
printf("Warning: loose source route is too long, discarding it");
opt_lsrr=0;
}
}
if (opt_ssrr)
{
if (ssr_length+optlen<=39)
{
memcpy(ip_opt + optlen, &ssr, ssr_length);
optlen += ssr_length;
}
else
{
printf("Warning: strict source route is too long, discarding it");
opt_ssrr=0;
}
}
if (opt_rroute)
{
if (optlen<=33)
{
ip_opt[optlen]=IPOPT_RR;
ip_opt[optlen+1]=39-optlen;
ip_opt[optlen+2]=8;
ip=inet_addr("1.2.3.4");
memcpy(ip_opt+optlen+3,&ip,4);
optlen=39;
}
else
{
printf("Warning: no room for record route, discarding option\n");
opt_rroute=0;
}
}
if (optlen)
{
optlen = (optlen + 3) & ~3;
ip_opt[optlen-1] = 0;
return optlen;
}
else
return 0;
}