Annotation of embedaddon/libnet/src/libnet_build_sebek.c, revision 1.1.1.3
1.1 misho 1: /*
2: * libnet
3: * libnet_build_sebek.c - sebek packet assembler
4: *
5: * Copyright (c) 2004 Frederic Raynal <pappy@security-labs.org>
6: * Copyright (c) 1998 - 2004 Mike D. Schiffman <mike@infonexus.com>
7: * All rights reserved.
8: *
9: * Redistribution and use in source and binary forms, with or without
10: * modification, are permitted provided that the following conditions
11: * are met:
12: * 1. Redistributions of source code must retain the above copyright
13: * notice, this list of conditions and the following disclaimer.
14: * 2. Redistributions in binary form must reproduce the above copyright
15: * notice, this list of conditions and the following disclaimer in the
16: * documentation and/or other materials provided with the distribution.
17: *
18: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21: * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28: * SUCH DAMAGE.
29: *
30: */
31:
1.1.1.3 ! misho 32: #include "common.h"
1.1 misho 33:
34: libnet_ptag_t
1.1.1.2 misho 35: libnet_build_sebek(uint32_t magic, uint16_t version, uint16_t type,
36: uint32_t counter, uint32_t time_sec, uint32_t time_usec, uint32_t pid,
37: uint32_t uid, uint32_t fd, uint8_t cmd[SEBEK_CMD_LENGTH], uint32_t length,
38: const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
1.1 misho 39: {
1.1.1.2 misho 40: uint32_t n;
1.1 misho 41: libnet_pblock_t *p;
42: struct libnet_sebek_hdr sebek_hdr;
43:
44: if (l == NULL)
45: {
46: return (-1);
47: }
48:
49: n = LIBNET_SEBEK_H + payload_s; /* size of memory block */
50:
51: /*
52: * Find the existing protocol block if a ptag is specified, or create
53: * a new one.
54: */
55: p = libnet_pblock_probe(l, ptag, n, LIBNET_PBLOCK_SEBEK_H);
56: if (p == NULL)
57: {
58: return (-1);
59: }
60:
61: memset(&sebek_hdr, 0, sizeof(sebek_hdr));
62: sebek_hdr.magic = htonl(magic);
63: sebek_hdr.version = htons(version);
64: sebek_hdr.type = htons(type);
65: sebek_hdr.counter = htonl(counter);
66: sebek_hdr.time_sec = htonl(time_sec);
67: sebek_hdr.time_usec = htonl(time_usec);
68: sebek_hdr.pid = htonl(pid);
69: sebek_hdr.uid = htonl(uid);
70: sebek_hdr.fd = htonl(fd);
1.1.1.2 misho 71: memcpy(sebek_hdr.cmd, cmd, SEBEK_CMD_LENGTH*sizeof(uint8_t));
1.1 misho 72: sebek_hdr.length = htonl(length);
73:
1.1.1.2 misho 74: n = libnet_pblock_append(l, p, (uint8_t *)&sebek_hdr, LIBNET_SEBEK_H);
1.1 misho 75: if (n == -1)
76: {
77: goto bad;
78: }
79:
1.1.1.2 misho 80: /* boilerplate payload sanity check / append macro */
81: LIBNET_DO_PAYLOAD(l, p);
1.1 misho 82:
83: return (ptag ? ptag : libnet_pblock_update(l, p, 0, LIBNET_PBLOCK_SEBEK_H));
84: bad:
85: libnet_pblock_delete(l, p);
86: return (-1);
87: }
1.1.1.3 ! misho 88:
! 89: /**
! 90: * Local Variables:
! 91: * indent-tabs-mode: nil
! 92: * c-file-style: "stroustrup"
! 93: * End:
! 94: */
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>