]>
git.ipfire.org Git - people/ms/strongswan.git/blob - src/libfreeswan/liblwres/lwpacket.c
2 * Copyright (C) 2000, 2001 Internet Software Consortium.
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
9 * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
10 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
11 * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
12 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
13 * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
14 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
15 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 /* $Id: lwpacket.c,v 1.1 2004/03/15 20:35:25 as 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
);