der_encode_to_buffer返回错误0.错误0究竟是什么?

时间:2015-03-06 00:43:13

标签: c sockets asn.1

MyTest DEFINITIONS ::=
BEGIN
    Client ::= CHOICE {
    clientInt INTEGER,
    clientStr OCTET STRING,
    clientOID OBJECT IDENTIFIER
}

END

  Client_t *newClient;          //new client struct
  newClient = calloc(1, sizeof(Client_t));
  asn_enc_rval_t encode_rtn;
  printf("input integer: ");
  scanf("%d", &((*newClient).choice.clientInt));

  encode_rtn = der_encode_to_buffer(&asn_DEF_Client, newClient,
                       send_buffer, BUFFER_SIZE);
  if (encode_rtn.encoded == -1){
        printf("Error while encoding  %s: %s\n", encode_rtn.failed_type->name, strerror(errno));
        exit(1);
   }

嗨,那里。这段代码可以编译,但输入整数后我总是得到“Client:Error 0”。什么是错误0?谢谢。

我要做的是使用BER将整数编码为串行字节序列并存储在发送缓冲区中。 我今天开始使用asn1编译器。我读过的唯一文档是使用开源ASN.1编译器,它没有提供太多信息。如果您能提供有用的信息,我将不胜感激。

编译器的文档是http://lionet.info/asn1c/documentation.html

1 个答案:

答案 0 :(得分:1)

没有得到与您完全相同的错误。但是,您缺少选择选项:

  Client_t *newClient;          //new client struct
  newClient = calloc(1, sizeof(Client_t));
  asn_enc_rval_t encode_rtn;
  printf("input integer: ");
  scanf("%d", &((*newClient).choice.clientInt));
  /* CHANGE: select clientInt on the CHOICE */
  (*newClient).present = Client_PR_clientInt;      

  encode_rtn = der_encode_to_buffer(&asn_DEF_Client, newClient,
                       send_buffer, BUFFER_SIZE);
  if (encode_rtn.encoded == -1){
        printf("Error while encoding  %s: %s\n", encode_rtn.failed_type->name, strerror(errno));
        exit(1);
  }

有了这个改变,我没有得到任何错误。