rubyipq 0.1.0-i686-linux
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/COPYING +339 -0
- data/Makefile +140 -0
- data/Rubyipq.so +0 -0
- data/extconf.rb +12 -0
- data/rubyipq.c +400 -0
- data/rubyipq.h +36 -0
- data/rubyipq_defs.h +85 -0
- data/rubyipq_ipheader.c +73 -0
- data/rubyipq_proto.h +167 -0
- data/rubyipq_tcpheader.c +69 -0
- data/rubyipq_udpheader.c +67 -0
- data/rubyipq_util.c +110 -0
- metadata +56 -0
data/rubyipq_defs.h
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* rubyipq v0.1.0
|
|
3
|
+
* Ruby bindings for Netfilter's libipq.
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) 2005 Leonardo Eloy
|
|
6
|
+
* Author: Leonardo Eloy <l.eloy@terra.com.br/leonardo.eloy@gmail.com>
|
|
7
|
+
* Project Homepage: http://rubyipq.rubyforge.org
|
|
8
|
+
*
|
|
9
|
+
*
|
|
10
|
+
* This program is free software; you can redistribute it and/or modify
|
|
11
|
+
* it under the terms of the GNU General Public License as published by
|
|
12
|
+
* the Free Software Foundation; either version 2 of the License, or
|
|
13
|
+
* (at your option) any later version.
|
|
14
|
+
*
|
|
15
|
+
* This program is distributed in the hope that it will be useful,
|
|
16
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
17
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
18
|
+
* GNU General Public License for more details.
|
|
19
|
+
*
|
|
20
|
+
* You should have received a copy of the GNU General Public License
|
|
21
|
+
* along with this program; if not, write to the Free Software
|
|
22
|
+
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
#include <sys/types.h>
|
|
26
|
+
#include <limits.h>
|
|
27
|
+
#include <net/if.h>
|
|
28
|
+
#include <netinet/ip.h>
|
|
29
|
+
#include <linux/netfilter_ipv4.h>
|
|
30
|
+
#include <linux/tcp.h>
|
|
31
|
+
#include <linux/udp.h>
|
|
32
|
+
#include <linux/icmp.h>
|
|
33
|
+
|
|
34
|
+
#include <linux/netfilter.h>
|
|
35
|
+
#include <libipq.h>
|
|
36
|
+
|
|
37
|
+
struct ipq_handle *handle;
|
|
38
|
+
unsigned char *last_packet;
|
|
39
|
+
ipq_packet_msg_t *last_packet_msg;
|
|
40
|
+
struct iphdr *last_ip_h;
|
|
41
|
+
struct tcphdr *last_tcp_h;
|
|
42
|
+
struct udphdr *last_udp_h;
|
|
43
|
+
struct icmphdr *last_icmp_h;
|
|
44
|
+
static int rubyipq_open, buffer_size;
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
/* Function declaration */
|
|
48
|
+
VALUE ipheader_new(VALUE class);
|
|
49
|
+
VALUE ipheader_init(VALUE class);
|
|
50
|
+
VALUE ipheader_tos(VALUE class);
|
|
51
|
+
VALUE ipheader_tot_len(VALUE class);
|
|
52
|
+
VALUE ipheader_id(VALUE class);
|
|
53
|
+
VALUE ipheader_frag_off(VALUE class);
|
|
54
|
+
VALUE ipheader_ttl(VALUE class);
|
|
55
|
+
VALUE ipheader_protocol(VALUE class);
|
|
56
|
+
VALUE ipheader_check(VALUE class);
|
|
57
|
+
VALUE ipheader_saddr(VALUE class);
|
|
58
|
+
VALUE ipheader_daddr(VALUE class);
|
|
59
|
+
|
|
60
|
+
VALUE tcpheader_new(VALUE class);
|
|
61
|
+
VALUE tcpheader_init(VALUE class);
|
|
62
|
+
VALUE tcpheader_source(VALUE class);
|
|
63
|
+
VALUE tcpheader_dest(VALUE class);
|
|
64
|
+
VALUE tcpheader_seq(VALUE class);
|
|
65
|
+
VALUE tcpheader_ack_seq(VALUE class);
|
|
66
|
+
VALUE tcpheader_window(VALUE class);
|
|
67
|
+
VALUE tcpheader_check(VALUE class);
|
|
68
|
+
VALUE tcpheader_get_data(VALUE class);
|
|
69
|
+
|
|
70
|
+
VALUE udpheader_new(VALUE class);
|
|
71
|
+
VALUE udpheader_init(VALUE class);
|
|
72
|
+
VALUE udpheader_source(VALUE class);
|
|
73
|
+
VALUE udpheader_dest(VALUE class);
|
|
74
|
+
VALUE udpheader_len(VALUE class);
|
|
75
|
+
VALUE udpheader_check(VALUE class);
|
|
76
|
+
VALUE udpheader_get_data(VALUE class);
|
|
77
|
+
|
|
78
|
+
char *__u32_to_str (__u32 ip);
|
|
79
|
+
unsigned char *get_last_packet();
|
|
80
|
+
ipq_packet_msg_t *get_last_packet_msg();
|
|
81
|
+
struct iphdr *get_last_ip_h();
|
|
82
|
+
struct tcphdr *get_last_tcp_h();
|
|
83
|
+
struct udphdr *get_last_udp_h();
|
|
84
|
+
struct udphdr *get_last_icmp_h();
|
|
85
|
+
void static_cleanup();
|
data/rubyipq_ipheader.c
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* rubyipq v0.1.0
|
|
3
|
+
* Ruby bindings for Netfilter's libipq.
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) 2005 Leonardo Eloy
|
|
6
|
+
* Author: Leonardo Eloy <l.eloy@terra.com.br/leonardo.eloy@gmail.com>
|
|
7
|
+
* Project Homepage: http://rubyipq.rubyforge.org
|
|
8
|
+
*
|
|
9
|
+
*
|
|
10
|
+
* This program is free software; you can redistribute it and/or modify
|
|
11
|
+
* it under the terms of the GNU General Public License as published by
|
|
12
|
+
* the Free Software Foundation; either version 2 of the License, or
|
|
13
|
+
* (at your option) any later version.
|
|
14
|
+
*
|
|
15
|
+
* This program is distributed in the hope that it will be useful,
|
|
16
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
17
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
18
|
+
* GNU General Public License for more details.
|
|
19
|
+
*
|
|
20
|
+
* You should have received a copy of the GNU General Public License
|
|
21
|
+
* along with this program; if not, write to the Free Software
|
|
22
|
+
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
#include "rubyipq.h"
|
|
26
|
+
|
|
27
|
+
/* IPHeader methods */
|
|
28
|
+
VALUE ipheader_new(VALUE class) {
|
|
29
|
+
last_ip_h = get_last_ip_h();
|
|
30
|
+
|
|
31
|
+
return class;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
VALUE ipheader_init(VALUE class) {
|
|
35
|
+
return class;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
VALUE ipheader_tos(VALUE class) {
|
|
39
|
+
return INT2NUM(get_last_ip_h()->tos);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
VALUE ipheader_tot_len(VALUE class) {
|
|
43
|
+
return INT2NUM(get_last_ip_h()->tot_len);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
VALUE ipheader_id(VALUE class) {
|
|
47
|
+
return INT2NUM(get_last_ip_h()->id);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
VALUE ipheader_frag_off(VALUE class) {
|
|
51
|
+
return INT2NUM(get_last_ip_h()->frag_off);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
VALUE ipheader_ttl(VALUE class) {
|
|
55
|
+
return INT2NUM(get_last_ip_h()->ttl);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
VALUE ipheader_protocol(VALUE class) {
|
|
59
|
+
return INT2NUM(get_last_ip_h()->protocol);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
VALUE ipheader_check(VALUE class) {
|
|
63
|
+
return INT2NUM(get_last_ip_h()->check);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
VALUE ipheader_saddr(VALUE class) {
|
|
67
|
+
return rb_str_new2(__u32_to_str((__u32)get_last_ip_h()->saddr));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
VALUE ipheader_daddr(VALUE class) {
|
|
71
|
+
return rb_str_new2(__u32_to_str((__u32)get_last_ip_h()->daddr));
|
|
72
|
+
}
|
|
73
|
+
|
data/rubyipq_proto.h
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* rubyipq v0.1.0
|
|
3
|
+
* Ruby bindings for Netfilter's libipq.
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) 2005 Leonardo Eloy
|
|
6
|
+
* Author: Leonardo Eloy <l.eloy@terra.com.br/leonardo.eloy@gmail.com>
|
|
7
|
+
* Project Homepage: http://rubyipq.rubyforge.org
|
|
8
|
+
*
|
|
9
|
+
*
|
|
10
|
+
* This program is free software; you can redistribute it and/or modify
|
|
11
|
+
* it under the terms of the GNU General Public License as published by
|
|
12
|
+
* the Free Software Foundation; either version 2 of the License, or
|
|
13
|
+
* (at your option) any later version.
|
|
14
|
+
*
|
|
15
|
+
* This program is distributed in the hope that it will be useful,
|
|
16
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
17
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
18
|
+
* GNU General Public License for more details.
|
|
19
|
+
*
|
|
20
|
+
* You should have received a copy of the GNU General Public License
|
|
21
|
+
* along with this program; if not, write to the Free Software
|
|
22
|
+
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/*
|
|
26
|
+
Protocol numbers took from http://www.iana.org/assignments/protocol_numbers
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
#define PROTO_HOPOPT 0
|
|
30
|
+
#define PROTO_GGP 3
|
|
31
|
+
#define PROTO_ST 5
|
|
32
|
+
#define PROTO_CBT 7
|
|
33
|
+
#define PROTO_EGP 8
|
|
34
|
+
#define PROTO_IGP 9
|
|
35
|
+
#define PROTO_BBN_RCC_MON 10
|
|
36
|
+
#define PROTO_NVP_II 11
|
|
37
|
+
#define PROTO_PUP 12
|
|
38
|
+
#define PROTO_ARGUS 13
|
|
39
|
+
#define PROTO_EMCON 14
|
|
40
|
+
#define PROTO_XNET 15
|
|
41
|
+
#define PROTO_CHAOS 16
|
|
42
|
+
#define PROTO_MUX 18
|
|
43
|
+
#define PROTO_DCN_MEAS 19
|
|
44
|
+
#define PROTO_HMP 20
|
|
45
|
+
#define PROTO_PRM 21
|
|
46
|
+
#define PROTO_XNS_IDP 22
|
|
47
|
+
#define PROTO_TRUNK_1 23
|
|
48
|
+
#define PROTO_TRUNK_2 24
|
|
49
|
+
#define PROTO_LEAF_1 25
|
|
50
|
+
#define PROTO_LEAF_2 26
|
|
51
|
+
#define PROTO_RDP 27
|
|
52
|
+
#define PROTO_IRTP 28
|
|
53
|
+
#define PROTO_ISO_TP4 29
|
|
54
|
+
#define PROTO_NETBLT 30
|
|
55
|
+
#define PROTO_MFE_NSP 31
|
|
56
|
+
#define PROTO_MERIT_INP 32
|
|
57
|
+
#define PROTO_DCCP 33
|
|
58
|
+
#define PROTO_3PC 34
|
|
59
|
+
#define PROTO_IDPR 35
|
|
60
|
+
#define PROTO_XTP 36
|
|
61
|
+
#define PROTO_DDP 37
|
|
62
|
+
#define PROTO_IDPR_CMTP 38
|
|
63
|
+
#define PROTO_TPpp 39
|
|
64
|
+
#define PROTO_IL 40
|
|
65
|
+
#define PROTO_IPV6 41
|
|
66
|
+
#define PROTO_SDRP 42
|
|
67
|
+
#define PROTO_IPV6_ROUTE 43
|
|
68
|
+
#define PROTO_IPV6_FRAG 44
|
|
69
|
+
#define PROTO_IDRP 45
|
|
70
|
+
#define PROTO_RSVP 46
|
|
71
|
+
#define PROTO_MHRP 48
|
|
72
|
+
#define PROTO_BNA 49
|
|
73
|
+
#define PROTO_I_NLSP 52
|
|
74
|
+
#define PROTO_SWIPE 53
|
|
75
|
+
#define PROTO_NARP 54
|
|
76
|
+
#define PROTO_MOBILE 55
|
|
77
|
+
#define PROTO_TLSP 56
|
|
78
|
+
#define PROTO_SKIP 57
|
|
79
|
+
#define PROTO_IPV6_ICMP 58
|
|
80
|
+
#define PROTO_IPV6_NONXT 59
|
|
81
|
+
#define PROTO_IPV6_OPTS 60
|
|
82
|
+
#define PROTO_ANY_HOST_INTERNAL_PROTOCOL 61
|
|
83
|
+
#define PROTO_CFTP 62
|
|
84
|
+
#define PROTO_ANY_LOCAL_NETWORK 63
|
|
85
|
+
#define PROTO_SAT_EXPAK 64
|
|
86
|
+
#define PROTO_KRYPTOLAN 65
|
|
87
|
+
#define PROTO_RVD 66
|
|
88
|
+
#define PROTO_IPPC 67
|
|
89
|
+
#define PROTO_ANY_DISTRIBUTED_FILE_SYSTEM 68
|
|
90
|
+
#define PROTO_SAT_MON 69
|
|
91
|
+
#define PROTO_VISA 70
|
|
92
|
+
#define PROTO_IPCV 71
|
|
93
|
+
#define PROTO_CPNX 72
|
|
94
|
+
#define PROTO_CPHB 73
|
|
95
|
+
#define PROTO_WSN 74
|
|
96
|
+
#define PROTO_PVP 75
|
|
97
|
+
#define PROTO_BR_SAT_MON 76
|
|
98
|
+
#define PROTO_SUN_ND 77
|
|
99
|
+
#define PROTO_WB_MON 78
|
|
100
|
+
#define PROTO_WB_EXPAK 79
|
|
101
|
+
#define PROTO_ISO_IP 80
|
|
102
|
+
#define PROTO_VMTP 81
|
|
103
|
+
#define PROTO_SECURE_VMTP 82
|
|
104
|
+
#define PROTO_VINES 83
|
|
105
|
+
#define PROTO_TTP 84
|
|
106
|
+
#define PROTO_NSFNET_IGP 85
|
|
107
|
+
#define PROTO_DGP 86
|
|
108
|
+
#define PROTO_TCF 87
|
|
109
|
+
#define PROTO_EIGRP 88
|
|
110
|
+
#define PROTO_OSPFIGP 89
|
|
111
|
+
#define PROTO_SPRITE_RPC 90
|
|
112
|
+
#define PROTO_LARP 91
|
|
113
|
+
#define PROTO_MTP 92
|
|
114
|
+
#define PROTO_AX_25 93
|
|
115
|
+
#define PROTO_IPIP 94
|
|
116
|
+
#define PROTO_MICP 95
|
|
117
|
+
#define PROTO_SCC_SP 96
|
|
118
|
+
#define PROTO_ETHERIP 97
|
|
119
|
+
#define PROTO_ENCAP 98
|
|
120
|
+
#define PROTO_ANY_PRIVATE_ENCRYPTION_SCHEME 99
|
|
121
|
+
#define PROTO_GMTP 100
|
|
122
|
+
#define PROTO_IFMP 101
|
|
123
|
+
#define PROTO_PNNI 102
|
|
124
|
+
#define PROTO_PIM 103
|
|
125
|
+
#define PROTO_ARIS 104
|
|
126
|
+
#define PROTO_SCPS 105
|
|
127
|
+
#define PROTO_QNX 106
|
|
128
|
+
#define PROTO_A_N 107
|
|
129
|
+
#define PROTO_IPCOMP 108
|
|
130
|
+
#define PROTO_SNP 109
|
|
131
|
+
#define PROTO_COMPAQ_PEER 110
|
|
132
|
+
#define PROTO_IPX_IN_IP 111
|
|
133
|
+
#define PROTO_VRRP 112
|
|
134
|
+
#define PROTO_PGM 113
|
|
135
|
+
#define PROTO_ANY_0_HOP_PROTOCOL 114
|
|
136
|
+
#define PROTO_DDX 116
|
|
137
|
+
#define PROTO_IATP 117
|
|
138
|
+
#define PROTO_STP 118
|
|
139
|
+
#define PROTO_SRP 119
|
|
140
|
+
#define PROTO_UTI 120
|
|
141
|
+
#define PROTO_SMP 121
|
|
142
|
+
#define PROTO_SM 122
|
|
143
|
+
#define PROTO_PTP 123
|
|
144
|
+
#define PROTO_ISIS_OVER_IPV4 124
|
|
145
|
+
#define PROTO_FIRE 125
|
|
146
|
+
#define PROTO_CRTP 126
|
|
147
|
+
#define PROTO_CRUDP 127
|
|
148
|
+
#define PROTO_SSCOPMCE 128
|
|
149
|
+
#define PROTO_IPLT 129
|
|
150
|
+
#define PROTO_SPS 130
|
|
151
|
+
#define PROTO_PIPE 131
|
|
152
|
+
#define PROTO_SCTP 132
|
|
153
|
+
#define PROTO_FC 133
|
|
154
|
+
#define PROTO_RSVP_E2E_IGNORE 134
|
|
155
|
+
#define PROTO_MOBILITY 135
|
|
156
|
+
#define PROTO_UDPLITE 136
|
|
157
|
+
#define PROTO_MPLS_IN_IP 137
|
|
158
|
+
|
|
159
|
+
#define PROTO_ICMP 1
|
|
160
|
+
#define PROTO_IGMP 2
|
|
161
|
+
#define PROTO_IP 4
|
|
162
|
+
#define PROTO_TCP 6
|
|
163
|
+
#define PROTO_UDP 17
|
|
164
|
+
#define PROTO_GRE 47
|
|
165
|
+
#define PROTO_ESP 50
|
|
166
|
+
#define PROTO_AH 51
|
|
167
|
+
#define PROTO_L2TP 115
|
data/rubyipq_tcpheader.c
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* rubyipq v0.1.0
|
|
3
|
+
* Ruby bindings for Netfilter's libipq.
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) 2005 Leonardo Eloy
|
|
6
|
+
* Author: Leonardo Eloy <l.eloy@terra.com.br/leonardo.eloy@gmail.com>
|
|
7
|
+
* Project Homepage: http://rubyipq.rubyforge.org
|
|
8
|
+
*
|
|
9
|
+
*
|
|
10
|
+
* This program is free software; you can redistribute it and/or modify
|
|
11
|
+
* it under the terms of the GNU General Public License as published by
|
|
12
|
+
* the Free Software Foundation; either version 2 of the License, or
|
|
13
|
+
* (at your option) any later version.
|
|
14
|
+
*
|
|
15
|
+
* This program is distributed in the hope that it will be useful,
|
|
16
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
17
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
18
|
+
* GNU General Public License for more details.
|
|
19
|
+
*
|
|
20
|
+
* You should have received a copy of the GNU General Public License
|
|
21
|
+
* along with this program; if not, write to the Free Software
|
|
22
|
+
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
#include "rubyipq.h"
|
|
26
|
+
|
|
27
|
+
/* TCPHeader methods */
|
|
28
|
+
VALUE tcpheader_new(VALUE class) {
|
|
29
|
+
last_tcp_h = get_last_tcp_h();
|
|
30
|
+
|
|
31
|
+
return class;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
VALUE tcpheader_init(VALUE class) {
|
|
35
|
+
return class;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
VALUE tcpheader_source(VALUE class) {
|
|
39
|
+
return INT2NUM(ntohs((__u16)get_last_tcp_h()->source));
|
|
40
|
+
}
|
|
41
|
+
VALUE tcpheader_dest(VALUE class) {
|
|
42
|
+
return INT2NUM(ntohs((__u16)get_last_tcp_h()->dest));
|
|
43
|
+
}
|
|
44
|
+
VALUE tcpheader_seq(VALUE class) {
|
|
45
|
+
return INT2NUM(get_last_tcp_h()->seq);
|
|
46
|
+
}
|
|
47
|
+
VALUE tcpheader_ack_seq(VALUE class) {
|
|
48
|
+
return INT2NUM(get_last_tcp_h()->ack_seq);
|
|
49
|
+
}
|
|
50
|
+
VALUE tcpheader_window(VALUE class) {
|
|
51
|
+
return INT2NUM(get_last_tcp_h()->window);
|
|
52
|
+
}
|
|
53
|
+
VALUE tcpheader_check(VALUE class) {
|
|
54
|
+
return INT2NUM(get_last_tcp_h()->check);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
VALUE tcpheader_get_data(VALUE class) {
|
|
58
|
+
unsigned int len = (unsigned int)ntohs(get_last_ip_h()->tot_len) - ((get_last_ip_h()->ihl<<2) + (get_last_tcp_h()->doff<<2));
|
|
59
|
+
|
|
60
|
+
if (len) {
|
|
61
|
+
char *str;
|
|
62
|
+
str = (get_last_packet_msg()->payload + (get_last_ip_h()->ihl<<2) + (get_last_tcp_h()->doff<<2));
|
|
63
|
+
|
|
64
|
+
return rb_str_new2(str);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return Qnil;
|
|
68
|
+
}
|
|
69
|
+
|
data/rubyipq_udpheader.c
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* rubyipq v0.1.0
|
|
3
|
+
* Ruby bindings for Netfilter's libipq.
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) 2005 Leonardo Eloy
|
|
6
|
+
* Author: Leonardo Eloy <l.eloy@terra.com.br/leonardo.eloy@gmail.com>
|
|
7
|
+
* Project Homepage: http://rubyipq.rubyforge.org
|
|
8
|
+
*
|
|
9
|
+
*
|
|
10
|
+
* This program is free software; you can redistribute it and/or modify
|
|
11
|
+
* it under the terms of the GNU General Public License as published by
|
|
12
|
+
* the Free Software Foundation; either version 2 of the License, or
|
|
13
|
+
* (at your option) any later version.
|
|
14
|
+
*
|
|
15
|
+
* This program is distributed in the hope that it will be useful,
|
|
16
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
17
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
18
|
+
* GNU General Public License for more details.
|
|
19
|
+
*
|
|
20
|
+
* You should have received a copy of the GNU General Public License
|
|
21
|
+
* along with this program; if not, write to the Free Software
|
|
22
|
+
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
#include "rubyipq.h"
|
|
26
|
+
|
|
27
|
+
/* UDP header methods */
|
|
28
|
+
VALUE udpheader_new(VALUE class) {
|
|
29
|
+
last_udp_h = get_last_udp_h();
|
|
30
|
+
|
|
31
|
+
return class;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
VALUE udpheader_init(VALUE class) {
|
|
35
|
+
return class;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
VALUE udpheader_source(VALUE class) {
|
|
39
|
+
return INT2NUM(ntohs((__u16)get_last_udp_h()->source));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
VALUE udpheader_dest(VALUE class) {
|
|
43
|
+
return INT2NUM(ntohs((__u16)get_last_udp_h()->dest));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
VALUE udpheader_len(VALUE class) {
|
|
47
|
+
return INT2NUM(get_last_udp_h()->len);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
VALUE udpheader_check(VALUE class) {
|
|
51
|
+
return INT2NUM(get_last_udp_h()->check);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
VALUE udpheader_get_data(VALUE class) {
|
|
55
|
+
/* UDP header has always 8 bytes in size */
|
|
56
|
+
|
|
57
|
+
if ((unsigned int)ntohs(get_last_ip_h()->tot_len) - (get_last_ip_h()->ihl<<2) + 8) {
|
|
58
|
+
char *str;
|
|
59
|
+
str = (get_last_packet_msg()->payload + (get_last_ip_h()->ihl<<2) + 8);
|
|
60
|
+
|
|
61
|
+
return rb_str_new2(str);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return Qnil;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
|