📄 msgparser_test.c
字号:
/* $Id: msgparser_test.c,v 1.2 2001/07/13 16:55:47 jm Exp $ * * Message parser tests * * Dynamic hierarchial IP tunnel * Copyright (C) 2001, Dynamics group * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. See README and COPYING for * more details. */#define DEBUG_FLAG 'p'#include "debug.h"#include "message.h"#include "msgparser.h"static char test_msg_1[] = { /* registration request */ 0x01, 0x00, 0x01, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, /* MN-HA auth. */ 32, 20, 1, 2, 3, 4, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};static char test_msg_2[] = { /* registration request */ 0x01, 0x00, 0x01, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, /* gen. MN-FA key req. */ 40, 7, 0, 20, 0, 0, 1, 44, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, /* gen. MN-FA key rep. */ 41, 7, 0, 16, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, /* gen. MN-HA key req. */ 42, 7, 0, 20, 0, 0, 1, 45, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, /* gen. MN-HA key rep. */ 43, 1, 0, 20, 0, 0, 1, 244, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, /* MN-HA auth. */ 32, 20, 0, 0, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};static char test_msg_3[] = { /* registration request */ 0x01, 0x00, 0x01, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, /* gen. MN-FA key req. */ 40, 7, 0, 20, 0, 0, 1, 44, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, /* gen. MN-FA key rep. */ 41, 7, 0, 16, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, /* gen. MN-HA key req. */ 42, 7, 0, 20, 0, 0, 1, 45, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, /* gen. MN-HA key rep. */ 43, 1, 0, 20, 0, 0, 1, 244, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, /* gen. FA-HA key rep. */ 45, 1, 0, 20, 0, 0, 1, 245, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, /* gen. FA-FA key rep. */ 46, 1, 0, 20, 0, 0, 1, 46, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, /* MN-HA auth. */ 32, 20, 0, 0, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};extern int opt_debug;int main(void){ struct msg_extensions ext; int res, ret = 0; opt_debug = 1; printf("Message parser test\n\n"); printf("Case 1: A valid registration request\n"); res = parse_msg(test_msg_1, sizeof(test_msg_1), &ext); printf("parse_msg res: %i\n", res); if (res != 0 || ext.req == NULL || ext.mh_auth == NULL) { printf("Case 1 FAILED\n"); ret = -1; } printf("\n"); printf("Case 2: Generalized key extensions\n"); res = parse_msg(test_msg_2, sizeof(test_msg_2), &ext); printf("parse_msg res: %i\n", res); if (res != 0) { printf("Case 2 FAILED\n"); ret = -1; } printf("\n"); printf("Case 3: Generalized key extensions with unknown subtypes\n"); res = parse_msg(test_msg_3, sizeof(test_msg_3), &ext); printf("parse_msg res: %i\n", res); if (res != -1) { printf("Case 3 FAILED\n"); ret = -1; } printf("\n"); if (ret) printf("\nAt least one of the tests failed!\n"); return ret;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -