1
/* hdr_check.c - Perform basic sanity checks on received packet.
3
* Copyright (C) 2010, Pawel Krawczyk <pawel.krawczyk@hush.com> and
4
* Jeroen Nijhof <jeroen@nijhofnet.nl>
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program - see the file COPYING.
19
* See `CHANGES' file for revision history.
26
/* Checks given reply header for possible inconsistencies:
27
* 1. reply type other than expected
28
* 2. sequence number other than 2 or 4
29
* 3. session_id different from one sent in request
30
* Returns pointer to error message
31
* or NULL when the header seems to be correct
33
char *_tac_check_header(HDR *th, int type) {
34
if(th->type != type) {
36
"%s: unrelated reply, type %d, expected %d",\
37
__FUNCTION__, th->type, type))
38
return protocol_err_msg;
39
} else if((th->seq_no != 2) && (th->seq_no != 4)) {
40
TACSYSLOG((LOG_ERR, "%s: not a reply - seq_no %d != {2,4}",\
41
__FUNCTION__, th->seq_no))
42
return protocol_err_msg;
43
} /* else if(ntohl(th->session_id) != session_id) {
45
"%s: unrelated reply, received session_id %d != sent %d",\
46
__FUNCTION__, ntohl(th->session_id), session_id))
47
return protocol_err_msg;
50
return NULL; /* header is ok */