当前位置: 首页 > news >正文

网络管理实验1:ASN.1软件应用

兰生幽谷,不为莫服而不芳;

君子行义,不为莫知而止休。

一. 实验目的

1. 掌握搭建C环境下ASN.1编码环境;

2. 掌握抽象语法表示asn文件的编码和编译方法;

3.试着按指定asn方法编制基本的ASN.1宏定义结构。

二. 实验内容

1.掌握ASN1C的安装方法;

2.掌握ASN宏定义数据结构;

3.根据下面的内容按宏定义的方法编制成ASN.1脚本程序并编译。

假如一个公司拥有一个连接了数个销售网点的仓库,进货保存在这个仓库里 ,出货从这个仓库中调出。这个公司需要一个具有以下特征的协议:
定单收集在本地销售网点处;
它们被发送到仓库,在那里管理着交付货物手续;
通过客户的要求,交付的回执必须送回销售网点做下一步处理。

三. 实验工具

VMware workstation 17.5pro、Mobaxterm、gcc、gcc-c++、perl、ASNC

四. 实验步骤

1.准备安装包

百度网盘下载ASN安装包asn1c-0.9.28.tar.gz,拖入自己所建专用文件夹。

 

2.安装必要工具和依赖关系

yum install -y gcc gcc-c++ perl

3.解压

tar xvf asn1c-0.9.28.tar.gz

4.编译

cd asn1c-0.9.28/

[root@wzz asn1c-0.9.28]# ls

aclocal.m4   config.log     FAQ              m4           stu

asn1c        config.status  INSTALL.md       Makefile     student

AUTHORS      config.sub     libasn1compiler  Makefile.am  tests

BUGS         configure      libasn1fix       Makefile.in  TODO

ChangeLog    configure.ac   libasn1parser    myHttp

config       depcomp        libasn1print     README.md

config.h     doc            libtool          skeletons

config.h.in  examples       LICENSE          stamp-h1

[root@wzz asn1c-0.9.28]# ./configure

\checking for a BSD-compatible install... /usr/bin/install -c

checking whether build environment is sane... yes

/wzz/asn1c928/asn1c-0.9.28/config/missing: Unknown `--is-lightweight' option

Try `/wzz/asn1c928/asn1c-0.9.28/config/missing --help' for more information

configure: WARNING: 'missing' script is too old or missing

checking for a thread-safe mkdir -p... /usr/bin/mkdir -p

checking for gawk... gawk

……

checking dependency style of gcc... gcc3

checking for a sed that does not truncate output... /usr/bin/sed

checking for grep that handles long lines and -e... /usr/bin/grep

checking for egrep... /usr/bin/grep -E

checking for fgrep... /usr/bin/grep -F

……

checking how to run the C preprocessor... gcc -E

checking for ANSI C header files... yes

checking for sys/types.h... yes

checking for sys/stat.h... yes

checking for stdlib.h... yes

checking for string.h... yes

checking for memory.h... yes

checking for strings.h... yes

checking for inttypes.h... yes

checking for stdint.h... yes

checking for unistd.h... yes

checking for dlfcn.h... yes

checking for objdir... .libs

checking if gcc supports -fno-rtti -fno-exceptions... no

checking for gcc option to produce PIC... -fPIC -DPIC

checking if gcc PIC flag -fPIC -DPIC works... yes

checking if gcc static flag -static works... no

checking if gcc supports -c -o file.o... yes

checking if gcc supports -c -o file.o... (cached) yes

checking whether the gcc linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes

……

checking whether gcc accepts -g... (cached) yes

checking for gcc option to accept ISO C89... (cached) none needed

checking whether gcc understands -c and -o together... (cached) yes

checking dependency style of gcc... (cached) gcc3

checking how to run the C preprocessor... gcc -E

checking whether ln -s works... yes

checking whether make sets $(MAKE)... (cached) yes

checking for bison... no

……

有错就自行排错。直到编译完成。

5.安装

[root@wzz asn1c-0.9.28]# make && make install

make  all-recursive

make[1]: 进入目录“/wzz/asn1c928/asn1c-0.9.28”

Making all in libasn1parser

……

make[2]: 离开目录“/wzz/asn1c928/asn1c-0.9.28”

make[1]: 离开目录“/wzz/asn1c928/asn1c-0.9.28”

有错就自行排错。直到安装完成。

6.退到自己专用目录,创建工程test目录

[root@wzz asn1c-0.9.28]# cd ..

[root@wzz asn1c928]# cd ..

[root@wzz wzz]# mkdir test

[root@wzz wzz]# cd test

[root@wzz test]#

创建个人信息的ASN宏

vi resume.asn

#以下是该宏文件的内容

MsgTest DEFINITIONS::=BEGIN

  Msg::=SEQUENCE{

    birthday  NumericString(SIZE(8)),

    studentnum NumericString(SIZE(9)),

    domitory  IA5String(SIZE(60)),

    name      IA5String(SIZE(60))

}

END

赋权

chmod +x resume.asn

编译生成各种头文件、链接及源文件

[root@wzz test]# asn1c -gen-PER *.asn

Compiled Msg.c

Compiled Msg.h

Copied /usr/local/share/asn1c/IA5String.h       -> IA5String.h

Copied /usr/local/share/asn1c/IA5String.c       -> IA5String.c

Copied /usr/local/share/asn1c/NumericString.h   -> NumericString.h

Copied /usr/local/share/asn1c/NumericString.c   -> NumericString.c

Copied /usr/local/share/asn1c/constr_SEQUENCE.h -> constr_SEQUENCE.h

Copied /usr/local/share/asn1c/constr_SEQUENCE.c -> constr_SEQUENCE.c

Copied /usr/local/share/asn1c/asn_application.h -> asn_application.h

Copied /usr/local/share/asn1c/asn_system.h      -> asn_system.h

Copied /usr/local/share/asn1c/asn_codecs.h      -> asn_codecs.h

Copied /usr/local/share/asn1c/asn_internal.h    -> asn_internal.h

Copied /usr/local/share/asn1c/OCTET_STRING.h    -> OCTET_STRING.h

Copied /usr/local/share/asn1c/OCTET_STRING.c    -> OCTET_STRING.c

Copied /usr/local/share/asn1c/BIT_STRING.h      -> BIT_STRING.h

Copied /usr/local/share/asn1c/BIT_STRING.c      -> BIT_STRING.c

Copied /usr/local/share/asn1c/asn_codecs_prim.c -> asn_codecs_prim.c

Copied /usr/local/share/asn1c/asn_codecs_prim.h -> asn_codecs_prim.h

Copied /usr/local/share/asn1c/ber_tlv_length.h  -> ber_tlv_length.h

Copied /usr/local/share/asn1c/ber_tlv_length.c  -> ber_tlv_length.c

Copied /usr/local/share/asn1c/ber_tlv_tag.h     -> ber_tlv_tag.h

Copied /usr/local/share/asn1c/ber_tlv_tag.c     -> ber_tlv_tag.c

Copied /usr/local/share/asn1c/ber_decoder.h     -> ber_decoder.h

Copied /usr/local/share/asn1c/ber_decoder.c     -> ber_decoder.c

Copied /usr/local/share/asn1c/der_encoder.h     -> der_encoder.h

Copied /usr/local/share/asn1c/der_encoder.c     -> der_encoder.c

Copied /usr/local/share/asn1c/constr_TYPE.h     -> constr_TYPE.h

Copied /usr/local/share/asn1c/constr_TYPE.c     -> constr_TYPE.c

Copied /usr/local/share/asn1c/constraints.h     -> constraints.h

Copied /usr/local/share/asn1c/constraints.c     -> constraints.c

Copied /usr/local/share/asn1c/xer_support.h     -> xer_support.h

Copied /usr/local/share/asn1c/xer_support.c     -> xer_support.c

Copied /usr/local/share/asn1c/xer_decoder.h     -> xer_decoder.h

Copied /usr/local/share/asn1c/xer_decoder.c     -> xer_decoder.c

Copied /usr/local/share/asn1c/xer_encoder.h     -> xer_encoder.h

Copied /usr/local/share/asn1c/xer_encoder.c     -> xer_encoder.c

Copied /usr/local/share/asn1c/per_support.h     -> per_support.h

Copied /usr/local/share/asn1c/per_support.c     -> per_support.c

Copied /usr/local/share/asn1c/per_decoder.h     -> per_decoder.h

Copied /usr/local/share/asn1c/per_decoder.c     -> per_decoder.c

Copied /usr/local/share/asn1c/per_encoder.h     -> per_encoder.h

Copied /usr/local/share/asn1c/per_encoder.c     -> per_encoder.c

Copied /usr/local/share/asn1c/per_opentype.h    -> per_opentype.h

Copied /usr/local/share/asn1c/per_opentype.c    -> per_opentype.c

Copied /usr/local/share/asn1c/converter-sample.c        -> converter-sample.c

Generated Makefile.am.sample

查看一下我们定义的Msg源文件和头文件:

[root@wzz test]# cat Msg.c

/*

 * Generated by asn1c-0.9.28 (http://lionet.info/asn1c)

 * From ASN.1 module "MsgTest"

 *      found in "resume.asn"

 *      `asn1c -gen-PER`

 */

#include "Msg.h"

static const int permitted_alphabet_table_2[256] = {

 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,        /*                  */

 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,        /*                  */

 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,        /* .                */

 2, 3, 4, 5, 6, 7, 8, 9,10,11, 0, 0, 0, 0, 0, 0,        /* 0123456789       */

};

……

载看看头文件

[root@wzz test]# cat Msg.h

/*

 * Generated by asn1c-0.9.28 (http://lionet.info/asn1c)

 * From ASN.1 module "MsgTest"

 *      found in "resume.asn"

 *      `asn1c -gen-PER`

 */

#ifndef _Msg_H_

#define _Msg_H_

#include <asn_application.h>

/* Including external dependencies */

#include <NumericString.h>

#include <IA5String.h>

#include <constr_SEQUENCE.h>

#ifdef __cplusplus

extern "C" {

#endif

/* Msg */

typedef struct Msg {

        NumericString_t  birthday;

        NumericString_t  studentnum;

        IA5String_t      domitory;

        IA5String_t      name;

        /* Context for parsing across buffer boundaries */

        asn_struct_ctx_t _asn_ctx;

} Msg_t;

/* Implementation */

extern asn_TYPE_descriptor_t asn_DEF_Msg;

#ifdef __cplusplus

}

#endif

#endif  /* _Msg_H_ */

#include <asn_internal.h>

7.编制一个订单处理的ASN宏程序

假如一个公司拥有一个连接了数个销售网点的仓库,进货保存在这个仓库里,出货从这个仓库中调出。这个公司需要一个具有以下特征的协议
定单收集在本地销售网点处;
它们被发送到仓库,在那里管理着交付货物手续;
通过客户的要求,交付的
回执必须送回销售网点做下一步处理。

分析设计过程略。直接给出结果:

Module-order DEFINITIONS AUTOMATIC TAGS::=BEGIN

Order::=SEQUENCE{

header Order-header,

items SEQUENCE OF Order-line}

Order-header::=SEQUENCE{

number Order-number,

date Date,client Client,

payment Payment-method}

Order-number::=NumericString(SIZE(12))

Date::=NumericString(SIZE(8)) -- MMDDYYYY

Client::=SEQUENCE{

name PrintableString(SIZE(1..20)),

street PrintableString(SIZE(1..50)) OPTIONAL,

postcode NumericString(SIZE(5)),

town PrintableString(SIZE(1..30)),

country PrintableString(SIZE(1..20))

DEFAULT default-country}

default-country PrintableString::="PR China"

Payment-method::=CHOICE{

check NumericString(SIZE(15)),

credit-card Credit-card,

cash NULL}

Credit-card::=SEQUENCE{

type Card-type,

number NumericString(SIZE(20)),

expiry-date NumericString(SIZE(6)) -- MMYYYY --}

Card-type::=ENUMERATED{yl(0),visa(1),eurocard(2),diners(3),american-express(4)}

Order-line::=SEQUENCE{

item-code Item-code,

label Label,

quantity Quantity,

price Cents}

Item-code::=NumericString(SIZE(7))

Label::=PrintableString(SIZE(1..30))

Quantity::=CHOICE{unites INTEGER,

millimetres INTEGER,

milligrammes INTEGER}

Cents::=INTEGER

Delivery-report::=SEQUENCE{order-code Order-number,

delivery SEQUENCE OF Delivery-line}

Delivery-line::=SEQUENCE{item Item-code,

quantity Quantity}

END

Protocol DEFINITIONS AUTOMATIC TAGS::=BEGIN

IMPORTS Order,Delivery-report,Item-code,Quantity,

Order-number FROM Module-order;

PDU::=CHOICE{question CHOICE{

question1 Order,

question2 Item-code,

question3 Order-number,

...},

answer CHOICE{

answer1 Delivery-report,

answer2 Quantity,

answer3 Delivery-report,

...}}

END

编译ASN宏

[root@wzz myOrder]# asn1c -gen-PER *.asn

Compiled Order.c

Compiled Order.h

Compiled Order-header.c

Compiled Order-header.h

Compiled Order-number.c

Compiled Order-number.h

Compiled Date.c

Compiled Date.h

Compiled Client.c

Compiled Client.h

Compiled Payment-method.c

Compiled Payment-method.h

Compiled Credit-card.c

Compiled Credit-card.h

Compiled Card-type.c

Compiled Card-type.h

Compiled Order-line.c

Compiled Order-line.h

Compiled Item-code.c

Compiled Item-code.h

Compiled Label.c

Compiled Label.h

Compiled Quantity.c

Compiled Quantity.h

Compiled Cents.c

Compiled Cents.h

Compiled Delivery-report.c

Compiled Delivery-report.h

Compiled Delivery-line.c

Compiled Delivery-line.h

Compiled PDU.c

Compiled PDU.h

Copied /usr/local/share/asn1c/BOOLEAN.h -> BOOLEAN.h

Copied /usr/local/share/asn1c/BOOLEAN.c -> BOOLEAN.c

Copied /usr/local/share/asn1c/INTEGER.h -> INTEGER.h

Copied /usr/local/share/asn1c/NativeEnumerated.h        -> NativeEnumerated.h

Copied /usr/local/share/asn1c/INTEGER.c -> INTEGER.c

Copied /usr/local/share/asn1c/NULL.h    -> NULL.h

Copied /usr/local/share/asn1c/NULL.c    -> NULL.c

Copied /usr/local/share/asn1c/NativeEnumerated.c        -> NativeEnumerated.c

Copied /usr/local/share/asn1c/NativeInteger.h   -> NativeInteger.h

Copied /usr/local/share/asn1c/NativeInteger.c   -> NativeInteger.c

Copied /usr/local/share/asn1c/NumericString.h   -> NumericString.h

Copied /usr/local/share/asn1c/NumericString.c   -> NumericString.c

Copied /usr/local/share/asn1c/PrintableString.h -> PrintableString.h

Copied /usr/local/share/asn1c/PrintableString.c -> PrintableString.c

Copied /usr/local/share/asn1c/asn_SEQUENCE_OF.h -> asn_SEQUENCE_OF.h

Copied /usr/local/share/asn1c/asn_SEQUENCE_OF.c -> asn_SEQUENCE_OF.c

Copied /usr/local/share/asn1c/asn_SET_OF.h      -> asn_SET_OF.h

Copied /usr/local/share/asn1c/asn_SET_OF.c      -> asn_SET_OF.c

Copied /usr/local/share/asn1c/constr_CHOICE.h   -> constr_CHOICE.h

Copied /usr/local/share/asn1c/constr_CHOICE.c   -> constr_CHOICE.c

Copied /usr/local/share/asn1c/constr_SEQUENCE.h -> constr_SEQUENCE.h

Copied /usr/local/share/asn1c/constr_SEQUENCE.c -> constr_SEQUENCE.c

Copied /usr/local/share/asn1c/constr_SEQUENCE_OF.h      -> constr_SEQUENCE_OF.h

Copied /usr/local/share/asn1c/constr_SEQUENCE_OF.c      -> constr_SEQUENCE_OF.c

Copied /usr/local/share/asn1c/constr_SET_OF.h   -> constr_SET_OF.h

Copied /usr/local/share/asn1c/constr_SET_OF.c   -> constr_SET_OF.c

Copied /usr/local/share/asn1c/asn_application.h -> asn_application.h

Copied /usr/local/share/asn1c/asn_system.h      -> asn_system.h

Copied /usr/local/share/asn1c/asn_codecs.h      -> asn_codecs.h

Copied /usr/local/share/asn1c/asn_internal.h    -> asn_internal.h

Copied /usr/local/share/asn1c/OCTET_STRING.h    -> OCTET_STRING.h

Copied /usr/local/share/asn1c/OCTET_STRING.c    -> OCTET_STRING.c

Copied /usr/local/share/asn1c/BIT_STRING.h      -> BIT_STRING.h

Copied /usr/local/share/asn1c/BIT_STRING.c      -> BIT_STRING.c

Copied /usr/local/share/asn1c/asn_codecs_prim.c -> asn_codecs_prim.c

Copied /usr/local/share/asn1c/asn_codecs_prim.h -> asn_codecs_prim.h

Copied /usr/local/share/asn1c/ber_tlv_length.h  -> ber_tlv_length.h

Copied /usr/local/share/asn1c/ber_tlv_length.c  -> ber_tlv_length.c

Copied /usr/local/share/asn1c/ber_tlv_tag.h     -> ber_tlv_tag.h

Copied /usr/local/share/asn1c/ber_tlv_tag.c     -> ber_tlv_tag.c

Copied /usr/local/share/asn1c/ber_decoder.h     -> ber_decoder.h

Copied /usr/local/share/asn1c/ber_decoder.c     -> ber_decoder.c

Copied /usr/local/share/asn1c/der_encoder.h     -> der_encoder.h

Copied /usr/local/share/asn1c/der_encoder.c     -> der_encoder.c

Copied /usr/local/share/asn1c/constr_TYPE.h     -> constr_TYPE.h

Copied /usr/local/share/asn1c/constr_TYPE.c     -> constr_TYPE.c

Copied /usr/local/share/asn1c/constraints.h     -> constraints.h

Copied /usr/local/share/asn1c/constraints.c     -> constraints.c

Copied /usr/local/share/asn1c/xer_support.h     -> xer_support.h

Copied /usr/local/share/asn1c/xer_support.c     -> xer_support.c

Copied /usr/local/share/asn1c/xer_decoder.h     -> xer_decoder.h

Copied /usr/local/share/asn1c/xer_decoder.c     -> xer_decoder.c

Copied /usr/local/share/asn1c/xer_encoder.h     -> xer_encoder.h

Copied /usr/local/share/asn1c/xer_encoder.c     -> xer_encoder.c

Copied /usr/local/share/asn1c/per_support.h     -> per_support.h

Copied /usr/local/share/asn1c/per_support.c     -> per_support.c

Copied /usr/local/share/asn1c/per_decoder.h     -> per_decoder.h

Copied /usr/local/share/asn1c/per_decoder.c     -> per_decoder.c

Copied /usr/local/share/asn1c/per_encoder.h     -> per_encoder.h

Copied /usr/local/share/asn1c/per_encoder.c     -> per_encoder.c

Copied /usr/local/share/asn1c/per_opentype.h    -> per_opentype.h

Copied /usr/local/share/asn1c/per_opentype.c    -> per_opentype.c

Copied /usr/local/share/asn1c/converter-sample.c        -> converter-sample.c

Generated Makefile.am.sample

8.按下列要求编写PersonalRecord宏定义脚本并编译

必须包含:

雇员姓名(包含姓、字辈(可选)、名)、职位、员工号、出生日期、配偶姓名(包含姓、字辈(可选)、名)、子女信息(包含:姓名、出生年月日、单位)

五.分析与讨论

1.枚举属于哪一种数据结构?

2.找度娘或DeepSeek了解BER、CER、DER和PER的相关概念和特性。

http://www.dtcms.com/a/405907.html

相关文章:

  • 前端开发用什么工具?前端开发工具推荐清单、实用对比与我的使用心得
  • 做亚马逊有什么网站可以借鉴大连城市建设档案馆官方网站
  • 协议不通,数据何通?耐达讯自动化Modbus TCP与Profibus网关技术破解建筑自动化最大瓶颈
  • 新零售模式下仓储变化与发展趋势
  • Stable Video Diffusion:将潜在视频扩散模型扩展到大规模数据集——论文阅读
  • [linux仓库]解剖ELF:从文件头到进程地址空间的完美映射
  • Lisp 与 C# 交互中,类型码(TypeCode)的映射关系
  • Java基础(十四):枚举类详解
  • python+springboot+uniapp基于微信小程序的任务打卡系统
  • 【多线程】计算机领域中的各种锁
  • python+uniapp基于微信小程序的医院陪诊预约系统
  • 免费html网页模板 html5网站模板 静态网页模板
  • 网站怎么做区域性优化公司网站建设会计上怎么处理
  • 专业商城网站建设价格定制家具网
  • ABCTorrents官网入口 – 磁力搜索引擎网站
  • python+django/flask+uniapp基于微信小程序的瑜伽体验课预约系统
  • 设计模式(C++)详解——解释器模式(1)
  • iOS 26 系统流畅度深度剖析,Liquid Glass 视效与界面滑动的实际测评
  • mysql asp网站2001国产卡一卡二新区
  • Docker容器化部署简要指南
  • 一文掌握 Apache SeaTunnel 构建系统与分发基础架构
  • 【数据结构】常用数据结构深度剖析
  • 适合小型网络公司的建站方式可以为网络黄页推广大全4
  • 男女性直接做的视频网站网页首页管理系统
  • 数字孪生 3D 风电场:HT 海上风电智慧化解决方案
  • 示波器使用,查看3d线扫相机的问题
  • 【汽车篇】基于深度学习的2D+3D整车漆面外观缺陷检测
  • (14)ASP.NET Core2.2 中的日志记录
  • Three.js 开发实战教程(五):外部 3D 模型加载与优化实战
  • SpringBoot 整合机器学习框架 Weka 实战操作详解:从 0 到 1 构建可扩展的智能预测微服务