// 第4个参数表示该选项的索引值
static struct option opts[] = {
{ "set-id", 1, 0, '1' },
{ 0 }
};
/* Initialize the target. */
static void
init(struct ipt_entry_target *t, unsigned int *nfcache)
{
// 空函数,不需要预处理
}
static void
parse_id(const unsigned char *s, struct ipt_id_target_info*info)
{
unsigned int i, id;
if (string_to_number(s, 0, 255, &id) != -1) {
// 注意要将主机序数据转换为网络序
info->id = htons((u_int16_t)id);
return;
}
exit_error(PARAMETER_PROBLEM, "Bad ID value `%s'", s);
}
/* Function which parses command options; returns true if it
ate an option */
static int
parse(int c, char **argv, int invert, unsigned int *flags,
const struct ipt_entry *entry,
struct ipt_entry_target**target)
{
struct ipt_id_target_info *idinfo
= (struct ipt_id_target_info *)(*target)->data;
switch (c) {
case '1':
if (*flags)
exit_error(PARAMETER_PROBLEM,
"ID target: Cant specify --set-id twice");
parse_id(optarg, idinfo);
*flags = 1;
break;
default:
return 0;
}
return 1;
}
static void
final_check(unsigned int flags)
{
if (!flags)
exit_error(PARAMETER_PROBLEM,
"ID target: Parameter --set-id is required");
}
static void
print_id(u_int8_t id, int numeric)
{
unsigned int i;
printf("0x%x ", ntohs(id));
}
/* Prints out the targinfo. */
static void
print(const struct ipt_ip *ip,
const struct ipt_entry_target*target,
int numeric)
{
const struct ipt_id_target_info *idinfo =
(const struct ipt_id_target_info *)target->data;
printf("ID set ");
print_id(idinfo->id, numeric);
}
/* Saves the union ipt_targinfo in parsable form to stdout.*/
本文来自电脑杂谈,转载请注明本文网址:
https://www.pc-fly.com/a/jisuanjixue/article-34719-7.html
自古二楼出狗奴
走一个
黑芝麻糊都是要热加工的
已经做了n次作战方案
我们也要摆出姿态