diff --git a/Makefile b/Makefile index b05093c6..4d3ffd6d 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/fko_test.c b/fko_test.c index 1d68efa0..7486f560 100644 --- a/fko_test.c +++ b/fko_test.c @@ -38,16 +38,28 @@ int main(int argc, char **argv) * Get a random 16-byte string of hex values. */ spa_random_number(&sm); - printf(" SPA_RAND_VAL: %s\n", sm.rand_val); + 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); + 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); } diff --git a/fwknop.h b/fwknop.h index 261326cc..36e7a691 100644 --- a/fwknop.h +++ b/fwknop.h @@ -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); diff --git a/spa_timestamp.c b/spa_timestamp.c new file mode 100644 index 00000000..a6770445 --- /dev/null +++ b/spa_timestamp.c @@ -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 + +unsigned int spa_timestamp(spa_message_t *sm, int offset) +{ + sm->timestamp = time(NULL) + offset; + return(sm->timestamp); +} + +/***EOF***/