📄 replytest.c
字号:
/* $Id: replytest.c,v 1.11 2000/04/06 07:26:53 jm Exp $ * Program for sending test replies * * Dynamic hierarchial IP tunnel * Copyright (C) 1998-2000, 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. */#include <sys/types.h>#include <sys/socket.h>#include <netinet/in.h>#include <string.h>#include <stdio.h>#include <arpa/inet.h>#include <unistd.h>#include <stdlib.h>#include <errno.h>#include <getopt.h>#include "md5_mac.h"#include "message.h"#include "msgparser.h"#include "util.h"#define MAXMSG 1024#define SHARED "1234567812345678"#define AUTHLEN 16#define KEY "1234567812345678"#define KEYLEN 16static intsend_reg_repl(int s){ char msg[MAXMSG]; struct reg_rep *reply = (struct reg_rep *) msg; char *msgpos; struct msg_key *key; int msglen; int result, i; char buf[256]; char secret[256]; unsigned char tmp[16]; struct sockaddr_in addr; struct msg_auth *auth; memset(reply, 0, sizeof(reply)); reply->type = REG_REP; printf("code? "); scanf("%d", &i); reply->code = i; printf("lifetime? "); scanf("%d", &i); reply->lifetime = i; reply->lifetime = htons(reply->lifetime); printf("home_addr? "); scanf("%s", buf); inet_aton(buf, &reply->home_addr); printf("ha_addr? "); scanf("%s", buf); inet_aton(buf, &reply->ha_addr); msgpos = (char *) reply + sizeof(struct reg_rep); /* Add message authentication */ auth = (struct msg_auth *) msgpos; auth->type = MH_AUTH; printf("spi? "); scanf("%d", &result); auth->spi = htonl(result); printf("Shared secret? "); scanf("%s", secret); /* ID prompting moved here for quicker sending after ids have been set */ printf("id[0]? "); scanf("%d", &reply->id[0]); reply->id[0] = htonl(reply->id[0]); printf("id[1]? "); scanf("%d", &reply->id[1]); reply->id[1] = htonl(reply->id[1]); msgpos += sizeof(struct msg_auth); md5_mac((unsigned char *) secret, strlen(secret), (unsigned char *) reply, sizeof(struct reg_rep), (unsigned char *) msgpos); auth->length = 16 + SPI_LEN; msgpos += 16; /* Add session key to mobile node */ key = (struct msg_key *) msgpos; init_key_extension(key, VENDOR_EXT_DYNAMICS_MN_KEYREP, auth->spi, 16); md5_mac((unsigned char *) secret, strlen(secret), (unsigned char *) reply, sizeof(*reply), tmp); memcpy(MSG_KEY_DATA(key), KEY, 16); for (i = 0; i < 16; i++) *(MSG_KEY_DATA(key) + i) ^= tmp[i]; msgpos += GET_KEY_EXT_LEN(key); msglen = msgpos - msg; printf("send to ip addr? "); scanf("%s", buf); inet_aton(buf, &addr.sin_addr); printf("port? "); scanf("%d", &result); addr.sin_port = htons(result); addr.sin_family = AF_INET; result = sendto(s, msg, msglen, 0, (struct sockaddr *) &addr, sizeof(struct sockaddr_in)); printf("sent %d bytes (of %d) to %s:%d\n", result, msglen, inet_ntoa(addr.sin_addr), ntohs(addr.sin_port)); return 0;}int main(int argc, char *argv[]){ int s; s = socket(AF_INET, SOCK_DGRAM, 0); if (s < 0) { perror("socket"); return -1; } send_reg_repl(s); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -