2 * Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 2000, 2001 Internet Software Consortium.
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15 * PERFORMANCE OF THIS SOFTWARE.
18 /* $Id: lwpacket.c,v 1.13.206.1 2004/03/06 08:15:32 marka Exp $ */
26 #include <lwres/lwbuffer.h>
27 #include <lwres/lwpacket.h>
28 #include <lwres/result.h>
32 #define LWPACKET_LENGTH \
33 (sizeof(lwres_uint16_t) * 4 + sizeof(lwres_uint32_t) * 5)
36 lwres_lwpacket_renderheader(lwres_buffer_t
*b
, lwres_lwpacket_t
*pkt
) {
40 if (!SPACE_OK(b
, LWPACKET_LENGTH
))
41 return (LWRES_R_UNEXPECTEDEND
);
43 lwres_buffer_putuint32(b
, pkt
->length
);
44 lwres_buffer_putuint16(b
, pkt
->version
);
45 lwres_buffer_putuint16(b
, pkt
->pktflags
);
46 lwres_buffer_putuint32(b
, pkt
->serial
);
47 lwres_buffer_putuint32(b
, pkt
->opcode
);
48 lwres_buffer_putuint32(b
, pkt
->result
);
49 lwres_buffer_putuint32(b
, pkt
->recvlength
);
50 lwres_buffer_putuint16(b
, pkt
->authtype
);
51 lwres_buffer_putuint16(b
, pkt
->authlength
);
53 return (LWRES_R_SUCCESS
);
57 lwres_lwpacket_parseheader(lwres_buffer_t
*b
, lwres_lwpacket_t
*pkt
) {
63 space
= LWRES_BUFFER_REMAINING(b
);
64 if (space
< LWPACKET_LENGTH
)
65 return (LWRES_R_UNEXPECTEDEND
);
67 pkt
->length
= lwres_buffer_getuint32(b
);
69 * XXXBEW/MLG Checking that the buffer is long enough probably
70 * shouldn't be done here, since this function is supposed to just
73 if (pkt
->length
> space
)
74 return (LWRES_R_UNEXPECTEDEND
);
75 pkt
->version
= lwres_buffer_getuint16(b
);
76 pkt
->pktflags
= lwres_buffer_getuint16(b
);
77 pkt
->serial
= lwres_buffer_getuint32(b
);
78 pkt
->opcode
= lwres_buffer_getuint32(b
);
79 pkt
->result
= lwres_buffer_getuint32(b
);
80 pkt
->recvlength
= lwres_buffer_getuint32(b
);
81 pkt
->authtype
= lwres_buffer_getuint16(b
);
82 pkt
->authlength
= lwres_buffer_getuint16(b
);
84 return (LWRES_R_SUCCESS
);