Added spa_timestamp function.

git-svn-id: file:///home/mbr/svn/fwknop/trunk@4 510a4753-2344-4c79-9c09-4d669213fbeb
This commit is contained in:
Damien Stuart 2008-11-29 21:59:08 +00:00
parent 12fce24403
commit 2564d103f0
4 changed files with 56 additions and 7 deletions

View File

@ -53,6 +53,7 @@ PROG = fko_test
SRCS = fko_test.c \
spa_random_number.c \
spa_user.c \
spa_timestamp.c \
strlcat.c \
strlcpy.c
@ -98,3 +99,4 @@ depend:
fko_test.o: fwknop.h
spa_random_number.o: fwknop.h
spa_user.o: fwknop.h
spa_timestamp.o: fwknop.h

View File

@ -41,13 +41,25 @@ int main(int argc, char **argv)
printf(" SPA_RAND_VAL: %s\n", sm.rand_val);
/*********************************************************************
* Get the current user, then s spoofed user.
* Get the current user, then a spoofed user.
*/
spa_user(&sm, NULL);
printf(" SPA_USER: %s\n", sm.user);
spa_user(&sm, "bubba");
printf("SPA_USER (spoof): %s\n", sm.user);
printf(" SPA_USER (spoof): %s\n", sm.user);
/*********************************************************************
* Get the timestamp, then with an positive and negative offset.
*/
spa_timestamp(&sm, 0);
printf(" SPA_TIMESTAMP: %u\n", sm.timestamp);
spa_timestamp(&sm, 300);
printf("SPA_TIMESTAMP (+300): %u\n", sm.timestamp);
spa_timestamp(&sm, -600);
printf("SPA_TIMESTAMP (-600): %u\n", sm.timestamp);
return(0);
}

View File

@ -107,13 +107,13 @@ typedef struct _spa_message {
*/
char* spa_random_number(spa_message_t *sm);
char* spa_user(spa_message_t *sm, char *spoof_user);
char* spa_timestamp(spa_message_t *sm);
unsigned int spa_timestamp(spa_message_t *sm, int offset);
char* spa_version(spa_message_t *sm);
char* spa_message_type(spa_message_t *sm);
unsigned short spa_message_type(spa_message_t *sm);
char* spa_message(spa_message_t *sm);
char* spa_nat_access(spa_message_t *sm);
char* spa_server_auth(spa_message_t *sm);
char* spa_client_timeout(spa_message_t *sm);
unsigned int spa_client_timeout(spa_message_t *sm);
char* spa_digest(spa_message_t *sm);
size_t strlcat(char *dst, const char *src, size_t siz);

35
spa_timestamp.c Normal file
View File

@ -0,0 +1,35 @@
/* $Id$
*****************************************************************************
*
* File: spa_timestamp.c
*
* Author: Damien S. Stuart
*
* Purpose: Get the current timestamp with optional offset applied.
*
* Copyright (C) 2008 Damien Stuart (dstuart@dstuart.org)
*
* License (GNU Public License):
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*
*****************************************************************************
*/
#include "fwknop.h"
#include <time.h>
unsigned int spa_timestamp(spa_message_t *sm, int offset)
{
sm->timestamp = time(NULL) + offset;
return(sm->timestamp);
}
/***EOF***/