1libnet-functions.h(3) libnet Programmers Guide libnet-functions.h(3)
2
3
4
6 libnet-functions.h - libnet exported function prototypes
7
8
10 Functions
11 LIBNET_API libnet_t * libnet_init (int injection_type, const char
12 *device, char *err_buf)
13 LIBNET_API void libnet_destroy (libnet_t *l)
14 LIBNET_API void libnet_clear_packet (libnet_t *l)
15 LIBNET_API void libnet_stats (libnet_t *l, struct libnet_stats *ls)
16 LIBNET_API int libnet_getfd (libnet_t *l)
17 LIBNET_API const char * libnet_getdevice (libnet_t *l)
18 LIBNET_API uint8_t * libnet_getpbuf (libnet_t *l, libnet_ptag_t ptag)
19 LIBNET_API uint32_t libnet_getpbuf_size (libnet_t *l, libnet_ptag_t
20 ptag)
21 LIBNET_API char * libnet_geterror (libnet_t *l)
22 LIBNET_API uint32_t libnet_getpacket_size (libnet_t *l)
23 LIBNET_API int libnet_seed_prand (libnet_t *l)
24 LIBNET_API uint32_t libnet_get_prand (int mod)
25 LIBNET_API int libnet_toggle_checksum (libnet_t *l, libnet_ptag_t ptag,
26 int mode)
27 LIBNET_API char * libnet_addr2name4 (uint32_t in, uint8_t use_name)
28 LIBNET_API uint32_t libnet_name2addr4 (libnet_t *l, const char
29 *host_name, uint8_t use_name)
30 LIBNET_API int libnet_in6_is_error (struct libnet_in6_addr addr)
31 LIBNET_API struct libnet_in6_addr libnet_name2addr6 (libnet_t *l, const
32 char *host_name, uint8_t use_name)
33 LIBNET_API void libnet_addr2name6_r (struct libnet_in6_addr addr,
34 uint8_t use_name, char *host_name, int host_name_len)
35 LIBNET_API int libnet_plist_chain_new (libnet_t *l, libnet_plist_t
36 **plist, char *token_list)
37 LIBNET_API int libnet_plist_chain_next_pair (libnet_plist_t *plist,
38 uint16_t *bport, uint16_t *eport)
39 LIBNET_API int libnet_plist_chain_dump (libnet_plist_t *plist)
40 LIBNET_API char * libnet_plist_chain_dump_string (libnet_plist_t
41 *plist)
42 LIBNET_API int libnet_plist_chain_free (libnet_plist_t *plist)
43 LIBNET_API libnet_ptag_t libnet_build_802_1q (const uint8_t *dst, const
44 uint8_t *src, uint16_t tpi, uint8_t priority, uint8_t cfi, uint16_t
45 vlan_id, uint16_t len_proto, const uint8_t *payload, uint32_t
46 payload_s, libnet_t *l, libnet_ptag_t ptag)
47 LIBNET_API libnet_ptag_t libnet_build_802_1x (uint8_t eap_ver, uint8_t
48 eap_type, uint16_t length, const uint8_t *payload, uint32_t
49 payload_s, libnet_t *l, libnet_ptag_t ptag)
50 LIBNET_API libnet_ptag_t libnet_build_802_2 (uint8_t dsap, uint8_t
51 ssap, uint8_t control, const uint8_t *payload, uint32_t payload_s,
52 libnet_t *l, libnet_ptag_t ptag)
53 LIBNET_API libnet_ptag_t libnet_build_802_2snap (uint8_t dsap, uint8_t
54 ssap, uint8_t control, uint8_t *oui, uint16_t type, const uint8_t
55 *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
56 LIBNET_API libnet_ptag_t libnet_build_802_3 (const uint8_t *dst, const
57 uint8_t *src, uint16_t len, const uint8_t *payload, uint32_t
58 payload_s, libnet_t *l, libnet_ptag_t ptag)
59 LIBNET_API libnet_ptag_t libnet_build_ethernet (const uint8_t *dst,
60 const uint8_t *src, uint16_t type, const uint8_t *payload, uint32_t
61 payload_s, libnet_t *l, libnet_ptag_t ptag)
62 LIBNET_API libnet_ptag_t libnet_autobuild_ethernet (const uint8_t *dst,
63 uint16_t type, libnet_t *l)
64 LIBNET_API libnet_ptag_t libnet_build_fddi (uint8_t fc, const uint8_t
65 *dst, const uint8_t *src, uint8_t dsap, uint8_t ssap, uint8_t cf,
66 const uint8_t *oui, uint16_t type, const uint8_t *payload, uint32_t
67 payload_s, libnet_t *l, libnet_ptag_t ptag)
68 LIBNET_API libnet_ptag_t libnet_autobuild_fddi (uint8_t fc, const
69 uint8_t *dst, uint8_t dsap, uint8_t ssap, uint8_t cf, const uint8_t
70 *oui, uint16_t type, libnet_t *l)
71 LIBNET_API libnet_ptag_t libnet_build_arp (uint16_t hrd, uint16_t pro,
72 uint8_t hln, uint8_t pln, uint16_t op, const uint8_t *sha, const
73 uint8_t *spa, const uint8_t *tha, const uint8_t *tpa, const uint8_t
74 *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
75 LIBNET_API libnet_ptag_t libnet_autobuild_arp (uint16_t op, const
76 uint8_t *sha, const uint8_t *spa, const uint8_t *tha, const uint8_t
77 *tpa, libnet_t *l)
78 LIBNET_API libnet_ptag_t libnet_build_tcp (uint16_t sp, uint16_t dp,
79 uint32_t seq, uint32_t ack, uint8_t control, uint16_t win, uint16_t
80 sum, uint16_t urg, uint16_t len, const uint8_t *payload, uint32_t
81 payload_s, libnet_t *l, libnet_ptag_t ptag)
82 LIBNET_API libnet_ptag_t libnet_build_tcp_options (const uint8_t
83 *options, uint32_t options_s, libnet_t *l, libnet_ptag_t ptag)
84 LIBNET_API libnet_ptag_t libnet_build_udp (uint16_t sp, uint16_t dp,
85 uint16_t len, uint16_t sum, const uint8_t *payload, uint32_t
86 payload_s, libnet_t *l, libnet_ptag_t ptag)
87 LIBNET_API libnet_ptag_t libnet_build_cdp (uint8_t version, uint8_t
88 ttl, uint16_t sum, uint16_t type, uint16_t value_s, const uint8_t
89 *value, const uint8_t *payload, uint32_t payload_s, libnet_t *l,
90 libnet_ptag_t ptag)
91 LIBNET_API libnet_ptag_t libnet_build_lldp_chassis (const uint8_t
92 subtype, const uint8_t *value, const uint8_t value_s, libnet_t *l,
93 libnet_ptag_t ptag)
94 LIBNET_API libnet_ptag_t libnet_build_lldp_port (const uint8_t subtype,
95 const uint8_t *value, const uint8_t value_s, libnet_t *l,
96 libnet_ptag_t ptag)
97 LIBNET_API libnet_ptag_t libnet_build_lldp_ttl (const uint16_t ttl,
98 libnet_t *l, libnet_ptag_t ptag)
99 LIBNET_API libnet_ptag_t libnet_build_lldp_end (libnet_t *l,
100 libnet_ptag_t ptag)
101 LIBNET_API libnet_ptag_t libnet_build_lldp_org_spec (const uint8_t
102 *value, const uint16_t value_s, libnet_t *l, libnet_ptag_t ptag)
103 LIBNET_API libnet_ptag_t libnet_build_icmpv4_echo (uint8_t type,
104 uint8_t code, uint16_t sum, uint16_t id, uint16_t seq, const
105 uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t
106 ptag)
107 LIBNET_API libnet_ptag_t libnet_build_icmpv4_mask (uint8_t type,
108 uint8_t code, uint16_t sum, uint16_t id, uint16_t seq, uint32_t
109 mask, const uint8_t *payload, uint32_t payload_s, libnet_t *l,
110 libnet_ptag_t ptag)
111 LIBNET_API libnet_ptag_t libnet_build_icmpv4_unreach (uint8_t type,
112 uint8_t code, uint16_t sum, const uint8_t *payload, uint32_t
113 payload_s, libnet_t *l, libnet_ptag_t ptag)
114 LIBNET_API libnet_ptag_t libnet_build_icmpv4_redirect (uint8_t type,
115 uint8_t code, uint16_t sum, uint32_t gateway, const uint8_t
116 *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
117 LIBNET_API libnet_ptag_t libnet_build_icmpv4_timeexceed (uint8_t type,
118 uint8_t code, uint16_t sum, const uint8_t *payload, uint32_t
119 payload_s, libnet_t *l, libnet_ptag_t ptag)
120 LIBNET_API libnet_ptag_t libnet_build_icmpv4_timestamp (uint8_t type,
121 uint8_t code, uint16_t sum, uint16_t id, uint16_t seq, uint32_t
122 otime, uint32_t rtime, uint32_t ttime, const uint8_t *payload,
123 uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
124 LIBNET_API libnet_ptag_t libnet_build_icmpv6_echo (uint8_t type,
125 uint8_t code, uint16_t sum, uint16_t id, uint16_t seq, uint8_t
126 *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
127 LIBNET_API libnet_ptag_t libnet_build_icmpv6_unreach (uint8_t type,
128 uint8_t code, uint16_t sum, uint8_t *payload, uint32_t payload_s,
129 libnet_t *l, libnet_ptag_t ptag)
130 LIBNET_API libnet_ptag_t libnet_build_icmpv6_ndp_nsol (uint8_t type,
131 uint8_t code, uint16_t sum, struct libnet_in6_addr target, uint8_t
132 *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
133 LIBNET_API libnet_ptag_t libnet_build_icmpv6_ndp_nadv (uint8_t type,
134 uint8_t code, uint16_t sum, uint32_t flags, struct libnet_in6_addr
135 target, uint8_t *payload, uint32_t payload_s, libnet_t *l,
136 libnet_ptag_t ptag)
137 LIBNET_API libnet_ptag_t libnet_build_icmpv6_ndp_opt (uint8_t type,
138 uint8_t *option, uint32_t option_s, libnet_t *l, libnet_ptag_t
139 ptag)
140 LIBNET_API libnet_ptag_t libnet_build_igmp (uint8_t type, uint8_t
141 reserved, uint16_t sum, uint32_t ip, const uint8_t *payload,
142 uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
143 LIBNET_API libnet_ptag_t libnet_build_ipv4 (uint16_t ip_len, uint8_t
144 tos, uint16_t id, uint16_t frag, uint8_t ttl, uint8_t prot,
145 uint16_t sum, uint32_t src, uint32_t dst, const uint8_t *payload,
146 uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
147 LIBNET_API libnet_ptag_t libnet_build_ipv4_options (const uint8_t
148 *options, uint32_t options_s, libnet_t *l, libnet_ptag_t ptag)
149 LIBNET_API libnet_ptag_t libnet_autobuild_ipv4 (uint16_t len, uint8_t
150 prot, uint32_t dst, libnet_t *l)
151 LIBNET_API libnet_ptag_t libnet_build_ipv6 (uint8_t tc, uint32_t fl,
152 uint16_t len, uint8_t nh, uint8_t hl, struct libnet_in6_addr src,
153 struct libnet_in6_addr dst, const uint8_t *payload, uint32_t
154 payload_s, libnet_t *l, libnet_ptag_t ptag)
155 LIBNET_API libnet_ptag_t libnet_build_ipv6_frag (uint8_t nh, uint8_t
156 reserved, uint16_t frag, uint32_t id, const uint8_t *payload,
157 uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
158 LIBNET_API libnet_ptag_t libnet_build_ipv6_routing (uint8_t nh, uint8_t
159 len, uint8_t rtype, uint8_t segments, const uint8_t *payload,
160 uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
161 LIBNET_API libnet_ptag_t libnet_build_ipv6_destopts (uint8_t nh,
162 uint8_t len, const uint8_t *payload, uint32_t payload_s, libnet_t
163 *l, libnet_ptag_t ptag)
164 LIBNET_API libnet_ptag_t libnet_build_ipv6_hbhopts (uint8_t nh, uint8_t
165 len, const uint8_t *payload, uint32_t payload_s, libnet_t *l,
166 libnet_ptag_t ptag)
167 LIBNET_API libnet_ptag_t libnet_autobuild_ipv6 (uint16_t len, uint8_t
168 nh, struct libnet_in6_addr dst, libnet_t *l, libnet_ptag_t ptag)
169 LIBNET_API libnet_ptag_t libnet_build_isl (uint8_t *dhost, uint8_t
170 type, uint8_t user, uint8_t *shost, uint16_t len, const uint8_t
171 *snap, uint16_t vid, uint16_t portindex, uint16_t reserved, const
172 uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t
173 ptag)
174 LIBNET_API libnet_ptag_t libnet_build_ipsec_esp_hdr (uint32_t spi,
175 uint32_t seq, uint32_t iv, const uint8_t *payload, uint32_t
176 payload_s, libnet_t *l, libnet_ptag_t ptag)
177 LIBNET_API libnet_ptag_t libnet_build_ipsec_esp_ftr (uint8_t len,
178 uint8_t nh, int8_t *auth, const uint8_t *payload, uint32_t
179 payload_s, libnet_t *l, libnet_ptag_t ptag)
180 LIBNET_API libnet_ptag_t libnet_build_ipsec_ah (uint8_t nh, uint8_t
181 len, uint16_t res, uint32_t spi, uint32_t seq, uint32_t auth, const
182 uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t
183 ptag)
184 LIBNET_API libnet_ptag_t libnet_build_dnsv4 (uint16_t h_len, uint16_t
185 id, uint16_t flags, uint16_t num_q, uint16_t num_anws_rr, uint16_t
186 num_auth_rr, uint16_t num_addi_rr, const uint8_t *payload, uint32_t
187 payload_s, libnet_t *l, libnet_ptag_t ptag)
188 LIBNET_API libnet_ptag_t libnet_build_rip (uint8_t cmd, uint8_t
189 version, uint16_t rd, uint16_t af, uint16_t rt, uint32_t addr,
190 uint32_t mask, uint32_t next_hop, uint32_t metric, const uint8_t
191 *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
192 LIBNET_API libnet_ptag_t libnet_build_rpc_call (uint32_t rm, uint32_t
193 xid, uint32_t prog_num, uint32_t prog_vers, uint32_t procedure,
194 uint32_t cflavor, uint32_t clength, uint8_t *cdata, uint32_t
195 vflavor, uint32_t vlength, const uint8_t *vdata, const uint8_t
196 *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
197 LIBNET_API libnet_ptag_t libnet_build_stp_conf (uint16_t id, uint8_t
198 version, uint8_t bpdu_type, uint8_t flags, const uint8_t *root_id,
199 uint32_t root_pc, const uint8_t *bridge_id, uint16_t port_id,
200 uint16_t message_age, uint16_t max_age, uint16_t hello_time,
201 uint16_t f_delay, const uint8_t *payload, uint32_t payload_s,
202 libnet_t *l, libnet_ptag_t ptag)
203 LIBNET_API libnet_ptag_t libnet_build_stp_tcn (uint16_t id, uint8_t
204 version, uint8_t bpdu_type, const uint8_t *payload, uint32_t
205 payload_s, libnet_t *l, libnet_ptag_t ptag)
206 LIBNET_API libnet_ptag_t libnet_build_udld_hdr (uint8_t version,
207 uint8_t opcode, uint8_t flags, uint8_t checksum, const uint8_t
208 *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
209 LIBNET_API libnet_ptag_t libnet_build_udld_device_id (const uint8_t
210 *value, const uint8_t value_s, libnet_t *l, libnet_ptag_t ptag)
211 LIBNET_API libnet_ptag_t libnet_build_udld_port_id (const uint8_t
212 *value, const uint8_t value_s, libnet_t *l, libnet_ptag_t ptag)
213 LIBNET_API libnet_ptag_t libnet_build_udld_echo (const uint8_t *value,
214 const uint8_t value_s, libnet_t *l, libnet_ptag_t ptag)
215 LIBNET_API libnet_ptag_t libnet_build_udld_message_interval (const
216 uint8_t *value, libnet_t *l, libnet_ptag_t ptag)
217 LIBNET_API libnet_ptag_t libnet_build_udld_timeout_interval (const
218 uint8_t *value, libnet_t *l, libnet_ptag_t ptag)
219 LIBNET_API libnet_ptag_t libnet_build_udld_device_name (const uint8_t
220 *value, const uint8_t value_s, libnet_t *l, libnet_ptag_t ptag)
221 LIBNET_API libnet_ptag_t libnet_build_udld_sequence_number (const
222 uint8_t *value, libnet_t *l, libnet_ptag_t ptag)
223 LIBNET_API libnet_ptag_t libnet_build_token_ring (uint8_t ac, uint8_t
224 fc, const uint8_t *dst, const uint8_t *src, uint8_t dsap, uint8_t
225 ssap, uint8_t cf, const uint8_t *oui, uint16_t type, const uint8_t
226 *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
227 LIBNET_API libnet_ptag_t libnet_autobuild_token_ring (uint8_t ac,
228 uint8_t fc, const uint8_t *dst, uint8_t dsap, uint8_t ssap, uint8_t
229 cf, const uint8_t *oui, uint16_t type, libnet_t *l)
230 LIBNET_API libnet_ptag_t libnet_build_vrrp (uint8_t version, uint8_t
231 type, uint8_t vrouter_id, uint8_t priority, uint8_t ip_count,
232 uint8_t auth_type, uint8_t advert_int, uint16_t sum, const uint8_t
233 *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
234 LIBNET_API libnet_ptag_t libnet_build_mpls (uint32_t label, uint8_t
235 experimental, uint8_t bos, uint8_t ttl, const uint8_t *payload,
236 uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
237 LIBNET_API libnet_ptag_t libnet_build_ntp (uint8_t leap_indicator,
238 uint8_t version, uint8_t mode, uint8_t stratum, uint8_t poll,
239 uint8_t precision, uint16_t delay_int, uint16_t delay_frac,
240 uint16_t dispersion_int, uint16_t dispersion_frac, uint32_t
241 reference_id, uint32_t ref_ts_int, uint32_t ref_ts_frac, uint32_t
242 orig_ts_int, uint32_t orig_ts_frac, uint32_t rec_ts_int, uint32_t
243 rec_ts_frac, uint32_t xmt_ts_int, uint32_t xmt_ts_frac, const
244 uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t
245 ptag)
246 LIBNET_API libnet_ptag_t libnet_build_ospfv2 (uint16_t len, uint8_t
247 type, uint32_t rtr_id, uint32_t area_id, uint16_t sum, uint16_t
248 autype, const uint8_t *payload, uint32_t payload_s, libnet_t *l,
249 libnet_ptag_t ptag)
250 LIBNET_API libnet_ptag_t libnet_build_ospfv2_hello (uint32_t netmask,
251 uint16_t interval, uint8_t opts, uint8_t priority, uint32_t
252 dead_int, uint32_t des_rtr, uint32_t bkup_rtr, const uint8_t
253 *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
254 libnet_ptag_t libnet_build_ospfv2_hello_neighbor (uint32_t netmask,
255 uint16_t interval, uint8_t opts, uint8_t priority, uint32_t
256 dead_int, uint32_t des_rtr, uint32_t bkup_rtr, uint32_t neighbor,
257 const uint8_t *payload, uint32_t payload_s, libnet_t *l,
258 libnet_ptag_t ptag)
259 LIBNET_API libnet_ptag_t libnet_build_ospfv2_dbd (uint16_t dgram_len,
260 uint8_t opts, uint8_t type, uint32_t seqnum, const uint8_t
261 *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
262 LIBNET_API libnet_ptag_t libnet_build_ospfv2_lsr (uint32_t type,
263 uint32_t lsid, uint32_t advrtr, const uint8_t *payload, uint32_t
264 payload_s, libnet_t *l, libnet_ptag_t ptag)
265 LIBNET_API libnet_ptag_t libnet_build_ospfv2_lsu (uint32_t num, const
266 uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t
267 ptag)
268 LIBNET_API libnet_ptag_t libnet_build_ospfv2_lsa (uint16_t age, uint8_t
269 opts, uint8_t type, uint32_t lsid, uint32_t advrtr, uint32_t
270 seqnum, uint16_t sum, uint16_t len, const uint8_t *payload,
271 uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
272 LIBNET_API libnet_ptag_t libnet_build_ospfv2_lsa_rtr (uint16_t flags,
273 uint16_t num, uint32_t id, uint32_t data, uint8_t type, uint8_t
274 tos, uint16_t metric, const uint8_t *payload, uint32_t payload_s,
275 libnet_t *l, libnet_ptag_t ptag)
276 LIBNET_API libnet_ptag_t libnet_build_ospfv2_lsa_net (uint32_t nmask,
277 uint32_t rtrid, const uint8_t *payload, uint32_t payload_s,
278 libnet_t *l, libnet_ptag_t ptag)
279 LIBNET_API libnet_ptag_t libnet_build_ospfv2_lsa_sum (uint32_t nmask,
280 uint32_t metric, uint32_t tos, const uint8_t *payload, uint32_t
281 payload_s, libnet_t *l, libnet_ptag_t ptag)
282 LIBNET_API libnet_ptag_t libnet_build_ospfv2_lsa_as (uint32_t nmask,
283 uint32_t metric, uint32_t fwdaddr, uint32_t tag, const uint8_t
284 *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
285 LIBNET_API libnet_ptag_t libnet_build_data (const uint8_t *payload,
286 uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
287 LIBNET_API libnet_ptag_t libnet_build_dhcpv4 (uint8_t opcode, uint8_t
288 htype, uint8_t hlen, uint8_t hopcount, uint32_t xid, uint16_t secs,
289 uint16_t flags, uint32_t cip, uint32_t yip, uint32_t sip, uint32_t
290 gip, const uint8_t *chaddr, const char *sname, const char *file,
291 const uint8_t *payload, uint32_t payload_s, libnet_t *l,
292 libnet_ptag_t ptag)
293 LIBNET_API libnet_ptag_t libnet_build_bootpv4 (uint8_t opcode, uint8_t
294 htype, uint8_t hlen, uint8_t hopcount, uint32_t xid, uint16_t secs,
295 uint16_t flags, uint32_t cip, uint32_t yip, uint32_t sip, uint32_t
296 gip, const uint8_t *chaddr, const char *sname, const char *file,
297 const uint8_t *payload, uint32_t payload_s, libnet_t *l,
298 libnet_ptag_t ptag)
299 LIBNET_API uint32_t libnet_getgre_length (uint16_t fv)
300 LIBNET_API libnet_ptag_t libnet_build_gre (uint16_t fv, uint16_t type,
301 uint16_t sum, uint16_t offset, uint32_t key, uint32_t seq, uint16_t
302 len, const uint8_t *payload, uint32_t payload_s, libnet_t *l,
303 libnet_ptag_t ptag)
304 LIBNET_API libnet_ptag_t libnet_build_egre (uint16_t fv, uint16_t type,
305 uint16_t sum, uint16_t offset, uint32_t key, uint32_t seq, uint16_t
306 len, const uint8_t *payload, uint32_t payload_s, libnet_t *l,
307 libnet_ptag_t ptag)
308 LIBNET_API libnet_ptag_t libnet_build_gre_sre (uint16_t af, uint8_t
309 offset, uint8_t length, uint8_t *routing, const uint8_t *payload,
310 uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
311 LIBNET_API libnet_ptag_t libnet_build_gre_last_sre (libnet_t *l,
312 libnet_ptag_t ptag)
313 LIBNET_API libnet_ptag_t libnet_build_bgp4_header (uint8_t
314 marker[LIBNET_BGP4_MARKER_SIZE], uint16_t len, uint8_t type, const
315 uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t
316 ptag)
317 LIBNET_API libnet_ptag_t libnet_build_bgp4_open (uint8_t version,
318 uint16_t src_as, uint16_t hold_time, uint32_t bgp_id, uint8_t
319 opt_len, const uint8_t *payload, uint32_t payload_s, libnet_t *l,
320 libnet_ptag_t ptag)
321 LIBNET_API libnet_ptag_t libnet_build_bgp4_update (uint16_t
322 unfeasible_rt_len, const uint8_t *withdrawn_rt, uint16_t
323 total_path_attr_len, const uint8_t *path_attributes, uint16_t
324 info_len, uint8_t *reachability_info, const uint8_t *payload,
325 uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
326 LIBNET_API libnet_ptag_t libnet_build_bgp4_notification (uint8_t
327 err_code, uint8_t err_subcode, const uint8_t *payload, uint32_t
328 payload_s, libnet_t *l, libnet_ptag_t ptag)
329 LIBNET_API libnet_ptag_t libnet_build_sebek (uint32_t magic, uint16_t
330 version, uint16_t type, uint32_t counter, uint32_t time_sec,
331 uint32_t time_usec, uint32_t pid, uint32_t uid, uint32_t fd,
332 uint8_t cmd[SEBEK_CMD_LENGTH], uint32_t length, const uint8_t
333 *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
334 LIBNET_API libnet_ptag_t libnet_build_hsrp (uint8_t version, uint8_t
335 opcode, uint8_t state, uint8_t hello_time, uint8_t hold_time,
336 uint8_t priority, uint8_t group, uint8_t reserved, uint8_t
337 authdata[HSRP_AUTHDATA_LENGTH], uint32_t virtual_ip, const uint8_t
338 *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
339 LIBNET_API libnet_ptag_t libnet_build_link (const uint8_t *dst, const
340 uint8_t *src, const uint8_t *oui, uint16_t type, const uint8_t
341 *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
342 LIBNET_API libnet_ptag_t libnet_autobuild_link (const uint8_t *dst,
343 const uint8_t *oui, uint16_t type, libnet_t *l)
344 LIBNET_API int libnet_write (libnet_t *l)
345 LIBNET_API uint32_t libnet_get_ipaddr4 (libnet_t *l)
346 LIBNET_API struct libnet_in6_addr libnet_get_ipaddr6 (libnet_t *l)
347 LIBNET_API struct libnet_ether_addr * libnet_get_hwaddr (libnet_t *l)
348 LIBNET_API uint8_t * libnet_hex_aton (const char *s, int *len)
349 LIBNET_API const char * libnet_version (void)
350 LIBNET_API int libnet_adv_cull_packet (libnet_t *l, uint8_t **packet,
351 uint32_t *packet_s)
352 LIBNET_API int libnet_adv_cull_header (libnet_t *l, libnet_ptag_t ptag,
353 uint8_t **header, uint32_t *header_s)
354 LIBNET_API int libnet_adv_write_link (libnet_t *l, const uint8_t
355 *packet, uint32_t packet_s)
356 LIBNET_API int libnet_adv_write_raw_ipv4 (libnet_t *l, const uint8_t
357 *packet, uint32_t packet_s)
358 LIBNET_API void libnet_adv_free_packet (libnet_t *l, uint8_t *packet)
359 int libnet_cq_add (libnet_t *l, char *label)
360 LIBNET_API libnet_t * libnet_cq_remove (libnet_t *l)
361 LIBNET_API libnet_t * libnet_cq_remove_by_label (char *label)
362 LIBNET_API const char * libnet_cq_getlabel (libnet_t *l)
363 LIBNET_API libnet_t * libnet_cq_find_by_label (char *label)
364 LIBNET_API void libnet_cq_destroy (void)
365 LIBNET_API libnet_t * libnet_cq_head (void)
366 LIBNET_API int libnet_cq_last (void)
367 LIBNET_API libnet_t * libnet_cq_next (void)
368 LIBNET_API uint32_t libnet_cq_size (void)
369 LIBNET_API uint32_t libnet_cq_end_loop (void)
370 LIBNET_API void libnet_diag_dump_context (libnet_t *l)
371 LIBNET_API void libnet_diag_dump_pblock (libnet_t *l)
372 LIBNET_API char * libnet_diag_dump_pblock_type (uint8_t type)
373 void libnet_diag_dump_hex (const uint8_t *packet, uint32_t len, int
374 swap, FILE *stream)
375
377 libnet exported function prototypes
378
379
380
382 LIBNET_API char * libnet_addr2name4 (uint32_t in, uint8_t use_name)
383 Takes a network byte ordered IPv4 address and returns a pointer to
384 either a canonical DNS name (if it has one) or a string of dotted
385 decimals. This may incur a DNS lookup if the hostname and mode is set
386 to LIBNET_RESOLVE. If mode is set to LIBNET_DONT_RESOLVE, no DNS lookup
387 will be performed and the function will return a pointer to a dotted
388 decimal string. The function cannot fail -- if no canonical name
389 exists, it will fall back on returning a dotted decimal string. This
390 function is non-reentrant.
391
392 Parameters
393 in network byte ordered IPv4 address
394 use_name LIBNET_RESOLVE or LIBNET_DONT_RESOLVE
395
396 Returns
397 a pointer to presentation format string
398
399 LIBNET_API void libnet_addr2name6_r (struct libnet_in6_addr addr, uint8_t
400 use_name, char * host_name, int host_name_len)
401 Translate an IPv6 address to a canonical DNS name or hexadecimal
402 string.
403
404 This may incur a DNS lookup if the mode is set to LIBNET_RESOLVE. If
405 mode is set to LIBNET_DONT_RESOLVE, no DNS lookup will be performed.
406 The function cannot fail -- if no canonical name exists, it will fall
407 back to the hexadecimal string representation.
408
409 This function is reentrant.
410
411 Parameters
412 addr address to convert
413 use_name LIBNET_RESOLVE or LIBNET_DONT_RESOLVE
414 host_name Buffer to return result in
415 host_name_len Length of host_name buffer
416
417 LIBNET_API int libnet_adv_cull_header (libnet_t * l, libnet_ptag_t ptag,
418 uint8_t ** header, uint32_t * header_s)
419 [Advanced Interface] Pulls the header from the specified ptag from the
420 given libnet context. This function is part of the advanced interface
421 and is only available when libnet is initialized in advanced mode. If
422 the function fails libnet_geterror() can tell you why.
423
424 Parameters
425 l pointer to a libnet context
426 ptag the ptag referencing the header to pull
427 header will contain the header
428 header_s will contain the header size
429
430 Return values
431 1 on success
432 -1 on failure
433
434
435 LIBNET_API int libnet_adv_cull_packet (libnet_t * l, uint8_t ** packet,
436 uint32_t * packet_s)
437 [Advanced Interface] Yanks a prebuilt, wire-ready packet from the given
438 libnet context. If libnet was configured to do so (which it is by
439 default) the packet will have all checksums written in. This function
440 is part of the advanced interface and is only available when libnet is
441 initialized in advanced mode. It is important to note that the function
442 performs an implicit malloc() and a corresponding call to
443 libnet_adv_free_packet() should be made to free the memory packet
444 occupies. If the function fails libnet_geterror() can tell you why.
445
446 Parameters
447 l pointer to a libnet context
448 packet will contain the wire-ready packet
449 packet_s will contain the packet size
450
451 Return values
452 1 on success
453 -1 on failure
454
455
456 LIBNET_API void libnet_adv_free_packet (libnet_t * l, uint8_t * packet)
457 [Advanced Interface] Frees the memory allocated when
458 libnet_adv_cull_packet() is called.
459
460 Parameters
461 l pointer to a libnet context
462 packet a pointer to the packet to free
463
464 LIBNET_API int libnet_adv_write_link (libnet_t * l, const uint8_t * packet,
465 uint32_t packet_s)
466 [Advanced Interface] Writes a packet the network at the link layer.
467 This function is useful to write a packet that has been constructed by
468 hand by the application programmer or, more commonly, to write a packet
469 that has been returned by a call to libnet_adv_cull_packet(). This
470 function is part of the advanced interface and is only available when
471 libnet is initialized in advanced mode. If the function fails
472 libnet_geterror() can tell you why.
473
474 Parameters
475 l pointer to a libnet context
476 packet a pointer to the packet to inject
477 packet_s the size of the packet
478
479 Returns
480 the number of bytes written
481
482 Return values
483 -1 on failure
484
485 LIBNET_API int libnet_adv_write_raw_ipv4 (libnet_t * l, const uint8_t *
486 packet, uint32_t packet_s)
487 [Advanced Interface] Writes a packet the network at the raw socket
488 layer. This function is useful to write a packet that has been
489 constructed by hand by the application programmer or, more commonly, to
490 write a packet that has been returned by a call to
491 libnet_adv_cull_packet(). This function is part of the advanced
492 interface and is only available when libnet is initialized in advanced
493 mode. If the function fails libnet_geterror() can tell you why.
494
495 Parameters
496 l pointer to a libnet context
497 packet a pointer to the packet to inject
498 packet_s the size of the packet
499
500 Returns
501 the number of bytes written
502
503 Return values
504 -1 on failure
505
506 LIBNET_API libnet_ptag_t libnet_autobuild_arp (uint16_t op, const uint8_t *
507 sha, const uint8_t * spa, const uint8_t * tha, const uint8_t * tpa,
508 libnet_t * l)
509 Autouilds an Address Resolution Protocol (ARP) header. Depending on the
510 op value, the function builds one of several different types of RFC 826
511 or RFC 903 RARP packets.
512
513 Parameters
514 op ARP operation type
515 sha sender's hardware address
516 spa sender's protocol address
517 tha target hardware address
518 tpa target protocol address
519 l pointer to a libnet context
520
521 Returns
522 protocol tag value on success
523
524 Return values
525 -1 on error
526
527 LIBNET_API libnet_ptag_t libnet_autobuild_ethernet (const uint8_t * dst,
528 uint16_t type, libnet_t * l)
529 Autobuilds an Ethernet header. The RFC 894 Ethernet II header is almost
530 identical to the IEEE 802.3 header, with the exception that the field
531 immediately following the source address holds the layer 3 protocol (as
532 opposed to frame's length). You should only use this function when
533 libnet is initialized with the LIBNET_LINK interface.
534
535 Parameters
536 dst destination ethernet address
537 type upper layer protocol type
538 l pointer to a libnet context
539
540 Returns
541 protocol tag value on success
542
543 Return values
544 -1 on error
545
546 LIBNET_API libnet_ptag_t libnet_autobuild_fddi (uint8_t fc, const uint8_t *
547 dst, uint8_t dsap, uint8_t ssap, uint8_t cf, const uint8_t * oui,
548 uint16_t type, libnet_t * l)
549 Autobuilds a Fiber Distributed Data Interface (FDDI) header.
550
551 Parameters
552 fc class format and priority
553 dst destination fddi address
554 dsap destination service access point
555 ssap source service access point
556 cf cf
557 oui IEEE organizational code
558 type upper layer protocol
559 l pointer to a libnet context
560
561 Returns
562 protocol tag value on success
563
564 Return values
565 -1 on error
566
567 LIBNET_API libnet_ptag_t libnet_autobuild_ipv4 (uint16_t len, uint8_t prot,
568 uint32_t dst, libnet_t * l)
569 Autobuilds a version 4 Internet Protocol (IP) header. The function is
570 useful to build an IP header quickly when you do not need a granular
571 level of control. The function takes the same len, prot, and dst
572 arguments as libnet_build_ipv4(). The function does not accept a ptag
573 argument, but it does return a ptag. In other words, you can use it to
574 build a new IP header but not to modify an existing one.
575
576 Parameters
577 len total length of the IP packet including all subsequent data
578 prot upper layer protocol
579 dst destination IPv4 address (little endian)
580 l pointer to a libnet context
581
582 Returns
583 protocol tag value on success
584
585 Return values
586 -1 on error
587
588 LIBNET_API libnet_ptag_t libnet_autobuild_ipv6 (uint16_t len, uint8_t nh,
589 struct libnet_in6_addr dst, libnet_t * l, libnet_ptag_t ptag)
590 Autobuilds a version 6 RFC 2460 Internet Protocol (IP) header. The
591 function is useful to build an IP header quickly when you do not need a
592 granular level of control. The function takes the same len, nh, and dst
593 arguments as libnet_build_ipv4(). The function does not accept a ptag
594 argument, but it does return a ptag. In other words, you can use it to
595 build a new IP header but not to modify an existing one. This function
596 requires libnet_get_ipaddr6(), which is not yet implemented for Win32
597 platforms.
598
599 Parameters
600 len length
601 nh next header
602 dst destination IPv6 address
603 l pointer to a libnet context
604 ptag protocol tag to modify an existing header, 0 to build a new
605 one
606
607 Returns
608 protocol tag value on success
609
610 Return values
611 -1 on error
612
613 LIBNET_API libnet_ptag_t libnet_autobuild_link (const uint8_t * dst, const
614 uint8_t * oui, uint16_t type, libnet_t * l)
615 Automatically builds a link layer header for an initialized l. The
616 function determines the proper link layer header format from how l was
617 initialized. The function current supports Ethernet and Token Ring link
618 layers.
619
620 Parameters
621 dst the destination MAC address
622 oui Organizationally Unique Identifier (unused for Ethernet)
623 type the upper layer protocol type
624 l pointer to a libnet context
625
626 Returns
627 protocol tag value on success
628
629 Return values
630 -1 on error
631
632 LIBNET_API libnet_ptag_t libnet_autobuild_token_ring (uint8_t ac, uint8_t
633 fc, const uint8_t * dst, uint8_t dsap, uint8_t ssap, uint8_t cf, const
634 uint8_t * oui, uint16_t type, libnet_t * l)
635 Auto-builds a token ring header.
636
637 Parameters
638 ac access control
639 fc frame control
640 dst destination address
641 dsap destination service access point
642 ssap source service access point
643 cf control field
644 oui Organizationally Unique Identifier
645 type upper layer protocol type
646 l pointer to a libnet context
647
648 Returns
649 protocol tag value on success
650
651 Return values
652 -1 on error
653
654 LIBNET_API libnet_ptag_t libnet_build_802_1q (const uint8_t * dst, const
655 uint8_t * src, uint16_t tpi, uint8_t priority, uint8_t cfi, uint16_t
656 vlan_id, uint16_t len_proto, const uint8_t * payload, uint32_t
657 payload_s, libnet_t * l, libnet_ptag_t ptag)
659 The core of libnet is the platform-independent packet-building
660 functionality. These functions enable an application programmer to
661 build protocol headers (and data) in a simple and consistent manner
662 without having to worry (too much) about low-level network odds and
663 ends. Each libnet_build() function builds a piece of a packet
664 (generally a protocol header). While it is perfectly possible to build
665 an entire, ready-to-transmit packet with a single call to a
666 libnet_build() function, generally more than one builder-class function
667 call is required to construct a full packet. A complete wire-ready
668 packet generally consists of more than one piece. Every function that
669 builds a protocol header takes a series of arguments roughly
670 corresponding to the header values as they appear on the wire. This
671 process is intuitive but often makes for functions with huge prototypes
672 and large stack frames. One important thing to note is that you must
673 call these functions in order, corresponding to how they should appear
674 on the wire (from the highest protocol layer on down). This building
675 process is intuitive; it approximates what happens in an operating
676 system kernel. In other words, to build a Network Time Protocol (NTP)
677 packet by using the link-layer interface, the application programmer
678 would call the libnet_build() functions in the following order:
679
680 1. libnet_build_ntp()
681
682 2. libnet_build_udp()
683
684 3. libnet_build_ipv4()
685
686 4. libnet_build_ethernet() This ordering is essential for libnet 1.1.x
687 to properly link together the packet internally (previous libnet
688 versions did not have the requirement).
689
690 The Payload Interface
691 The payload interface specifies an optional way to include data
692 directly after the protocol header in question. You can use this
693 function for a variety of purposes, including the following:
694
695 • Including additional or arbitrary protocol header information that is
696 not available from a libnet interface
697
698 • Including a packet payload (data segment)
699
700 • Building another protocol header that is not available from a libnet
701 interface To employ the interface, the application programmer should
702 construct the i payload data and pass a const uint8_t * to this data
703 and its size to the desired libnet_build() function. Libnet handles
704 the rest.
705
706 It is important to note that some functions (notably the IPv6 builders)
707 do use the payload interface to specify variable length but ostensibly
708 non-optional data. See the individual libnet_build_ipv6*() functions
709 for more information.
710
711 Protocol Tags and Packet Builder Return Values
712 Libnet uses the protocol tag (ptag) to identify individual pieces of a
713 packet after being created. A new ptag results every time a
714 libnet_build() function with an empty (0) ptag argument completes
715 successfully. This new ptag now refers to the packet piece just
716 created. The application programmer's responsibility is to save this
717 value if he or she plans to modify this particular portion later on in
718 the program. If the application programmer needs to modify some portion
719 of that particular packet piece again, he or she calls the same
720 libnet_build() function specifying the saved ptag argument. Libnet then
721 searches for that packet piece and modifies it rather than creating a
722 new one. Upon failure for any reason, libnet_build() functions return
723 -1; libnet_geterror() tells you why. Builds an IEEE 802.1q VLAN tagging
724 header. Depending on the value of len_proto, the function wraps the
725 802.1q header inside either an IEEE 802.3 header or an RFC 894 Ethernet
726 II (DIX) header (both resulting in an 18-byte frame). If len is 1500 or
727 less, most receiving protocol stacks parse the frame as an IEEE 802.3
728 encapsulated frame. If len is one of the Ethernet type values, most
729 protocol stacks parse the frame as an RFC 894 Ethernet II encapsulated
730 frame. Note the length value is calculated without the 802.1q header of
731 18 bytes.
732
733 Parameters
734 dst pointer to a six byte source ethernet address
735 src pointer to a six byte destination ethernet address
736 tpi tag protocol identifier
737 priority priority
738 cfi canonical format indicator
739 vlan_id vlan identifier
740 len_proto length (802.3) protocol (Ethernet II)
741 payload optional payload or NULL
742 payload_s payload length or 0
743 l pointer to a libnet context
744 ptag protocol tag to modify an existing header, 0 to build a new
745 one
746
747 Returns
748 protocol tag value on success
749
750 Return values
751 -1 on error
752
753 LIBNET_API libnet_ptag_t libnet_build_802_1x (uint8_t eap_ver, uint8_t
754 eap_type, uint16_t length, const uint8_t * payload, uint32_t payload_s,
755 libnet_t * l, libnet_ptag_t ptag)
756 Builds an IEEE 802.1x extended authentication protocol header.
757
758 Parameters
759 eap_ver the EAP version
760 eap_type the EAP type
761 length frame length
762 payload optional payload or NULL
763 payload_s payload length or 0
764 l pointer to a libnet context
765 ptag protocol tag to modify an existing header, 0 to build a new
766 one
767
768 Returns
769 protocol tag value on success
770
771 Return values
772 -1 on error
773
774 LIBNET_API libnet_ptag_t libnet_build_802_2 (uint8_t dsap, uint8_t ssap,
775 uint8_t control, const uint8_t * payload, uint32_t payload_s, libnet_t
776 * l, libnet_ptag_t ptag)
777 Builds an IEEE 802.2 LLC header.
778
779 Parameters
780 dsap destination service access point
781 ssap source service access point
782 control control field
783 payload optional payload or NULL
784 payload_s payload length or 0
785 l pointer to a libnet context
786 ptag protocol tag to modify an existing header, 0 to build a new
787 one
788
789 Returns
790 protocol tag value on success
791
792 Return values
793 -1 on error
794
795 LIBNET_API libnet_ptag_t libnet_build_802_2snap (uint8_t dsap, uint8_t
796 ssap, uint8_t control, uint8_t * oui, uint16_t type, const uint8_t *
797 payload, uint32_t payload_s, libnet_t * l, libnet_ptag_t ptag)
798 Builds an IEEE 802.2 LLC SNAP header.
799
800 Parameters
801 dsap destination service access point
802 ssap source service access point
803 control control field
804 oui Organizationally Unique Identifier
805 type upper layer protocol
806 payload optional payload or NULL
807 payload_s payload length or 0
808 l pointer to a libnet context
809 ptag protocol tag to modify an existing header, 0 to build a new
810 one
811
812 Returns
813 protocol tag value on success
814
815 Return values
816 -1 on error
817
818 LIBNET_API libnet_ptag_t libnet_build_802_3 (const uint8_t * dst, const
819 uint8_t * src, uint16_t len, const uint8_t * payload, uint32_t
820 payload_s, libnet_t * l, libnet_ptag_t ptag)
821 Builds an IEEE 802.3 header. The 802.3 header is almost identical to
822 the RFC 894 Ethernet II header, the exception being that the field
823 immediately following the source address holds the frame's length (as
824 opposed to the layer 3 protocol). You should only use this function
825 when libnet is initialized with the LIBNET_LINK interface.
826
827 Parameters
828 dst destination ethernet address
829 src source ethernet address
830 len frame length sans header
831 payload optional payload or NULL
832 payload_s payload length or 0
833 l pointer to a libnet context
834 ptag protocol tag to modify an existing header, 0 to build a new
835 one
836
837 Returns
838 protocol tag value on success
839
840 Return values
841 -1 on error
842
843 LIBNET_API libnet_ptag_t libnet_build_arp (uint16_t hrd, uint16_t pro,
844 uint8_t hln, uint8_t pln, uint16_t op, const uint8_t * sha, const
845 uint8_t * spa, const uint8_t * tha, const uint8_t * tpa, const uint8_t
846 * payload, uint32_t payload_s, libnet_t * l, libnet_ptag_t ptag)
847 Builds an Address Resolution Protocol (ARP) header. Depending on the op
848 value, the function builds one of several different types of RFC 826 or
849 RFC 903 RARP packets.
850
851 Parameters
852 hrd hardware address format
853 pro protocol address format
854 hln hardware address length
855 pln protocol address length
856 op ARP operation type
857 sha sender's hardware address
858 spa sender's protocol address
859 tha target hardware address
860 tpa target protocol address
861 payload optional payload or NULL
862 payload_s payload length or 0
863 l pointer to a libnet context
864 ptag protocol tag to modify an existing header, 0 to build a new
865 one
866
867 Returns
868 protocol tag value on success
869
870 Return values
871 -1 on error
872
873 LIBNET_API libnet_ptag_t libnet_build_bgp4_header (uint8_t
874 marker[LIBNET_BGP4_MARKER_SIZE], uint16_t len, uint8_t type, const
875 uint8_t * payload, uint32_t payload_s, libnet_t * l, libnet_ptag_t
876 ptag)
877 Builds an RFC 1771 Border Gateway Protocol 4 (BGP-4) header. The
878 primary function of a BGP speaking system is to exchange network
879 reachability information with other BGP systems. This network
880 reachability information includes information on the list of Autonomous
881 Systems (ASs) that reachability information traverses. This information
882 is sufficient to construct a graph of AS connectivity from which
883 routing loops may be pruned and some policy decisions at the AS level
884 may be enforced. This function builds the base BGP header which is used
885 as a preamble before any other BGP header. For example, a BGP KEEPALIVE
886 message may be built with only this function, while an error
887 notification requires a subsequent call to
888 libnet_build_bgp4_notification.
889
890 Parameters
891 marker a value the receiver can predict (if the message type is not
892 BGP OPEN, or no authentication is used, these 16 bytes are normally
893 set as all ones)
894 len total length of the BGP message, including the header
895 type type code of the message (OPEN, UPDATE, NOTIFICATION or
896 KEEPALIVE)
897 payload optional payload or NULL
898 payload_s payload length or 0
899 l pointer to a libnet context
900 ptag protocol tag to modify an existing header, 0 to build a new
901 one
902
903 Returns
904 protocol tag value on success
905
906 Return values
907 -1 on error
908
909 LIBNET_API libnet_ptag_t libnet_build_bgp4_notification (uint8_t err_code,
910 uint8_t err_subcode, const uint8_t * payload, uint32_t payload_s,
911 libnet_t * l, libnet_ptag_t ptag)
912 Builds an RFC 1771 Border Gateway Protocol 4 (BGP-4) notification
913 header. A NOTIFICATION message is sent when an error condition is
914 detected. Specific error information may be passed through the payload
915 interface.
916
917 Parameters
918 err_code type of notification
919 err_subcode more specific information about the reported error.
920 payload optional payload or NULL
921 payload_s payload length or 0
922 l pointer to a libnet context
923 ptag protocol tag to modify an existing header, 0 to build a new
924 one
925
926 Returns
927 protocol tag value on success
928
929 Return values
930 -1 on error
931
932 LIBNET_API libnet_ptag_t libnet_build_bgp4_open (uint8_t version, uint16_t
933 src_as, uint16_t hold_time, uint32_t bgp_id, uint8_t opt_len, const
934 uint8_t * payload, uint32_t payload_s, libnet_t * l, libnet_ptag_t
935 ptag)
936 Builds an RFC 1771 Border Gateway Protocol 4 (BGP-4) OPEN header. This
937 is the first message sent by each side of a BGP connection. The
938 optional parameters options should be constructed using the payload
939 interface (see RFC 1771 for the options structures).
940
941 Parameters
942 version protocol version (should be set to 4)
943 src_as Autonomous System of the sender
944 hold_time used to compute the maximum allowed time between the
945 receipt of KEEPALIVE, and/or UPDATE messages by the sender
946 bgp_id BGP identifier of the sender
947 opt_len total length of the optional parameters field in bytes
948 payload optional payload or NULL
949 payload_s payload length or 0
950 l pointer to a libnet context
951 ptag protocol tag to modify an existing header, 0 to build a new
952 one
953
954 Returns
955 protocol tag value on success
956
957 Return values
958 -1 on error
959
960 LIBNET_API libnet_ptag_t libnet_build_bgp4_update (uint16_t
961 unfeasible_rt_len, const uint8_t * withdrawn_rt, uint16_t
962 total_path_attr_len, const uint8_t * path_attributes, uint16_t
963 info_len, uint8_t * reachability_info, const uint8_t * payload,
964 uint32_t payload_s, libnet_t * l, libnet_ptag_t ptag)
965 Builds an RFC 1771 Border Gateway Protocol 4 (BGP-4) update header.
966 Update messages are used to transfer routing information between BGP
967 peers.
968
969 Parameters
970 unfeasible_rt_len indicates the length of the (next) 'withdrawn
971 routes' field in bytes
972 withdrawn_rt list of IP addresses prefixes for the routes that are
973 being withdrawn; each IP address prefix is built as a 2-tuple
974 <length (1 byte), prefix (variable)>
975 total_path_attr_len indicates the length of the (next) 'path
976 attributes' field in bytes
977 path_attributes each attribute is a 3-tuple <type (2 bytes),
978 length, value>
979 info_len indicates the length of the (next) 'network layer
980 reachability information' field in bytes (needed for internal
981 memory size calculation)
982 reachability_info 2-tuples <length (1 byte), prefix (variable)>.
983 payload optional payload or NULL
984 payload_s payload length or 0
985 l pointer to a libnet context
986 ptag protocol tag to modify an existing header, 0 to build a new
987 one
988
989 Returns
990 protocol tag value on success
991
992 Return values
993 -1 on error
994
995 LIBNET_API libnet_ptag_t libnet_build_bootpv4 (uint8_t opcode, uint8_t
996 htype, uint8_t hlen, uint8_t hopcount, uint32_t xid, uint16_t secs,
997 uint16_t flags, uint32_t cip, uint32_t yip, uint32_t sip, uint32_t gip,
998 const uint8_t * chaddr, const char * sname, const char * file, const
999 uint8_t * payload, uint32_t payload_s, libnet_t * l, libnet_ptag_t
1000 ptag)
1001 Parameters
1002 opcode
1003 htype
1004 hlen
1005 hopcount
1006 xid
1007 secs
1008 flags
1009 cip
1010 yip
1011 sip
1012 gip
1013 chaddr client hardware address, length is hlen
1014 sname server host name, a null terminated string
1015 file boot file name, a null terminated string
1016 payload optional payload or NULL
1017 payload_s payload length or 0
1018 l pointer to a libnet context
1019 ptag protocol tag to modify an existing header, 0 to build a new
1020 one
1021
1022 Returns
1023 protocol tag value on success
1024
1025 Return values
1026 -1 on error
1027
1028 LIBNET_API libnet_ptag_t libnet_build_cdp (uint8_t version, uint8_t ttl,
1029 uint16_t sum, uint16_t type, uint16_t value_s, const uint8_t * value,
1030 const uint8_t * payload, uint32_t payload_s, libnet_t * l,
1031 libnet_ptag_t ptag)
1032 Builds a Cisco Discovery Protocol (CDP) header. Cisco Systems designed
1033 CDP to aid in the network management of adjacent Cisco devices. The CDP
1034 protocol specifies data by using a type/length/value (TLV) setup. The
1035 first TLV can specified by using the functions type, length, and value
1036 arguments. To specify additional TLVs, the programmer could either use
1037 the payload interface or libnet_build_data() to construct them.
1038
1039 Parameters
1040 version CDP version
1041 ttl time to live (time information should be cached by recipient)
1042 sum checksum (0 for libnet to auto-fill)
1043 type type of data contained in value
1044 value_s length of value argument
1045 value the CDP information string
1046 payload optional payload or NULL
1047 payload_s payload length or 0
1048 l pointer to a libnet context
1049 ptag protocol tag to modify an existing header, 0 to build a new
1050 one
1051
1052 Returns
1053 protocol tag value on success
1054
1055 Return values
1056 -1 on error
1057
1058 LIBNET_API libnet_ptag_t libnet_build_data (const uint8_t * payload,
1059 uint32_t payload_s, libnet_t * l, libnet_ptag_t ptag)
1060 Builds a generic libnet protocol header. This is useful for including
1061 an optional payload to a packet that might need to change repeatedly
1062 inside of a loop. This won't work for TCP or IP payload, they have
1063 special types (this is probably a bug).
1064
1065 Parameters
1066 payload optional payload or NULL
1067 payload_s payload length or 0
1068 l pointer to a libnet context
1069 ptag protocol tag to modify an existing header, 0 to build a new
1070 one
1071
1072 Returns
1073 protocol tag value on success
1074
1075 Return values
1076 -1 on error
1077
1078 LIBNET_API libnet_ptag_t libnet_build_dhcpv4 (uint8_t opcode, uint8_t
1079 htype, uint8_t hlen, uint8_t hopcount, uint32_t xid, uint16_t secs,
1080 uint16_t flags, uint32_t cip, uint32_t yip, uint32_t sip, uint32_t gip,
1081 const uint8_t * chaddr, const char * sname, const char * file, const
1082 uint8_t * payload, uint32_t payload_s, libnet_t * l, libnet_ptag_t
1083 ptag)
1084 Parameters
1085 opcode
1086 htype
1087 hlen
1088 hopcount
1089 xid
1090 secs
1091 flags
1092 cip
1093 yip
1094 sip
1095 gip
1096 chaddr client hardware address, length is hlen
1097 sname server host name, a null terminated string
1098 file boot file name, a null terminated string
1099 payload optional payload or NULL
1100 payload_s payload length or 0
1101 l pointer to a libnet context
1102 ptag protocol tag to modify an existing header, 0 to build a new
1103 one
1104
1105 Returns
1106 protocol tag value on success
1107
1108 Return values
1109 -1 on error
1110
1111 LIBNET_API libnet_ptag_t libnet_build_dnsv4 (uint16_t h_len, uint16_t id,
1112 uint16_t flags, uint16_t num_q, uint16_t num_anws_rr, uint16_t
1113 num_auth_rr, uint16_t num_addi_rr, const uint8_t * payload, uint32_t
1114 payload_s, libnet_t * l, libnet_ptag_t ptag)
1115 Builds an RFC 1035 version 4 DNS header. Additional DNS payload
1116 information should be specified using the payload interface.
1117
1118 Parameters
1119 h_len
1120 id DNS packet id
1121 flags control flags
1122 num_q number of questions
1123 num_anws_rr number of answer resource records
1124 num_auth_rr number of authority resource records
1125 num_addi_rr number of additional resource records
1126 payload optional payload or NULL
1127 payload_s payload length or 0
1128 l pointer to a libnet context
1129 ptag protocol tag to modify an existing header, 0 to build a new
1130 one
1131
1132 Returns
1133 protocol tag value on success
1134
1135 Return values
1136 -1 on error
1137
1138 LIBNET_API libnet_ptag_t libnet_build_egre (uint16_t fv, uint16_t type,
1139 uint16_t sum, uint16_t offset, uint32_t key, uint32_t seq, uint16_t
1140 len, const uint8_t * payload, uint32_t payload_s, libnet_t * l,
1141 libnet_ptag_t ptag)
1142 Generic Routing Encapsulation (GRE - RFC 1701) is used to encapsulate
1143 any protocol. Hence, the IP part of the packet is usually referred as
1144 'delivery header'. It is then followed by the GRE header and finally
1145 the encapsulated packet (IP or whatever). As GRE is very modular, the
1146 first GRE header describes the structure of the header, using bits and
1147 flag to specify which fields will be present in the header.
1148
1149 Parameters
1150 fv the 16 0 to 7: which fields are included in the header
1151 (checksum, seq. number, key, ...), bits 8 to 12: flag, bits 13 to
1152 15: version.
1153 type which protocol is encapsulated (PPP, IP, ...)
1154 sum checksum (0 for libnet to auto-fill).
1155 offset byte offset from the start of the routing field to the first
1156 byte of the SRE
1157 key inserted by the encapsulator to authenticate the source
1158 seq sequence number used by the receiver to sort the packets
1159 len size of the GRE packet
1160 payload optional payload or NULL
1161 payload_s payload length or 0
1162 l pointer to a libnet context
1163 ptag protocol tag to modify an existing header, 0 to build a new
1164 one
1165
1166 Returns
1167 protocol tag value on success
1168
1169 Return values
1170 -1 on error
1171
1172 LIBNET_API libnet_ptag_t libnet_build_ethernet (const uint8_t * dst, const
1173 uint8_t * src, uint16_t type, const uint8_t * payload, uint32_t
1174 payload_s, libnet_t * l, libnet_ptag_t ptag)
1175 Builds an Ethernet header. The RFC 894 Ethernet II header is almost
1176 identical to the IEEE 802.3 header, with the exception that the field
1177 immediately following the source address holds the layer 3 protocol (as
1178 opposed to frame's length). You should only use this function when
1179 libnet is initialized with the LIBNET_LINK interface.
1180
1181 Parameters
1182 dst destination ethernet address
1183 src source ethernet address
1184 type upper layer protocol type
1185 payload optional payload or NULL
1186 payload_s payload length or 0
1187 l pointer to a libnet context
1188 ptag protocol tag to modify an existing header, 0 to build a new
1189 one
1190
1191 Returns
1192 protocol tag value on success
1193
1194 Return values
1195 -1 on error
1196
1197 LIBNET_API libnet_ptag_t libnet_build_fddi (uint8_t fc, const uint8_t *
1198 dst, const uint8_t * src, uint8_t dsap, uint8_t ssap, uint8_t cf, const
1199 uint8_t * oui, uint16_t type, const uint8_t * payload, uint32_t
1200 payload_s, libnet_t * l, libnet_ptag_t ptag)
1201 Builds a Fiber Distributed Data Interface (FDDI) header.
1202
1203 Parameters
1204 fc class format and priority
1205 dst destination fddi address
1206 src source fddi address
1207 dsap destination service access point
1208 ssap source service access point
1209 cf cf
1210 oui 3 byte IEEE organizational code
1211 type upper layer protocol
1212 payload optional payload or NULL
1213 payload_s payload length or 0
1214 l pointer to a libnet context
1215 ptag protocol tag to modify an existing header, 0 to build a new
1216 one
1217
1218 Returns
1219 protocol tag value on success
1220
1221 Return values
1222 -1 on error
1223
1224 LIBNET_API libnet_ptag_t libnet_build_gre (uint16_t fv, uint16_t type,
1225 uint16_t sum, uint16_t offset, uint32_t key, uint32_t seq, uint16_t
1226 len, const uint8_t * payload, uint32_t payload_s, libnet_t * l,
1227 libnet_ptag_t ptag)
1228 Generic Routing Encapsulation (GRE - RFC 1701) is used to encapsulate
1229 any protocol. Hence, the IP part of the packet is usually referred as
1230 'delivery header'. It is then followed by the GRE header and finally
1231 the encapsulated packet (IP or whatever). As GRE is very modular, the
1232 first GRE header describes the structure of the header, using bits and
1233 flag to specify which fields will be present in the header.
1234
1235 Parameters
1236 fv the 16 0 to 7: which fields are included in the header
1237 (checksum, seq. number, key, ...), bits 8 to 12: flag, bits 13 to
1238 15: version.
1239 type which protocol is encapsulated (PPP, IP, ...)
1240 sum checksum (0 for libnet to auto-fill).
1241 offset byte offset from the start of the routing field to the first
1242 byte of the SRE
1243 key inserted by the encapsulator to authenticate the source
1244 seq sequence number used by the receiver to sort the packets
1245 len size of the GRE packet
1246 payload
1247 payload_s payload length or 0
1248 l pointer to a libnet context
1249 ptag protocol tag to modify an existing header, 0 to build a new
1250 one
1251
1252 Returns
1253 protocol tag value on success
1254
1255 Return values
1256 -1 on error
1257
1258 LIBNET_API libnet_ptag_t libnet_build_gre_last_sre (libnet_t * l,
1259 libnet_ptag_t ptag)
1260 Parameters
1261 l pointer to a libnet context
1262 ptag protocol tag to modify an existing header, 0 to build a new
1263 one
1264
1265 Returns
1266 protocol tag value on success
1267
1268 Return values
1269 -1 on error
1270
1271 LIBNET_API libnet_ptag_t libnet_build_gre_sre (uint16_t af, uint8_t offset,
1272 uint8_t length, uint8_t * routing, const uint8_t * payload, uint32_t
1273 payload_s, libnet_t * l, libnet_ptag_t ptag)
1274 Parameters
1275 af
1276 offset
1277 length
1278 routing
1279 payload optional payload or NULL
1280 payload_s payload length or 0
1281 l pointer to a libnet context
1282 ptag protocol tag to modify an existing header, 0 to build a new
1283 one
1284
1285 Returns
1286 protocol tag value on success
1287
1288 Return values
1289 -1 on error
1290
1291 LIBNET_API libnet_ptag_t libnet_build_hsrp (uint8_t version, uint8_t
1292 opcode, uint8_t state, uint8_t hello_time, uint8_t hold_time, uint8_t
1293 priority, uint8_t group, uint8_t reserved, uint8_t
1294 authdata[HSRP_AUTHDATA_LENGTH], uint32_t virtual_ip, const uint8_t *
1295 payload, uint32_t payload_s, libnet_t * l, libnet_ptag_t ptag)
1296 Builds a HSRP header. HSRP is a Cisco proprietary protocol defined in
1297 RFC 2281
1298
1299 Parameters
1300 version version of the HSRP messages
1301 opcode type of message
1302 state current state of the router
1303 hello_time period in seconds between hello messages
1304 hold_time seconds that the current hello message is valid
1305 priority priority for the election process
1306 group standby group
1307 reserved reserved field
1308 authdata password
1309 virtual_ip virtual ip address
1310 payload optional payload or NULL
1311 payload_s payload length or 0
1312 l pointer to a libnet context
1313 ptag protocol tag to modify an existing header, 0 to build a new
1314 one
1315
1316 Returns
1317 protocol tag value on success
1318
1319 Return values
1320 -1 on error
1321
1322 LIBNET_API libnet_ptag_t libnet_build_icmpv4_echo (uint8_t type, uint8_t
1323 code, uint16_t sum, uint16_t id, uint16_t seq, const uint8_t * payload,
1324 uint32_t payload_s, libnet_t * l, libnet_ptag_t ptag)
1325 At the moment, this function is not implemented.
1326
1327 This stub may be useful in feature to let to the user build the LLDPDU
1328 in one function by passing corresponding arguments. Builds an IP
1329 version 4 RFC 792 Internet Control Message Protocol (ICMP) echo
1330 request/reply header
1331
1332 Parameters
1333 type type of ICMP packet (should be ICMP_ECHOREPLY or ICMP_ECHO)
1334 code code of ICMP packet (should be 0)
1335 sum checksum (0 for libnet to auto-fill)
1336 id identification number
1337 seq packet sequence number
1338 payload optional payload or NULL
1339 payload_s payload length or 0
1340 l pointer to a libnet context
1341 ptag protocol tag to modify an existing header, 0 to build a new
1342 one
1343
1344 Returns
1345 protocol tag value on success
1346
1347 Return values
1348 -1 on error
1349
1350 LIBNET_API libnet_ptag_t libnet_build_icmpv4_mask (uint8_t type, uint8_t
1351 code, uint16_t sum, uint16_t id, uint16_t seq, uint32_t mask, const
1352 uint8_t * payload, uint32_t payload_s, libnet_t * l, libnet_ptag_t
1353 ptag)
1354 Builds an IP version 4 RFC 792 Internet Control Message Protocol (ICMP)
1355 IP netmask request/reply header.
1356
1357 Parameters
1358 type type of ICMP packet (should be ICMP_MASKREQ or ICMP_MASKREPLY)
1359 code code of ICMP packet (should be 0)
1360 sum checksum (0 for libnet to auto-fill)
1361 id identification number
1362 seq packet sequence number
1363 mask subnet mask
1364 payload optional payload or NULL
1365 payload_s payload length or 0
1366 l pointer to a libnet context
1367 ptag protocol tag to modify an existing header, 0 to build a new
1368 one
1369
1370 Returns
1371 protocol tag value on success
1372
1373 Return values
1374 -1 on error
1375
1376 LIBNET_API libnet_ptag_t libnet_build_icmpv4_redirect (uint8_t type,
1377 uint8_t code, uint16_t sum, uint32_t gateway, const uint8_t * payload,
1378 uint32_t payload_s, libnet_t * l, libnet_ptag_t ptag)
1379 Builds an IP version 4 RFC 792 Internet Message Control Protocol (ICMP)
1380 redirect header. The IP header that caused the error message should be
1381 built by a previous call to libnet_build_ipv4().
1382
1383 Parameters
1384 type type of ICMP packet (should be ICMP_REDIRECT)
1385 code code of ICMP packet (should be one of the four redirect codes)
1386 sum checksum (0 for libnet to auto-fill)
1387 gateway
1388 payload optional payload or NULL
1389 payload_s payload length or 0
1390 l pointer to a libnet context
1391 ptag protocol tag to modify an existing header, 0 to build a new
1392 one
1393
1394 Returns
1395 protocol tag value on success
1396
1397 Return values
1398 -1 on error
1399
1400 LIBNET_API libnet_ptag_t libnet_build_icmpv4_timeexceed (uint8_t type,
1401 uint8_t code, uint16_t sum, const uint8_t * payload, uint32_t
1402 payload_s, libnet_t * l, libnet_ptag_t ptag)
1403 Builds an IP version 4 RFC 792 Internet Control Message Protocol (ICMP)
1404 time exceeded header. The IP header that caused the error message
1405 should be built by a previous call to libnet_build_ipv4().
1406
1407 Parameters
1408 type type of ICMP packet (should be ICMP_TIMXCEED)
1409 code code of ICMP packet (ICMP_TIMXCEED_INTRANS /
1410 ICMP_TIMXCEED_REASS)
1411 sum checksum (0 for libnet to auto-fill)
1412 payload optional payload or NULL
1413 payload_s payload length or 0
1414 l pointer to a libnet context
1415 ptag protocol tag to modify an existing header, 0 to build a new
1416 one
1417
1418 Returns
1419 protocol tag value on success
1420
1421 Return values
1422 -1 on error
1423
1424 LIBNET_API libnet_ptag_t libnet_build_icmpv4_timestamp (uint8_t type,
1425 uint8_t code, uint16_t sum, uint16_t id, uint16_t seq, uint32_t otime,
1426 uint32_t rtime, uint32_t ttime, const uint8_t * payload, uint32_t
1427 payload_s, libnet_t * l, libnet_ptag_t ptag)
1428 Builds an IP version 4 RFC 792 Internet Control Message Protocol (ICMP)
1429 timestamp request/reply header.
1430
1431 Parameters
1432 type type of ICMP packet (should be ICMP_TSTAMP or
1433 ICMP_TSTAMPREPLY)
1434 code code of ICMP packet (should be 0)
1435 sum checksum (0 for libnet to auto-fill)
1436 id identification number
1437 seq sequence number
1438 otime originate timestamp
1439 rtime receive timestamp
1440 ttime transmit timestamp
1441 payload optional payload or NULL
1442 payload_s payload length or 0
1443 l pointer to a libnet context
1444 ptag protocol tag to modify an existing header, 0 to build a new
1445 one
1446
1447 Returns
1448 protocol tag value on success
1449
1450 Return values
1451 -1 on error
1452
1453 LIBNET_API libnet_ptag_t libnet_build_icmpv4_unreach (uint8_t type, uint8_t
1454 code, uint16_t sum, const uint8_t * payload, uint32_t payload_s,
1455 libnet_t * l, libnet_ptag_t ptag)
1456 Builds an IP version 4 RFC 792 Internet Control Message Protocol (ICMP)
1457 unreachable header. The IP header that caused the error message should
1458 be built by a previous call to libnet_build_ipv4().
1459
1460 Parameters
1461 type type of ICMP packet (should be ICMP_UNREACH)
1462 code code of ICMP packet (should be one of the 16 unreachable
1463 codes)
1464 sum checksum (0 for libnet to auto-fill)
1465 payload optional payload or NULL
1466 payload_s payload length or 0
1467 l pointer to a libnet context
1468 ptag protocol tag to modify an existing header, 0 to build a new
1469 one
1470
1471 Returns
1472 protocol tag value on success
1473
1474 Return values
1475 -1 on error
1476
1477 LIBNET_API libnet_ptag_t libnet_build_icmpv6_echo (uint8_t type, uint8_t
1478 code, uint16_t sum, uint16_t id, uint16_t seq, uint8_t * payload,
1479 uint32_t payload_s, libnet_t * l, libnet_ptag_t ptag)
1480 Builds an IP version 6 RFC 4443 Internet Control Message Protocol
1481 (ICMP) echo or echo reply header.
1482
1483 Parameters
1484 type type of ICMP packet (should be ICMP6_ECHO_REQUEST or
1485 ICMP6_ECHO_REPLY)
1486 code code of ICMP packet (should be zero)
1487 sum checksum (0 for libnet to auto-fill)
1488 id echo id number
1489 seq echo sequence number
1490 payload optional payload or NULL
1491 payload_s payload length or 0
1492 l pointer to a libnet context
1493 ptag protocol tag to modify an existing header, 0 to build a new
1494 one
1495
1496 Returns
1497 protocol tag value on success
1498
1499 Return values
1500 -1 on error
1501
1502 LIBNET_API libnet_ptag_t libnet_build_icmpv6_ndp_nadv (uint8_t type,
1503 uint8_t code, uint16_t sum, uint32_t flags, struct libnet_in6_addr
1504 target, uint8_t * payload, uint32_t payload_s, libnet_t * l,
1505 libnet_ptag_t ptag)
1506 Builds an IP version 6 RFC 2461 Internet Control Message Protocol
1507 (ICMP) NDP neighbour advertisement header. Could be used with
1508 libnet_build_icmpv6_ndp_opt() and ND_OPT_TARGET_LINKADDR.
1509
1510 Parameters
1511 type type of ICMP packet (should be ND_NEIGHBOR_ADVERT)
1512 code code of ICMP packet (should be zero)
1513 sum checksum (0 for libnet to auto-fill)
1514 flags should be a bitwise or of any applicable ND_NA_FLAG_* flags
1515 target target ipv6 address
1516 payload optional payload or NULL
1517 payload_s payload length or 0
1518 l pointer to a libnet context
1519 ptag protocol tag to modify an existing header, 0 to build a new
1520 one
1521
1522 Returns
1523 protocol tag value on success
1524
1525 Return values
1526 -1 on error
1527
1528 LIBNET_API libnet_ptag_t libnet_build_icmpv6_ndp_nsol (uint8_t type,
1529 uint8_t code, uint16_t sum, struct libnet_in6_addr target, uint8_t *
1530 payload, uint32_t payload_s, libnet_t * l, libnet_ptag_t ptag)
1531 Builds an IP version 6 RFC 2461 Internet Control Message Protocol
1532 (ICMP) NDP neighbour solicitation header. Could be used with
1533 libnet_build_icmpv6_ndp_opt() and ICMPV6_NDP_OPT_SLLA.
1534
1535 Parameters
1536 type type of ICMP packet (should be ND_NEIGHBOR_SOLICIT)
1537 code code of ICMP packet (should be zero)
1538 sum checksum (0 for libnet to auto-fill)
1539 target target ipv6 address
1540 payload optional payload or NULL
1541 payload_s payload length or 0
1542 l pointer to a libnet context
1543 ptag protocol tag to modify an existing header, 0 to build a new
1544 one
1545
1546 Returns
1547 protocol tag value on success
1548
1549 Return values
1550 -1 on error
1551
1552 LIBNET_API libnet_ptag_t libnet_build_icmpv6_ndp_opt (uint8_t type, uint8_t
1553 * option, uint32_t option_s, libnet_t * l, libnet_ptag_t ptag)
1554 Builds ICMPv6 NDP options.
1555
1556 Parameters
1557 type one of ND_OPT_* types
1558 option option data
1559 option_s size of option data (will be padded out to an 8-byte
1560 boundary)
1561 l pointer to a libnet context
1562 ptag protocol tag to modify an existing header, 0 to build a new
1563 one
1564
1565 Returns
1566 protocol tag value on success
1567
1568 Return values
1569 -1 on error
1570
1571 LIBNET_API libnet_ptag_t libnet_build_icmpv6_unreach (uint8_t type, uint8_t
1572 code, uint16_t sum, uint8_t * payload, uint32_t payload_s, libnet_t *
1573 l, libnet_ptag_t ptag)
1574 Builds an IP version 6 RFC 4443 Internet Control Message Protocol
1575 (ICMP) unreachable header. The IP header that caused the error message
1576 should be built by a previous call to libnet_build_ipv6().
1577
1578 Parameters
1579 type type of ICMP packet (should be ICMP6_DST_UNREACH)
1580 code code of ICMP packet (should be one of the 5
1581 ICMP6_DST_UNREACH_* codes)
1582 sum checksum (0 for libnet to auto-fill)
1583 payload optional payload or NULL
1584 payload_s payload length or 0
1585 l pointer to a libnet context
1586 ptag protocol tag to modify an existing header, 0 to build a new
1587 one
1588
1589 Returns
1590 protocol tag value on success
1591
1592 Return values
1593 -1 on error
1594
1595 LIBNET_API libnet_ptag_t libnet_build_igmp (uint8_t type, uint8_t reserved,
1596 uint16_t sum, uint32_t ip, const uint8_t * payload, uint32_t payload_s,
1597 libnet_t * l, libnet_ptag_t ptag)
1598 Builds an RFC 1112 Internet Group Membership Protocol (IGMP) header.
1599
1600 Parameters
1601 type packet type
1602 reserved (should be 0 for IGMPv1)
1603 sum checksum (0 for libnet to auto-fill)
1604 ip IPv4 address (in standard/network byte order)
1605 payload optional payload or NULL
1606 payload_s payload length or 0
1607 l pointer to a libnet context
1608 ptag protocol tag to modify an existing header, 0 to build a new
1609 one
1610
1611 Returns
1612 protocol tag value on success
1613
1614 Return values
1615 -1 on error
1616
1617 Note
1618
1619 LIBNET_API libnet_ptag_t libnet_build_ipsec_ah (uint8_t nh, uint8_t len,
1620 uint16_t res, uint32_t spi, uint32_t seq, uint32_t auth, const uint8_t
1621 * payload, uint32_t payload_s, libnet_t * l, libnet_ptag_t ptag)
1622 Builds an Internet Protocol Security Authentication header.
1623
1624 Parameters
1625 nh next header
1626 len payload length
1627 res reserved
1628 spi security parameter index
1629 seq sequence number
1630 auth authentication data
1631 payload optional payload or NULL
1632 payload_s payload length or 0
1633 l pointer to a libnet context
1634 ptag protocol tag to modify an existing header, 0 to build a new
1635 one
1636
1637 Returns
1638 protocol tag value on success
1639
1640 Return values
1641 -1 on error
1642
1643 LIBNET_API libnet_ptag_t libnet_build_ipsec_esp_ftr (uint8_t len, uint8_t
1644 nh, int8_t * auth, const uint8_t * payload, uint32_t payload_s,
1645 libnet_t * l, libnet_ptag_t ptag)
1646 Builds an Internet Protocol Security Encapsulating Security Payload
1647 footer.
1648
1649 Parameters
1650 len padding length
1651 nh next header
1652 auth authentication data
1653 payload optional payload or NULL
1654 payload_s payload length or 0
1655 l pointer to a libnet context
1656 ptag protocol tag to modify an existing header, 0 to build a new
1657 one
1658
1659 Returns
1660 protocol tag value on success
1661
1662 Return values
1663 -1 on error
1664
1665 LIBNET_API libnet_ptag_t libnet_build_ipsec_esp_hdr (uint32_t spi, uint32_t
1666 seq, uint32_t iv, const uint8_t * payload, uint32_t payload_s, libnet_t
1667 * l, libnet_ptag_t ptag)
1668 Builds an Internet Protocol Security Encapsulating Security Payload
1669 header.
1670
1671 Parameters
1672 spi security parameter index
1673 seq ESP sequence number
1674 iv initialization vector
1675 payload optional payload or NULL
1676 payload_s payload length or 0
1677 l pointer to a libnet context
1678 ptag protocol tag to modify an existing header, 0 to build a new
1679 one
1680
1681 Returns
1682 protocol tag value on success
1683
1684 Return values
1685 -1 on error
1686
1687 LIBNET_API libnet_ptag_t libnet_build_ipv4 (uint16_t ip_len, uint8_t tos,
1688 uint16_t id, uint16_t frag, uint8_t ttl, uint8_t prot, uint16_t sum,
1689 uint32_t src, uint32_t dst, const uint8_t * payload, uint32_t
1690 payload_s, libnet_t * l, libnet_ptag_t ptag)
1691 Builds a version 4 RFC 791 Internet Protocol (IP) header.
1692
1693 Parameters
1694 ip_len total length of the IP packet including all subsequent data
1695 (subsequent data includes any IP options and IP options padding)
1696 tos type of service bits
1697 id IP identification number
1698 frag fragmentation bits and offset
1699 ttl time to live in the network
1700 prot upper layer protocol
1701 sum checksum (0 for libnet to auto-fill)
1702 src source IPv4 address (little endian)
1703 dst destination IPv4 address (little endian)
1704 payload optional payload or NULL
1705 payload_s payload length or 0
1706 l pointer to a libnet context
1707 ptag protocol tag to modify an existing header, 0 to build a new
1708 one
1709
1710 Returns
1711 protocol tag value on success
1712
1713 Return values
1714 -1 on error
1715
1716 LIBNET_API libnet_ptag_t libnet_build_ipv4_options (const uint8_t *
1717 options, uint32_t options_s, libnet_t * l, libnet_ptag_t ptag)
1718 Builds an version 4 Internet Protocol (IP) options header. The function
1719 expects options to be a valid IP options string of size options_s, no
1720 larger than 40 bytes (the maximum size of an options string).
1721
1722 When building a chain, the options must be built, then the IPv4 header.
1723
1724 When updating a chain, if the block following the options is an IPv4
1725 header, it's total length and header length will be updated if the
1726 options block size changes.
1727
1728 Parameters
1729 options byte string of IP options (it will be padded up to be an
1730 integral multiple of 32-bit words).
1731 options_s length of options string
1732 l pointer to a libnet context
1733 ptag protocol tag to modify an existing header, 0 to build a new
1734 one
1735
1736 Returns
1737 protocol tag value on success
1738
1739 Return values
1740 -1 on error
1741
1742 LIBNET_API libnet_ptag_t libnet_build_ipv6 (uint8_t tc, uint32_t fl,
1743 uint16_t len, uint8_t nh, uint8_t hl, struct libnet_in6_addr src,
1744 struct libnet_in6_addr dst, const uint8_t * payload, uint32_t
1745 payload_s, libnet_t * l, libnet_ptag_t ptag)
1746 Builds a version 6 RFC 2460 Internet Protocol (IP) header.
1747
1748 Parameters
1749 tc traffic class
1750 fl flow label
1751 len total length of the IP packet
1752 nh next header
1753 hl hop limit
1754 src source IPv6 address
1755 dst destination IPv6 address
1756 payload optional payload or NULL
1757 payload_s payload length or 0
1758 l pointer to a libnet context
1759 ptag protocol tag to modify an existing header, 0 to build a new
1760 one
1761
1762 Returns
1763 protocol tag value on success
1764
1765 Return values
1766 -1 on error
1767
1768 LIBNET_API libnet_ptag_t libnet_build_ipv6_destopts (uint8_t nh, uint8_t
1769 len, const uint8_t * payload, uint32_t payload_s, libnet_t * l,
1770 libnet_ptag_t ptag)
1771 Builds a version 6 RFC 2460 Internet Protocol (IP) destination options
1772 header. This function is special in that it uses the payload interface
1773 to include the options data. The application programmer will build an
1774 IPv6 options byte string and pass it to the function using the payload
1775 interface.
1776
1777 Parameters
1778 nh next header
1779 len length of the header in 8-byte octets not including the first 8
1780 octets
1781 payload options payload
1782 payload_s payload length
1783 l pointer to a libnet context
1784 ptag protocol tag to modify an existing header, 0 to build a new
1785 one
1786
1787 Returns
1788 protocol tag value on success
1789
1790 Return values
1791 -1 on error
1792
1793 LIBNET_API libnet_ptag_t libnet_build_ipv6_frag (uint8_t nh, uint8_t
1794 reserved, uint16_t frag, uint32_t id, const uint8_t * payload, uint32_t
1795 payload_s, libnet_t * l, libnet_ptag_t ptag)
1796 Builds a version 6 RFC 2460 Internet Protocol (IP) fragmentation
1797 header.
1798
1799 Parameters
1800 nh next header
1801 reserved unused value... OR IS IT!
1802 frag fragmentation bits (ala ipv4)
1803 id packet identification
1804 payload optional payload or NULL
1805 payload_s payload length or 0
1806 l pointer to a libnet context
1807 ptag protocol tag to modify an existing header, 0 to build a new
1808 one
1809
1810 Returns
1811 protocol tag value on success
1812
1813 Return values
1814 -1 on error
1815
1816 LIBNET_API libnet_ptag_t libnet_build_ipv6_hbhopts (uint8_t nh, uint8_t
1817 len, const uint8_t * payload, uint32_t payload_s, libnet_t * l,
1818 libnet_ptag_t ptag)
1819 Builds a version 6 RFC 2460 Internet Protocol (IP) hop by hop options
1820 header. This function is special in that it uses the payload interface
1821 to include the options data. The application programmer will build an
1822 IPv6 hop by hop options byte string and pass it to the function using
1823 the payload interface.
1824
1825 Parameters
1826 nh next header
1827 len length of the header in 8-byte octets not including the first 8
1828 octets
1829 payload options payload
1830 payload_s payload length
1831 l pointer to a libnet context
1832 ptag protocol tag to modify an existing header, 0 to build a new
1833 one
1834
1835 Returns
1836 protocol tag value on success
1837
1838 Return values
1839 -1 on error
1840
1841 LIBNET_API libnet_ptag_t libnet_build_ipv6_routing (uint8_t nh, uint8_t
1842 len, uint8_t rtype, uint8_t segments, const uint8_t * payload, uint32_t
1843 payload_s, libnet_t * l, libnet_ptag_t ptag)
1844 Builds a version 6 RFC 2460 Internet Protocol (IP) routing header. This
1845 function is special in that it uses the payload interface to include
1846 the 'type-specific data'; that is the routing information. Most often
1847 this will be a number of 128-bit IPv6 addresses. The application
1848 programmer will build a byte string of IPv6 address and pass them to
1849 the function using the payload interface.
1850
1851 Parameters
1852 nh next header
1853 len length of the header in 8-byte octets not including the first 8
1854 octets
1855 rtype routing header type
1856 segments number of routing segments that follow
1857 payload optional payload of routing information
1858 payload_s payload length
1859 l pointer to a libnet context
1860 ptag protocol tag to modify an existing header, 0 to build a new
1861 one
1862
1863 Returns
1864 protocol tag value on success
1865
1866 Return values
1867 -1 on error
1868
1869 LIBNET_API libnet_ptag_t libnet_build_isl (uint8_t * dhost, uint8_t type,
1870 uint8_t user, uint8_t * shost, uint16_t len, const uint8_t * snap,
1871 uint16_t vid, uint16_t portindex, uint16_t reserved, const uint8_t *
1872 payload, uint32_t payload_s, libnet_t * l, libnet_ptag_t ptag)
1873 Builds a Cisco Inter-Switch Link (ISL) header.
1874
1875 Parameters
1876 dhost destination address (should be 01:00:0c:00:00)
1877 type type of frame
1878 user user defined data
1879 shost source mac address
1880 len total length of the encapsulated packet less 18 bytes
1881 snap SNAP information (0xaaaa03 + vendor code)
1882 vid 15 bit VLAN ID, 1 bit BPDU or CDP indicator
1883 portindex port index
1884 reserved used for FDDI and token ring
1885 payload optional payload or NULL
1886 payload_s payload length or 0
1887 l pointer to a libnet context
1888 ptag protocol tag to modify an existing header, 0 to build a new
1889 one
1890
1891 Returns
1892 protocol tag value on success
1893
1894 Return values
1895 -1 on error
1896
1897 LIBNET_API libnet_ptag_t libnet_build_link (const uint8_t * dst, const
1898 uint8_t * src, const uint8_t * oui, uint16_t type, const uint8_t *
1899 payload, uint32_t payload_s, libnet_t * l, libnet_ptag_t ptag)
1900 Builds a link layer header for an initialized l. The function
1901 determines the proper link layer header format from how l was
1902 initialized. The function current supports Ethernet and Token Ring link
1903 layers.
1904
1905 Parameters
1906 dst the destination MAC address
1907 src the source MAC address
1908 oui Organizationally Unique Identifier (unused for Ethernet)
1909 type the upper layer protocol type
1910 payload optional payload or NULL
1911 payload_s payload length or 0
1912 l pointer to a libnet context
1913 ptag protocol tag to modify an existing header, 0 to build a new
1914 one
1915
1916 Returns
1917 protocol tag value on success
1918
1919 Return values
1920 -1 on error
1921
1922 LIBNET_API libnet_ptag_t libnet_build_lldp_chassis (const uint8_t subtype,
1923 const uint8_t * value, const uint8_t value_s, libnet_t * l,
1924 libnet_ptag_t ptag)
1925 Builds a LLDP Chassis ID TLV. The Chassis ID TLV is the first mandatory
1926 TLV in the LLDPDU.
1927
1928 Parameters
1929 subtype Chassis ID Subtype
1930 value the Chassis ID string
1931 value_s length of value argument
1932 l pointer to a libnet context
1933 ptag protocol tag to modify an existing header, 0 to build a new
1934 one
1935
1936 Returns
1937 protocol tag value on success
1938
1939 Return values
1940 -1 on error
1941
1942 LIBNET_API libnet_ptag_t libnet_build_lldp_end (libnet_t * l, libnet_ptag_t
1943 ptag)
1944 Builds a LLDP End of LLDPDU TLV. The End of LLDPDU TLV used to mark the
1945 end of the TLV sequence in LLDPDU. Is a 2 octet all-zero TLV
1946
1947 Parameters
1948 l pointer to a libnet context
1949 ptag protocol tag to modify an existing header, 0 to build a new
1950 one
1951
1952 Returns
1953 protocol tag value on success
1954
1955 Return values
1956 -1 on error
1957
1958 LIBNET_API libnet_ptag_t libnet_build_lldp_org_spec (const uint8_t * value,
1959 const uint16_t value_s, libnet_t * l, libnet_ptag_t ptag)
1960 Builds a LLDP Organization Specific TLV.
1961
1962 Parameters
1963 value the TLV information string
1964 value_s length of value argument
1965 l pointer to a libnet context
1966 ptag protocol tag to modify an existing header, 0 to build a new
1967 one
1968
1969 Returns
1970 protocol tag value on success
1971
1972 Return values
1973 -1 on error
1974
1975 LIBNET_API libnet_ptag_t libnet_build_lldp_port (const uint8_t subtype,
1976 const uint8_t * value, const uint8_t value_s, libnet_t * l,
1977 libnet_ptag_t ptag)
1978 Builds a LLDP Port ID TLV. The Port ID TLV is the second mandatory TLV
1979 in the LLDPDU.
1980
1981 Parameters
1982 subtype Port ID Subtype
1983 value the Port ID string
1984 value_s length of value argument
1985 l pointer to a libnet context
1986 ptag protocol tag to modify an existing header, 0 to build a new
1987 one
1988
1989 Returns
1990 protocol tag value on success
1991
1992 Return values
1993 -1 on error
1994
1995 LIBNET_API libnet_ptag_t libnet_build_lldp_ttl (const uint16_t ttl,
1996 libnet_t * l, libnet_ptag_t ptag)
1997 Builds a LLDP TTL TLV. The TTL TLV is the third mandatory TLV in the
1998 LLDPDU.
1999
2000 Parameters
2001 ttl number of seconds
2002 l pointer to a libnet context
2003 ptag protocol tag to modify an existing header, 0 to build a new
2004 one
2005
2006 Returns
2007 protocol tag value on success
2008
2009 Return values
2010 -1 on error
2011
2012 LIBNET_API libnet_ptag_t libnet_build_mpls (uint32_t label, uint8_t
2013 experimental, uint8_t bos, uint8_t ttl, const uint8_t * payload,
2014 uint32_t payload_s, libnet_t * l, libnet_ptag_t ptag)
2015 Builds an RFC 3032 Multi-Protocol Label Switching (MPLS) header.
2016
2017 Parameters
2018 label 20-bit label value
2019 experimental 3-bit reserved field
2020 bos 1-bit bottom of stack identifier
2021 ttl time to live
2022 payload optional payload or NULL
2023 payload_s payload length or 0
2024 l pointer to a libnet context
2025 ptag protocol tag to modify an existing header, 0 to build a new
2026 one
2027
2028 Returns
2029 protocol tag value on success
2030
2031 Return values
2032 -1 on error
2033
2034 LIBNET_API libnet_ptag_t libnet_build_ntp (uint8_t leap_indicator, uint8_t
2035 version, uint8_t mode, uint8_t stratum, uint8_t poll, uint8_t
2036 precision, uint16_t delay_int, uint16_t delay_frac, uint16_t
2037 dispersion_int, uint16_t dispersion_frac, uint32_t reference_id,
2038 uint32_t ref_ts_int, uint32_t ref_ts_frac, uint32_t orig_ts_int,
2039 uint32_t orig_ts_frac, uint32_t rec_ts_int, uint32_t rec_ts_frac,
2040 uint32_t xmt_ts_int, uint32_t xmt_ts_frac, const uint8_t * payload,
2041 uint32_t payload_s, libnet_t * l, libnet_ptag_t ptag)
2042 Builds an RFC 958 Network Time Protocol (NTP) header.
2043
2044 Parameters
2045 leap_indicator the leap indicator
2046 version NTP protocol version
2047 mode NTP mode
2048 stratum stratum
2049 poll polling interval
2050 precision precision
2051 delay_int delay interval
2052 delay_frac delay fraction
2053 dispersion_int dispersion interval
2054 dispersion_frac dispersion fraction
2055 reference_id reference id
2056 ref_ts_int reference timestamp integer
2057 ref_ts_frac reference timestamp fraction
2058 orig_ts_int original timestamp integer
2059 orig_ts_frac original timestamp fraction
2060 rec_ts_int receiver timestamp integer
2061 rec_ts_frac receiver timestamp fraction
2062 xmt_ts_int transmit timestamp integer
2063 xmt_ts_frac transmit timestamp integer
2064 payload optional payload or NULL
2065 payload_s payload length or 0
2066 l pointer to a libnet context
2067 ptag protocol tag to modify an existing header, 0 to build a new
2068 one
2069
2070 Returns
2071 protocol tag value on success
2072
2073 Return values
2074 -1 on error
2075
2076 LIBNET_API libnet_ptag_t libnet_build_ospfv2 (uint16_t len, uint8_t type,
2077 uint32_t rtr_id, uint32_t area_id, uint16_t sum, uint16_t autype, const
2078 uint8_t * payload, uint32_t payload_s, libnet_t * l, libnet_ptag_t
2079 ptag)
2080 Parameters
2081 len
2082 type
2083 rtr_id
2084 area_id
2085 sum
2086 autype
2087 payload optional payload or NULL
2088 payload_s payload length or 0
2089 l pointer to a libnet context
2090 ptag protocol tag to modify an existing header, 0 to build a new
2091 one
2092
2093 Returns
2094 protocol tag value on success
2095
2096 Return values
2097 -1 on error
2098
2099 LIBNET_API libnet_ptag_t libnet_build_ospfv2_dbd (uint16_t dgram_len,
2100 uint8_t opts, uint8_t type, uint32_t seqnum, const uint8_t * payload,
2101 uint32_t payload_s, libnet_t * l, libnet_ptag_t ptag)
2102 Parameters
2103 dgram_len
2104 opts
2105 type
2106 seqnum
2107 payload optional payload or NULL
2108 payload_s payload length or 0
2109 l pointer to a libnet context
2110 ptag protocol tag to modify an existing header, 0 to build a new
2111 one
2112
2113 Returns
2114 protocol tag value on success
2115
2116 Return values
2117 -1 on error
2118
2119 LIBNET_API libnet_ptag_t libnet_build_ospfv2_hello (uint32_t netmask,
2120 uint16_t interval, uint8_t opts, uint8_t priority, uint32_t dead_int,
2121 uint32_t des_rtr, uint32_t bkup_rtr, const uint8_t * payload, uint32_t
2122 payload_s, libnet_t * l, libnet_ptag_t ptag)
2123 Parameters
2124 netmask
2125 interval
2126 opts
2127 priority
2128 dead_int
2129 des_rtr
2130 bkup_rtr
2131 payload optional payload or NULL
2132 payload_s payload length or 0
2133 l pointer to a libnet context
2134 ptag protocol tag to modify an existing header, 0 to build a new
2135 one
2136
2137 Returns
2138 protocol tag value on success
2139
2140 Return values
2141 -1 on error
2142
2143 libnet_ptag_t libnet_build_ospfv2_hello_neighbor (uint32_t netmask,
2144 uint16_t interval, uint8_t opts, uint8_t priority, uint32_t dead_int,
2145 uint32_t des_rtr, uint32_t bkup_rtr, uint32_t neighbor, const uint8_t *
2146 payload, uint32_t payload_s, libnet_t * l, libnet_ptag_t ptag)
2147 Parameters
2148 netmask
2149 interval
2150 opts
2151 priority
2152 dead_int
2153 des_rtr
2154 bkup_rtr
2155 neighbor
2156 payload optional payload or NULL
2157 payload_s payload length or 0
2158 l pointer to a libnet context
2159 ptag protocol tag to modify an existing header, 0 to build a new
2160 one
2161
2162 Returns
2163 protocol tag value on success
2164
2165 Return values
2166 -1 on error
2167
2168 LIBNET_API libnet_ptag_t libnet_build_ospfv2_lsa (uint16_t age, uint8_t
2169 opts, uint8_t type, uint32_t lsid, uint32_t advrtr, uint32_t seqnum,
2170 uint16_t sum, uint16_t len, const uint8_t * payload, uint32_t
2171 payload_s, libnet_t * l, libnet_ptag_t ptag)
2172 Parameters
2173 age
2174 opts
2175 type
2176 lsid
2177 advrtr
2178 seqnum
2179 sum
2180 len
2181 payload optional payload or NULL
2182 payload_s payload length or 0
2183 l pointer to a libnet context
2184 ptag protocol tag to modify an existing header, 0 to build a new
2185 one
2186
2187 Returns
2188 protocol tag value on success
2189
2190 Return values
2191 -1 on error
2192
2193 LIBNET_API libnet_ptag_t libnet_build_ospfv2_lsa_as (uint32_t nmask,
2194 uint32_t metric, uint32_t fwdaddr, uint32_t tag, const uint8_t *
2195 payload, uint32_t payload_s, libnet_t * l, libnet_ptag_t ptag)
2196 Parameters
2197 nmask
2198 metric
2199 fwdaddr
2200 tag
2201 payload optional payload or NULL
2202 payload_s payload length or 0
2203 l pointer to a libnet context
2204 ptag protocol tag to modify an existing header, 0 to build a new
2205 one
2206
2207 Returns
2208 protocol tag value on success
2209
2210 Return values
2211 -1 on error
2212
2213 LIBNET_API libnet_ptag_t libnet_build_ospfv2_lsa_net (uint32_t nmask,
2214 uint32_t rtrid, const uint8_t * payload, uint32_t payload_s, libnet_t *
2215 l, libnet_ptag_t ptag)
2216 Parameters
2217 nmask
2218 rtrid
2219 payload optional payload or NULL
2220 payload_s payload length or 0
2221 l pointer to a libnet context
2222 ptag protocol tag to modify an existing header, 0 to build a new
2223 one
2224
2225 Returns
2226 protocol tag value on success
2227
2228 Return values
2229 -1 on error
2230
2231 LIBNET_API libnet_ptag_t libnet_build_ospfv2_lsa_rtr (uint16_t flags,
2232 uint16_t num, uint32_t id, uint32_t data, uint8_t type, uint8_t tos,
2233 uint16_t metric, const uint8_t * payload, uint32_t payload_s, libnet_t
2234 * l, libnet_ptag_t ptag)
2235 Parameters
2236 flags
2237 num
2238 id
2239 data
2240 type
2241 tos
2242 metric
2243 payload optional payload or NULL
2244 payload_s payload length or 0
2245 l pointer to a libnet context
2246 ptag protocol tag to modify an existing header, 0 to build a new
2247 one
2248
2249 Returns
2250 protocol tag value on success
2251
2252 Return values
2253 -1 on error
2254
2255 LIBNET_API libnet_ptag_t libnet_build_ospfv2_lsa_sum (uint32_t nmask,
2256 uint32_t metric, uint32_t tos, const uint8_t * payload, uint32_t
2257 payload_s, libnet_t * l, libnet_ptag_t ptag)
2258 Parameters
2259 nmask
2260 metric
2261 tos
2262 payload optional payload or NULL
2263 payload_s payload length or 0
2264 l pointer to a libnet context
2265 ptag protocol tag to modify an existing header, 0 to build a new
2266 one
2267
2268 Returns
2269 protocol tag value on success
2270
2271 Return values
2272 -1 on error
2273
2274 LIBNET_API libnet_ptag_t libnet_build_ospfv2_lsr (uint32_t type, uint32_t
2275 lsid, uint32_t advrtr, const uint8_t * payload, uint32_t payload_s,
2276 libnet_t * l, libnet_ptag_t ptag)
2277 Parameters
2278 type
2279 lsid
2280 advrtr
2281 payload optional payload or NULL
2282 payload_s payload length or 0
2283 l pointer to a libnet context
2284 ptag protocol tag to modify an existing header, 0 to build a new
2285 one
2286
2287 Returns
2288 protocol tag value on success
2289
2290 Return values
2291 -1 on error
2292
2293 LIBNET_API libnet_ptag_t libnet_build_ospfv2_lsu (uint32_t num, const
2294 uint8_t * payload, uint32_t payload_s, libnet_t * l, libnet_ptag_t
2295 ptag)
2296 Parameters
2297 num
2298 payload optional payload or NULL
2299 payload_s payload length or 0
2300 l pointer to a libnet context
2301 ptag protocol tag to modify an existing header, 0 to build a new
2302 one
2303
2304 Returns
2305 protocol tag value on success
2306
2307 Return values
2308 -1 on error
2309
2310 LIBNET_API libnet_ptag_t libnet_build_rip (uint8_t cmd, uint8_t version,
2311 uint16_t rd, uint16_t af, uint16_t rt, uint32_t addr, uint32_t mask,
2312 uint32_t next_hop, uint32_t metric, const uint8_t * payload, uint32_t
2313 payload_s, libnet_t * l, libnet_ptag_t ptag)
2314 Builds a Routing Information Protocol header (RFCs 1058 and 2453).
2315
2316 Parameters
2317 cmd command
2318 version protocol version
2319 rd version one: 0, version two: routing domain
2320 af address family
2321 rt version one: 0, version two: route tag
2322 addr IPv4 address
2323 mask version one: 0, version two: subnet mask
2324 next_hop version one: 0, version two: next hop address
2325 metric routing metric
2326 payload optional payload or NULL
2327 payload_s payload length or 0
2328 l pointer to a libnet context
2329 ptag protocol tag to modify an existing header, 0 to build a new
2330 one
2331
2332 Returns
2333 protocol tag value on success
2334
2335 Return values
2336 -1 on error
2337
2338 LIBNET_API libnet_ptag_t libnet_build_rpc_call (uint32_t rm, uint32_t xid,
2339 uint32_t prog_num, uint32_t prog_vers, uint32_t procedure, uint32_t
2340 cflavor, uint32_t clength, uint8_t * cdata, uint32_t vflavor, uint32_t
2341 vlength, const uint8_t * vdata, const uint8_t * payload, uint32_t
2342 payload_s, libnet_t * l, libnet_ptag_t ptag)
2343 Builds an Remote Procedure Call (Version 2) Call message header as
2344 specified in RFC 1831. This builder provides the option for specifying
2345 the record marking which is required when used with streaming protocols
2346 (TCP).
2347
2348 Parameters
2349 rm record marking indicating the position in a stream, 0 otherwise
2350 xid transaction identifier used to link calls and replies
2351 prog_num remote program specification typically between 0 -
2352 1fffffff
2353 prog_vers remote program version specification
2354 procedure procedure to be performed by remote program
2355 cflavor authentication credential type
2356 clength credential length (should be 0)
2357 cdata opaque credential data (currently unused)
2358 vflavor authentication verifier type
2359 vlength verifier length (should be 0)
2360 vdata opaque verifier data (currently unused)
2361 payload optional payload or NULL
2362 payload_s payload length or 0
2363 l pointer to a libnet context
2364 ptag protocol tag to modify an existing header, 0 to build a new
2365 one
2366
2367 Returns
2368 protocol tag value on success
2369
2370 Return values
2371 -1 on error
2372
2373 LIBNET_API libnet_ptag_t libnet_build_sebek (uint32_t magic, uint16_t
2374 version, uint16_t type, uint32_t counter, uint32_t time_sec, uint32_t
2375 time_usec, uint32_t pid, uint32_t uid, uint32_t fd, uint8_t
2376 cmd[SEBEK_CMD_LENGTH], uint32_t length, const uint8_t * payload,
2377 uint32_t payload_s, libnet_t * l, libnet_ptag_t ptag)
2378 Builds a Sebek header. The Sebek protocol was designed by the Honeynet
2379 Project as a transport mechanism for post-intrusion forensic data. More
2380 information may be found here:
2381 http://www.honeynet.org/papers/sebek.pdf.
2382
2383 Parameters
2384 magic identify packets that should be hidden
2385 version protocol version, currently 1
2386 type type of record (read data is type 0, write data is type 1)
2387 counter PDU counter used to identify when packet are lost
2388 time_sec seconds since EPOCH according to the honeypot
2389 time_usec residual microseconds
2390 pid PID
2391 uid UID
2392 fd FD
2393 cmd 12 first characters of the command
2394 length length in bytes of the PDU's body
2395 payload optional payload or NULL
2396 payload_s payload length or 0
2397 l pointer to a libnet context
2398 ptag protocol tag to modify an existing header, 0 to build a new
2399 one
2400
2401 Returns
2402 protocol tag value on success
2403
2404 Return values
2405 -1 on error
2406
2407 LIBNET_API libnet_ptag_t libnet_build_stp_conf (uint16_t id, uint8_t
2408 version, uint8_t bpdu_type, uint8_t flags, const uint8_t * root_id,
2409 uint32_t root_pc, const uint8_t * bridge_id, uint16_t port_id, uint16_t
2410 message_age, uint16_t max_age, uint16_t hello_time, uint16_t f_delay,
2411 const uint8_t * payload, uint32_t payload_s, libnet_t * l,
2412 libnet_ptag_t ptag)
2413 Builds an IEEE 802.1d Spanning Tree Protocol (STP) configuration
2414 header. STP frames are usually encapsulated inside of an 802.2 + 802.3
2415 frame combination.
2416
2417 Parameters
2418 id protocol id
2419 version protocol version
2420 bpdu_type bridge protocol data unit type
2421 flags flags
2422 root_id root id
2423 root_pc root path cost
2424 bridge_id bridge id
2425 port_id port id
2426 message_age message age
2427 max_age max age
2428 hello_time hello time
2429 f_delay forward delay
2430 payload optional payload or NULL
2431 payload_s payload length or 0
2432 l pointer to a libnet context
2433 ptag protocol tag to modify an existing header, 0 to build a new
2434 one
2435
2436 Returns
2437 protocol tag value on success
2438
2439 Return values
2440 -1 on error
2441
2442 LIBNET_API libnet_ptag_t libnet_build_stp_tcn (uint16_t id, uint8_t
2443 version, uint8_t bpdu_type, const uint8_t * payload, uint32_t
2444 payload_s, libnet_t * l, libnet_ptag_t ptag)
2445 Builds an IEEE 802.1d Spanning Tree Protocol (STP) topology change
2446 notification header. STP frames are usually encapsulated inside of an
2447 802.2 + 802.3 frame combination.
2448
2449 Parameters
2450 id protocol id
2451 version protocol version
2452 bpdu_type bridge protocol data unit type
2453 payload optional payload or NULL
2454 payload_s payload length or 0
2455 l pointer to a libnet context
2456 ptag protocol tag to modify an existing header, 0 to build a new
2457 one
2458
2459 Returns
2460 protocol tag value on success
2461
2462 Return values
2463 -1 on error
2464
2465 LIBNET_API libnet_ptag_t libnet_build_tcp (uint16_t sp, uint16_t dp,
2466 uint32_t seq, uint32_t ack, uint8_t control, uint16_t win, uint16_t
2467 sum, uint16_t urg, uint16_t len, const uint8_t * payload, uint32_t
2468 payload_s, libnet_t * l, libnet_ptag_t ptag)
2469 Builds an RFC 793 Transmission Control Protocol (TCP) header.
2470
2471 Parameters
2472 sp source port
2473 dp destination port
2474 seq sequence number
2475 ack acknowledgement number
2476 control control flags
2477 win window size
2478 sum checksum (0 for libnet to auto-fill)
2479 urg urgent pointer
2480 len total length of the TCP packet (for checksum calculation)
2481 payload
2482 payload_s payload length or 0
2483 l pointer to a libnet context
2484 ptag protocol tag to modify an existing header, 0 to build a new
2485 one
2486
2487 Returns
2488 protocol tag value on success
2489
2490 Return values
2491 -1 on error
2492
2493 LIBNET_API libnet_ptag_t libnet_build_tcp_options (const uint8_t * options,
2494 uint32_t options_s, libnet_t * l, libnet_ptag_t ptag)
2495 Builds an RFC 793 Transmission Control Protocol (TCP) options header.
2496 The function expects options to be a valid TCP options string of size
2497 options_s, which is no larger than 40 bytes (the maximum size of an
2498 options string). The function checks to ensure that the packet consists
2499 of a TCP header preceded by an IPv4 header, and that the addition of
2500 the options string would not result in a packet larger than 65,535
2501 bytes (IPMAXPACKET). The function counts up the number of 32-bit words
2502 in the options string and adjusts the TCP header length value as
2503 necessary.
2504
2505 Parameters
2506 options byte string of TCP options
2507 options_s length of options string
2508 l pointer to a libnet context
2509 ptag protocol tag to modify an existing header, 0 to build a new
2510 one
2511
2512 Returns
2513 protocol tag value on success
2514
2515 Return values
2516 -1 on error
2517
2518 LIBNET_API libnet_ptag_t libnet_build_token_ring (uint8_t ac, uint8_t fc,
2519 const uint8_t * dst, const uint8_t * src, uint8_t dsap, uint8_t ssap,
2520 uint8_t cf, const uint8_t * oui, uint16_t type, const uint8_t *
2521 payload, uint32_t payload_s, libnet_t * l, libnet_ptag_t ptag)
2522 Builds a token ring header.
2523
2524 Parameters
2525 ac access control
2526 fc frame control
2527 dst destination address
2528 src source address
2529 dsap destination service access point
2530 ssap source service access point
2531 cf control field
2532 oui Organizationally Unique Identifier
2533 type upper layer protocol type
2534 payload optional payload or NULL
2535 payload_s payload length or 0
2536 l pointer to a libnet context
2537 ptag protocol tag to modify an existing header, 0 to build a new
2538 one
2539
2540 Returns
2541 protocol tag value on success
2542
2543 Return values
2544 -1 on error
2545
2546 LIBNET_API libnet_ptag_t libnet_build_udld_device_id (const uint8_t *
2547 value, const uint8_t value_s, libnet_t * l, libnet_ptag_t ptag)
2548 Builds an UniDirectional Link Detection(UDLD) Device ID TLV.
2549
2550 Parameters
2551 value device id(ASCII character string)
2552 value_s device id(ASCII character string) length
2553 l pointer to a libnet context
2554 ptag protocol tag to modify an existing header, 0 to build a new
2555 one
2556
2557 Returns
2558 protocol tag value on success
2559
2560 Return values
2561 -1 on error
2562
2563 LIBNET_API libnet_ptag_t libnet_build_udld_device_name (const uint8_t *
2564 value, const uint8_t value_s, libnet_t * l, libnet_ptag_t ptag)
2565 Builds an UniDirectional Link Detection(UDLD) Device Name TLV.
2566
2567 Parameters
2568 value device name(ASCII character string)
2569 value_s device name length
2570 l pointer to a libnet context
2571 ptag protocol tag to modify an existing header, 0 to build a new
2572 one
2573
2574 Returns
2575 protocol tag value on success
2576
2577 Return values
2578 -1 on error
2579
2580 LIBNET_API libnet_ptag_t libnet_build_udld_echo (const uint8_t * value,
2581 const uint8_t value_s, libnet_t * l, libnet_ptag_t ptag)
2582 Builds an UniDirectional Link Detection(UDLD) Echo TLV.
2583
2584 Parameters
2585 value list of ID pairs
2586 value_s ID pairs length
2587 l pointer to a libnet context
2588 ptag protocol tag to modify an existing header, 0 to build a new
2589 one
2590
2591 Returns
2592 protocol tag value on success
2593
2594 Return values
2595 -1 on error
2596
2597 LIBNET_API libnet_ptag_t libnet_build_udld_hdr (uint8_t version, uint8_t
2598 opcode, uint8_t flags, uint8_t checksum, const uint8_t * payload,
2599 uint32_t payload_s, libnet_t * l, libnet_ptag_t ptag)
2600 Builds an UniDirectional Link Detection(UDLD) header. UDLD frames are
2601 usually encapsulated inside of an 802.2 + 802.3 frame combination.
2602
2603 Parameters
2604 version UDLD PDU version number
2605 opcode operation code
2606 flags flags
2607 checksum checksum (0 for libnet to auto-fill)
2608 payload optional payload or NULL
2609 payload_s payload length or 0
2610 l pointer to a libnet context
2611 ptag protocol tag to modify an existing header, 0 to build a new
2612 one
2613
2614 Returns
2615 protocol tag value on success
2616
2617 Return values
2618 -1 on error
2619
2620 LIBNET_API libnet_ptag_t libnet_build_udld_message_interval (const uint8_t
2621 * value, libnet_t * l, libnet_ptag_t ptag)
2622 Builds an UniDirectional Link Detection(UDLD) Message Interval TLV.
2623
2624 Parameters
2625 value time interval(8-bit unsigned integer)
2626 l pointer to a libnet context
2627 ptag protocol tag to modify an existing header, 0 to build a new
2628 one
2629
2630 Returns
2631 protocol tag value on success
2632
2633 Return values
2634 -1 on error
2635
2636 LIBNET_API libnet_ptag_t libnet_build_udld_port_id (const uint8_t * value,
2637 const uint8_t value_s, libnet_t * l, libnet_ptag_t ptag)
2638 Builds an UniDirectional Link Detection(UDLD) Port ID TLV.
2639
2640 Parameters
2641 value port id(ASCII character string)
2642 value_s port id(ASCII character string) length
2643 l pointer to a libnet context
2644 ptag protocol tag to modify an existing header, 0 to build a new
2645 one
2646
2647 Returns
2648 protocol tag value on success
2649
2650 Return values
2651 -1 on error
2652
2653 LIBNET_API libnet_ptag_t libnet_build_udld_sequence_number (const uint8_t *
2654 value, libnet_t * l, libnet_ptag_t ptag)
2655 Builds an UniDirectional Link Detection(UDLD) Sequence Number TLV.
2656
2657 Parameters
2658 value sequence number(32-bit unsigned integer)
2659 l pointer to a libnet context
2660 ptag protocol tag to modify an existing header, 0 to build a new
2661 one
2662
2663 Returns
2664 protocol tag value on success
2665
2666 Return values
2667 -1 on error
2668
2669 LIBNET_API libnet_ptag_t libnet_build_udld_timeout_interval (const uint8_t
2670 * value, libnet_t * l, libnet_ptag_t ptag)
2671 Builds an UniDirectional Link Detection(UDLD) Timeout Interval TLV.
2672
2673 Parameters
2674 value timeout interval(8-bit unsigned integer)
2675 l pointer to a libnet context
2676 ptag protocol tag to modify an existing header, 0 to build a new
2677 one
2678
2679 Returns
2680 protocol tag value on success
2681
2682 Return values
2683 -1 on error
2684
2685 LIBNET_API libnet_ptag_t libnet_build_udp (uint16_t sp, uint16_t dp,
2686 uint16_t len, uint16_t sum, const uint8_t * payload, uint32_t
2687 payload_s, libnet_t * l, libnet_ptag_t ptag)
2688 Builds an RFC 768 User Datagram Protocol (UDP) header.
2689
2690 Parameters
2691 sp source port
2692 dp destination port
2693 len total length of the UDP packet
2694 sum checksum (0 for libnet to auto-fill)
2695 payload optional payload or NULL
2696 payload_s payload length or 0
2697 l pointer to a libnet context
2698 ptag protocol tag to modify an existing header, 0 to build a new
2699 one
2700
2701 Returns
2702 protocol tag value on success
2703
2704 Return values
2705 -1 on error
2706
2707 LIBNET_API libnet_ptag_t libnet_build_vrrp (uint8_t version, uint8_t type,
2708 uint8_t vrouter_id, uint8_t priority, uint8_t ip_count, uint8_t
2709 auth_type, uint8_t advert_int, uint16_t sum, const uint8_t * payload,
2710 uint32_t payload_s, libnet_t * l, libnet_ptag_t ptag)
2711 Builds an RFC 2338 Virtual Router Redundacy Protool (VRRP) header. Use
2712 the payload interface to specify address and authentication
2713 information. To build a 'legal' packet, the destination IPv4 address
2714 should be the multicast * address 224.0.0.18, the IP TTL should be set
2715 to 255, and the IP protocol should be set to 112.
2716
2717 Parameters
2718 version VRRP version (should be 2)
2719 type VRRP packet type (should be 1 -- ADVERTISEMENT)
2720 vrouter_id virtual router identification
2721 priority priority (higher numbers indicate higher priority)
2722 ip_count number of IPv4 addresses contained in this advertisement
2723 auth_type type of authentication (0, 1, 2 -- see RFC)
2724 advert_int interval between advertisements
2725 sum checksum (0 for libnet to autofill)
2726 payload optional payload or NULL
2727 payload_s payload length or 0
2728 l pointer to a libnet context
2729 ptag protocol tag to modify an existing header, 0 to build a new
2730 one
2731
2732 Returns
2733 protocol tag value on success
2734
2735 Return values
2736 -1 on error
2737
2738 LIBNET_API void libnet_clear_packet (libnet_t * l)
2739 Clears the current packet referenced and frees all pblocks. Should be
2740 called when the programmer want to send a completely new packet of a
2741 different type using the same context.
2742
2743 Parameters
2744 l pointer to a libnet context
2745
2746 int libnet_cq_add (libnet_t * l, char * label)
2747 [Context Queue] Adds a new context to the libnet context queue. If no
2748 queue exists, this function will create the queue and add the specified
2749 libnet context as the first entry on the list. The functions checks to
2750 ensure niether l nor label are NULL, and that label doesn't refer to an
2751 existing context already in the queue. Additionally, l should refer to
2752 a libnet context previously initialized with a call to libnet_init().
2753 If the context queue in write locked, this function will fail.
2754
2755 Parameters
2756 l pointer to a libnet context
2757 label a canonical name given to recognize the new context, no
2758 longer than LIBNET_LABEL_SIZE
2759
2760 Return values
2761 1 on success
2762 -1 on failure
2763
2764 LIBNET_API void libnet_cq_destroy (void)
2765 [Context Queue] Destroys the entire context queue, calling
2766 libnet_destroy() on each member context.
2767
2768 LIBNET_API uint32_t libnet_cq_end_loop (void)
2769 [Context Queue] Cleanup from iterating through the context queue.
2770
2771 Return values
2772 1 Cleanup completed OK
2773 0 failed clearing the write lock
2774
2775 LIBNET_API libnet_t * libnet_cq_find_by_label (char * label)
2776 [Context Queue] Locates a libnet context from the queue, indexed by a
2777 canonical label.
2778
2779 Parameters
2780 label canonical label of the libnet context to retrieve
2781
2782 Returns
2783 the expected libnet context
2784
2785 Return values
2786 NULL on failure
2787
2788 LIBNET_API const char * libnet_cq_getlabel (libnet_t * l)
2789 [Context Queue] Returns the canonical label associated with the
2790 context.
2791
2792 Parameters
2793 l pointer to a libnet context
2794
2795 Returns
2796 pointer to the libnet context's label
2797
2798 LIBNET_API libnet_t * libnet_cq_head (void)
2799 [Context Queue] Intiailizes the interator interface and set a write
2800 lock on the entire queue. This function is intended to be called just
2801 prior to interating through the entire list of contexts (with the
2802 probable intent of inject a series of packets in rapid succession).
2803 This function is often used as per the following:
2804
2805 for (l = libnet_cq_head(); libnet_cq_last(); l = libnet_cq_next()) {
2806 ... }
2807
2808 Much of the time, the application programmer will use the iterator as
2809 it is written above; as such, libnet provides a macro to do exactly
2810 that, for_each_context_in_cq(l). Warning: do not call the iterator more
2811 than once in a single loop.
2812
2813 Returns
2814 the head of the context queue
2815
2816 LIBNET_API int libnet_cq_last (void)
2817 [Context Queue] Check whether the iterator is at the last context in
2818 the queue.
2819
2820 Return values
2821 1 if at the end of the context queue
2822 0 otherwise
2823
2824 LIBNET_API libnet_t * libnet_cq_next (void)
2825 [Context Queue] Get next context from the context queue.
2826
2827 Returns
2828 the next context from the context queue
2829
2830 LIBNET_API libnet_t * libnet_cq_remove (libnet_t * l)
2831 [Context Queue] Removes a specified context from the libnet context
2832 queue by specifying the libnet context pointer. Note the function will
2833 remove the specified context from the context queue and cleanup
2834 internal memory from the queue, it is up to the application programmer
2835 to free the returned libnet context with a call to libnet_destroy().
2836 Also, as it is not necessary to keep the libnet context pointer when
2837 initially adding it to the context queue, most application programmers
2838 will prefer to refer to entries on the context queue by canonical name
2839 and would use libnet_cq_remove_by_label(). If the context queue is
2840 write locked, this function will fail.
2841
2842 Parameters
2843 l pointer to a libnet context
2844
2845 Returns
2846 the pointer to the removed libnet context
2847
2848 Return values
2849 NULL on failure
2850
2851 LIBNET_API libnet_t * libnet_cq_remove_by_label (char * label)
2852 [Context Queue] Removes a specified context from the libnet context
2853 queue by specifying the canonical name. Note the function will remove
2854 the specified context from the context queue and cleanup internal
2855 memory from the queue, it is up to the application programmer to free
2856 the returned libnet context with a call to libnet_destroy(). If the
2857 context queue is write locked, this function will fail.
2858
2859 Parameters
2860 label canonical name of the context to remove
2861
2862 Returns
2863 the pointer to the removed libnet context
2864
2865 Return values
2866 NULL on failure
2867
2868 LIBNET_API uint32_t libnet_cq_size (void)
2869 [Context Queue] Function returns the number of libnet contexts that are
2870 in the queue.
2871
2872 Returns
2873 the number of libnet contexts currently in the queue
2874
2875 LIBNET_API void libnet_destroy (libnet_t * l)
2876 Shuts down the libnet session referenced by l. It closes the network
2877 interface and frees all internal memory structures associated with l.
2878
2879
2880 Parameters
2881 l pointer to a libnet context
2882
2883 LIBNET_API void libnet_diag_dump_context (libnet_t * l)
2884 [Diagnostic] Prints the contents of the given context.
2885
2886 Parameters
2887 l pointer to a libnet context
2888
2889 void libnet_diag_dump_hex (const uint8_t * packet, uint32_t len, int swap,
2890 FILE * stream)
2891 [Diagnostic] Function prints the contents of the supplied buffer to the
2892 supplied stream pointer. Will swap endianness based disposition of mode
2893 variable. Useful to be used in conjunction with the advanced interface
2894 and a culled packet.
2895
2896 Parameters
2897 packet the packet to print
2898 len length of the packet in bytes
2899 swap 1 to swap byte order, 0 to not. Counter-intuitively, it is
2900 necessary to swap in order to see the byte order as it is on the
2901 wire (this may be a bug).
2902 stream a stream pointer to print to
2903
2904 LIBNET_API void libnet_diag_dump_pblock (libnet_t * l)
2905 [Diagnostic] Prints the contents of every pblock.
2906
2907 Parameters
2908 l pointer to a libnet context
2909
2910 LIBNET_API char * libnet_diag_dump_pblock_type (uint8_t type)
2911 [Diagnostic] Returns the canonical name of the pblock type.
2912
2913 Parameters
2914 type pblock type
2915
2916 Returns
2917 a string representing the pblock type type
2918
2919 Return values
2920 unknown for an unknown value
2921
2922 LIBNET_API struct libnet_ether_addr * libnet_get_hwaddr (libnet_t * l)
2923 Returns the MAC address for the device libnet was initialized with. If
2924 libnet was initialized without a device the function will attempt to
2925 find one. If the function fails and returns NULL a call to
2926 libnet_geterror() will tell you why.
2927
2928 Parameters
2929 l pointer to a libnet context
2930
2931 Returns
2932 a pointer to the MAC address or NULL
2933
2934 LIBNET_API uint32_t libnet_get_ipaddr4 (libnet_t * l)
2935 Returns the IP address for the device libnet was initialized with. If
2936 libnet was initialized without a device (in raw socket mode) the
2937 function will attempt to find one. If the function fails and returns -1
2938 a call to libnet_geterrror() will tell you why.
2939
2940 Parameters
2941 l pointer to a libnet context
2942
2943 Returns
2944 a big endian IP address suitable for use in a libnet_build function
2945
2946 Return values
2947 -1
2948
2949 LIBNET_API struct libnet_in6_addr libnet_get_ipaddr6 (libnet_t * l)
2950 Returns the IPv6 address for the device libnet was initialized with. If
2951 libnet was initialized without a device (in raw socket mode) the
2952 function will attempt to find one. If the function fails and returns
2953 in6addr_error, a call to libnet_geterrror() will tell you why. This
2954 function is not yet implemented for Win32 platforms.
2955
2956 Parameters
2957 l pointer to a libnet context
2958
2959 Return values
2960 in6addr_error on failure
2961
2962 LIBNET_API uint32_t libnet_get_prand (int mod)
2963 Generates an unsigned pseudo-random value within the range specified by
2964 mod. LIBNET_PR2 0 - 1 LIBNET_PR8 0 - 255 LIBNET_PR16 0 - 32767
2965 LIBNET_PRu16 0 - 65535 LIBNET_PR32 0 - 2147483647 LIBNET_PRu32 0 -
2966 4294967295
2967
2968 Parameters
2969 mod one the of LIBNET_PR* constants
2970
2971 Return values
2972 1 on success
2973 -1 on failure
2974
2975 LIBNET_API const char * libnet_getdevice (libnet_t * l)
2976 Returns the canonical name of the device used for packet injection.
2977
2978 Parameters
2979 l pointer to a libnet context
2980
2981 Returns
2982 the canonical name of the device used for packet injection. Note it
2983 can be NULL without being an error.
2984
2985 LIBNET_API char * libnet_geterror (libnet_t * l)
2986 Returns the last error set inside of the referenced libnet context.
2987 This function should be called anytime a function fails or an error
2988 condition is detected inside of libnet.
2989
2990 Parameters
2991 l pointer to a libnet context
2992
2993 Returns
2994 an error string or NULL if no error has occurred
2995
2996 LIBNET_API int libnet_getfd (libnet_t * l)
2997 Returns the FILENO of the file descriptor used for packet injection.
2998
2999 Parameters
3000 l pointer to a libnet context
3001
3002 Returns
3003 the file number of the file descriptor used for packet injection
3004
3005 LIBNET_API uint32_t libnet_getgre_length (uint16_t fv)
3006 Parameters
3007 fv see libnet_build_gre().
3008
3009 Returns
3010 size
3011
3012 See also
3013 libnet_build_gre().
3014
3015 LIBNET_API uint32_t libnet_getpacket_size (libnet_t * l)
3016 Returns the sum of the size of all of the pblocks inside of l (this
3017 should be the resulting packet size).
3018
3019 Parameters
3020 l pointer to a libnet context
3021
3022 Returns
3023 the size of the packet in l
3024
3025 LIBNET_API uint8_t * libnet_getpbuf (libnet_t * l, libnet_ptag_t ptag)
3026 Returns the pblock buffer contents for the specified ptag; a subsequent
3027 call to libnet_getpbuf_size() should be made to determine the size of
3028 the buffer.
3029
3030 Parameters
3031 l pointer to a libnet context
3032 ptag the ptag reference number
3033
3034 Returns
3035 a pointer to the pblock buffer or NULL on error
3036
3037 LIBNET_API uint32_t libnet_getpbuf_size (libnet_t * l, libnet_ptag_t ptag)
3038 Returns the pblock buffer size for the specified ptag; a previous call
3039 to libnet_getpbuf() should be made to pull the actual buffer contents.
3040
3041 Parameters
3042 l pointer to a libnet context
3043 ptag the ptag reference number
3044
3045 Returns
3046 the size of the pblock buffer
3047
3048 LIBNET_API uint8_t * libnet_hex_aton (const char * s, int * len)
3049 Takes a colon separated hexidecimal address (from the command line) and
3050 returns a bytestring suitable for use in a libnet_build function. Note
3051 this function performs an implicit malloc and the return value should
3052 be freed after its use.
3053
3054 Parameters
3055 s the string to be parsed
3056 len the resulting size of the returned byte string
3057
3058 Returns
3059 a byte string or NULL on failure
3060
3061 LIBNET_API int libnet_in6_is_error (struct libnet_in6_addr addr)
3062 Check a libnet_in6_addr structure for identity with in6addr_error.
3063
3064 Parameters
3065 addr address to check
3066
3067 Return values
3068 1 if addr is in6addr_error
3069 0 if it is not
3070
3071 LIBNET_API libnet_t * libnet_init (int injection_type, const char * device,
3072 char * err_buf)
3073 Creates the libnet environment. It initializes the library and returns
3074 a libnet context. If the injection_type is LIBNET_LINK or
3075 LIBNET_LINK_ADV, the function initializes the injection primitives for
3076 the link-layer interface enabling the application programmer to build
3077 packets starting at the data-link layer (which also provides more
3078 granular control over the IP layer). If libnet uses the link-layer and
3079 the device argument is non-NULL, the function attempts to use the
3080 specified network device for packet injection. This is either a
3081 canonical string that references the device (such as 'eth0' for a 100MB
3082 Ethernet card on Linux or 'fxp0' for a 100MB Ethernet card on OpenBSD)
3083 or the dots and decimals representation of the device's IP address
3084 (192.168.0.1). If device is NULL, libnet attempts to find a suitable
3085 device to use. If the injection_type is LIBNET_RAW4 or LIBNET_RAW4_ADV,
3086 the function initializes the injection primitives for the IPv4 raw
3087 socket interface. The final argument, err_buf, should be a buffer of
3088 size LIBNET_ERRBUF_SIZE and holds an error message if the function
3089 fails. This function requires root privileges to execute successfully.
3090 Upon success, the function returns a valid libnet context for use in
3091 later function calls; upon failure, the function returns NULL.
3092
3093 Parameters
3094 injection_type packet injection type (LIBNET_LINK, LIBNET_LINK_ADV,
3095 LIBNET_RAW4, LIBNET_RAW4_ADV, LIBNET_RAW6, LIBNET_RAW6_ADV)
3096 device the interface to use (NULL and libnet will choose one)
3097 err_buf will contain an error message on failure
3098
3099 Returns
3100 libnet context ready for use or NULL on error.
3101
3102 LIBNET_API uint32_t libnet_name2addr4 (libnet_t * l, const char *
3103 host_name, uint8_t use_name)
3104 Takes a dotted decimal string or a canonical DNS name and returns a
3105 network byte ordered IPv4 address. This may incur a DNS lookup if mode
3106 is set to LIBNET_RESOLVE and host_name refers to a canonical DNS name.
3107 If mode is set to LIBNET_DONT_RESOLVE no DNS lookup will occur. The
3108 function can fail if DNS lookup fails or if mode is set to
3109 LIBNET_DONT_RESOLVE and host_name refers to a canonical DNS name.
3110
3111 Parameters
3112 l pointer to a libnet context
3113 host_name pointer to a string containing a presentation format host
3114 name
3115 use_name LIBNET_RESOLVE or LIBNET_DONT_RESOLVE
3116
3117 Returns
3118 address in network byte order
3119
3120 Return values
3121 -1 (2^32 - 1) on error
3122
3123 LIBNET_API struct libnet_in6_addr libnet_name2addr6 (libnet_t * l, const
3124 char * host_name, uint8_t use_name)
3125 Takes a dotted decimal string or a canonical DNS name and returns a
3126 network byte ordered IPv6 address. This may incur a DNS lookup if mode
3127 is set to LIBNET_RESOLVE and host_name refers to a canonical DNS name.
3128 If mode is set to LIBNET_DONT_RESOLVE no DNS lookup will occur. The
3129 function can fail if DNS lookup fails or if mode is set to
3130 LIBNET_DONT_RESOLVE and host_name refers to a canonical DNS name.
3131
3132 Parameters
3133 l pointer to a libnet context
3134 host_name pointer to a string containing a presentation format host
3135 name
3136 use_name LIBNET_RESOLVE or LIBNET_DONT_RESOLVE
3137
3138 Returns
3139 network byte ordered IPv6 address structure
3140
3141 LIBNET_API int libnet_plist_chain_dump (libnet_plist_t * plist)
3142 Runs through the port list and prints the contents of the port list
3143 chain list to stdout.
3144
3145 Parameters
3146 plist previously created portlist
3147
3148 Return values
3149 1 on success
3150 -1 on failure
3151
3152 LIBNET_API char * libnet_plist_chain_dump_string (libnet_plist_t * plist)
3153 Runs through the port list and prints the contents of the port list
3154 chain list to string. This function uses strdup and is not re-entrant.
3155 It also has a memory leak and should not really be used.
3156
3157 Parameters
3158 plist previously created portlist
3159
3160 Returns
3161 a printable string containing the port list contents on success or
3162 NULL on error
3163
3164 LIBNET_API int libnet_plist_chain_free (libnet_plist_t * plist)
3165 Frees all memory associated with port list chain.
3166
3167 Parameters
3168 plist previously created portlist
3169
3170 Return values
3171 1 on success
3172 -1 on failure
3173
3174 LIBNET_API int libnet_plist_chain_new (libnet_t * l, libnet_plist_t **
3175 plist, char * token_list)
3176 Creates a new port list. Port list chains are useful for TCP and UDP-
3177 based applications that need to send packets to a range of ports
3178 (contiguous or otherwise). The port list chain, which token_list points
3179 to, should contain a series of int8_tacters from the following list:
3180 '0123456789,-' of the general format 'x - y, z', where 'xyz' are port
3181 numbers between 0 and 65,535. plist points to the front of the port
3182 list chain list for use in further libnet_plist_chain() functions. Upon
3183 success, the function returns
3184
3185 1. Upon failure, the function returns -1 and libnet_geterror() can
3186 tell you why.
3187
3188 Parameters
3189 l pointer to a libnet context
3190 plist if successful, will refer to the portlist, if not, NULL
3191 token_list string containing the port list primitive
3192
3193 Return values
3194 1 on success
3195 -1 on failure
3196
3197 LIBNET_API int libnet_plist_chain_next_pair (libnet_plist_t * plist,
3198 uint16_t * bport, uint16_t * eport)
3199 Returns the next port list chain pair from the port list chain plist.
3200 bport and eport contain the starting port number and ending port
3201 number, respectively. Upon success, the function returns 1 and fills in
3202 the port variables; however, if the list is empty, the function returns
3203 0 and sets both port variables to 0. Upon failure, the function returns
3204 -1.
3205
3206 Parameters
3207 plist previously created portlist
3208 bport will contain the beginning port number or 0
3209 eport will contain the ending port number or 0
3210
3211 Return values
3212 1 on success
3213 0 if empty
3214 -1 on failure
3215
3216 LIBNET_API int libnet_seed_prand (libnet_t * l)
3217 Seeds the pseudo-random number generator.
3218
3219 Parameters
3220 l pointer to a libnet context
3221
3222 Return values
3223 1 on success
3224 -1 on failure
3225
3226 LIBNET_API void libnet_stats (libnet_t * l, struct libnet_stats * ls)
3227 Fills in a libnet_stats structure with packet injection statistics
3228 (packets written, bytes written, packet sending errors).
3229
3230 Parameters
3231 l pointer to a libnet context
3232 ls pointer to a libnet statistics structure
3233
3234 LIBNET_API int libnet_toggle_checksum (libnet_t * l, libnet_ptag_t ptag,
3235 int mode)
3236 If a given protocol header is built with the checksum field set to '0',
3237 by default libnet will calculate the header checksum prior to
3238 injection. If the header is set to any other value, by default libnet
3239 will not calculate the header checksum. To over-ride this behavior, use
3240 libnet_toggle_checksum(). Switches auto-checksumming on or off for the
3241 specified ptag. If mode is set to LIBNET_ON, libnet will mark the
3242 specified ptag to calculate a checksum for the ptag prior to injection.
3243 This assumes that the ptag refers to a protocol that has a checksum
3244 field. If mode is set to LIBNET_OFF, libnet will clear the checksum
3245 flag and no checksum will be computed prior to injection. This assumes
3246 that the programmer will assign a value (zero or otherwise) to the
3247 checksum field. Often times this is useful if a precomputed checksum or
3248 some other predefined value is going to be used. Note that when libnet
3249 is initialized with LIBNET_RAW4, the IPv4 header checksum will always
3250 be computed by the kernel prior to injection, regardless of what the
3251 programmer sets.
3252
3253 Parameters
3254 l pointer to a libnet context
3255 ptag the ptag reference number
3256 mode LIBNET_ON or LIBNET_OFF
3257
3258 Return values
3259 1 on success
3260 -1 on failure
3261
3262 LIBNET_API const char * libnet_version (void)
3263 Returns the version of libnet.
3264
3265 Returns
3266 the libnet version
3267
3268 LIBNET_API int libnet_write (libnet_t * l)
3269 Writes a prebuilt packet to the network. The function assumes that l
3270 was previously initialized (via a call to libnet_init()) and that a
3271 previously constructed packet has been built inside this context (via
3272 one or more calls to the libnet_build* family of functions) and is
3273 ready to go. Depending on how libnet was initialized, the function will
3274 write the packet to the wire either via the raw or link layer
3275 interface. The function will also bump up the internal libnet stat
3276 counters which are retrievable via libnet_stats().
3277
3278 Parameters
3279 l pointer to a libnet context
3280
3281 Returns
3282 the number of bytes written
3283
3284 Return values
3285 -1 on error
3286
3288 libnet(3)
3289
3291 The original author of libnet is Mike D. Schiffman.
3292
3293 libnet has been maintained and extensively enhanced since 2009 by Sam
3294 Roberts.
3295
3296 It is maintained by the Libnet Developer Community at GitHub.
3297
3298 <https://github.com/libnet/libnet>
3299
3301 Suggestions, bug reports/fixes, and pull requests, see:
3302
3303 <https://github.com/libnet/libnet/issues>
3304
3306 libnet is licensed under the 2-Clause BSD License.
3307
3309 libnet(3)
3310
3312 The original author of libnet is Mike D. Schiffman.
3313
3314 libnet has been maintained and extensively enhanced since 2009 by Sam
3315 Roberts.
3316
3317 It is maintained by the Libnet Developer Community at GitHub.
3318
3319 <https://github.com/libnet/libnet>
3320
3322 Suggestions, bug reports/fixes, and pull requests, see:
3323
3324 <https://github.com/libnet/libnet/issues>
3325
3327 libnet is licensed under the 2-Clause BSD License.
3328
3329
3330
3331libnet-1.3 Tue Oct 3 2023 libnet-functions.h(3)