Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / verif / env / common / vera / niu_ippktgen / C / libnet / src / libnet_build_pim.c
CommitLineData
86530b38
AT
1#if (HAVE_CONFIG_H)
2#include "../include/config.h"
3#endif
4#if (!(_WIN32) || (__CYGWIN__))
5#include "../include/libnet.h"
6#else
7#include "../include/win32/libnet.h"
8#endif
9
10libnet_ptag_t
11libnet_build_pim(u_int8_t vers, u_int8_t type, u_int16_t chksum,
12 u_int8_t *payload, u_int32_t payload_s, libnet_t *l,
13 libnet_ptag_t ptag)
14{
15 u_int32_t n, h;
16 libnet_pblock_t *p;
17 struct libnet_pim_hdr pim_hdr;
18
19 if (l == NULL)
20 {
21 return (-1);
22 }
23
24 n = LIBNET_PIM_H + payload_s;
25 h = LIBNET_PIM_H;
26
27 /*
28 * Find the existing protocol block if a ptag is specified, or create
29 * a new one.
30 */
31 p = libnet_pblock_probe(l, ptag, n, LIBNET_PBLOCK_PIM_H);
32 if (p == NULL)
33 {
34 return (-1);
35 }
36
37 memset(&pim_hdr, 0, sizeof(pim_hdr));
38 pim_hdr.pim_ver_type = (vers << 4) | (type & 0x0f); /* version and type */
39 pim_hdr.pim_sum = (chksum ? htons(chksum) : 0); /* checksum */
40
41 n = libnet_pblock_append(l, p, (u_int8_t *)&pim_hdr, LIBNET_PIM_H);
42 if (n == -1)
43 {
44 goto bad;
45 }
46
47 if ((payload && !payload_s) || (!payload && payload_s))
48 {
49 snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
50 "%s(): payload inconsistency\n", __func__);
51 goto bad;
52 }
53
54 if (payload && payload_s)
55 {
56 n = libnet_pblock_append(l, p, payload, payload_s);
57 if (n == -1)
58 {
59 goto bad;
60 }
61 }
62 if (chksum == 0)
63 {
64 /*
65 * If checksum is zero, by default libnet will compute a checksum
66 * for the user. The programmer can override this by calling
67 * libnet_toggle_checksum(l, ptag, 1);
68 */
69 libnet_pblock_setflags(p, LIBNET_PBLOCK_DO_CHECKSUM);
70 }
71
72
73 return (ptag ? ptag : libnet_pblock_update(l, p, h, LIBNET_PBLOCK_PIM_H));
74bad:
75 libnet_pblock_delete(l, p);
76 return (-1);
77}
78
79/* EOF */