[strongSwan] Unable to parse Vici "list-conn" message element with custom code

Harry Chan-Maestas harry.chan.maestas at gmail.com
Tue Sep 29 01:40:52 CEST 2015


Hi All,

In my test program, where I open a Vici connection with Charon and call
"list-conns", I can't seem to parse the Vici response which comes back from
Charon using the libvici API. The raw vici message is

{homes {local_addrs=[%any] remote_addrs=[192.168.2.129] version=IKEv2
local-1 {id=RoadWarrior class=public key groups=[] certs=[C=US, ST=CA,
L=Cupertino, O=Testing, OU=Testing, CN=RoadWarrior] cacerts=[]} remote-1
{id=GateWay class=public key groups=[] certs=[] cacerts=[]} children {home
{mode=TUNNEL local-ts=[dynamic] remote-ts=[192.168.11.0/24]}}}}

My program (modeled on swanctl) outputs

Sec homes
Key local_addrs, Value %any
'start' within list

and fails with error. The code is below. Would someone take a look, and see
what I am doing wrong?

Thank you,

Harry

----------------------------------------------

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
extern "C" {
#include "strongswan/vici/libvici.h"
}

int key_val_cb(void *null, vici_res_t *res, char *name, void *value, int
len)
{
  ((char*)value)[len] = '\0';
  printf("Key %s, Value %s\n", name, ((char*)value));
  return 0;
}

int children_sn(void *null, vici_res_t *res, char *name)
{
  return vici_parse_cb(res, NULL, key_val_cb, key_val_cb, NULL);
}

int conn_sn(void *null, vici_res_t *res, char *name)
{
  if (strcmp(name, "children") == 0) {
    return vici_parse_cb(res, children_sn, NULL, NULL, NULL);
  } else {
    return vici_parse_cb(res, NULL, key_val_cb, key_val_cb, NULL);
  }
}

int conns(void *null, vici_res_t *res, char *name)
{
  printf("Sec %s\n", name);
  return vici_parse_cb(res, conn_sn, NULL, key_val_cb, NULL);
}

void list_cb(void *null, char *name, vici_res_t *res)
{
  vici_dump(res, "Raw Message: ", 0, stdout);
  vici_parse_cb(res, conns, NULL, NULL, NULL);
}

int main(int argc, char **argv)
{
  // Test out VICI
  vici_conn_t *conn = NULL;

  vici_init();
  conn = vici_connect(NULL);
  if (conn == NULL) {
    perror("VICI connect failed");
  } else {
    vici_req_t *req = NULL;
    vici_res_t *res = NULL;
    vici_register(conn, "list-conn", list_cb, NULL);
    req = vici_begin("list-conns");
    res = vici_submit(req, conn);
    if (res == NULL) {
      perror("VICI transaction failed");
    } else {
      vici_free_res(res);
    }
    vici_disconnect(conn);
  }
  vici_deinit();

  return 0;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.strongswan.org/pipermail/users/attachments/20150928/9d4a39b6/attachment-0001.html>


More information about the Users mailing list