hdr.ts_usec = 0;
hdr.incl_len = hdr.orig_len = size;
n = write(dump, &hdr, sizeof(hdr));
- fail_unless(n != -1, "unable to write pcap record header to %s", filename);
+ if (n == 1) {
+ fail("unable to write pcap record header to %s", filename);
+ return -1;
+ }
/* Write data */
n = write(dump, buffer, size);
- fail_unless(n != -1, "unable to write pcap data to %s", filename);
+ if (n == -1) {
+ fail("unable to write pcap data to %s", filename);
+ return -1;
+ }
/* Append to list of packets */
pkt = (struct packet *)malloc(size + sizeof(TAILQ_HEAD(,packet)) + sizeof(int));
- fail_unless(pkt != NULL);
+ if (!pkt) {
+ fail("unable to allocate packet");
+ return -1;
+ }
memcpy(pkt->data, buffer, size);
pkt->size = size;
TAILQ_INSERT_TAIL(&pkts, pkt, next);
TAILQ_INIT(&pkts);
/* Open a new dump file */
n = asprintf(&filename, "lldp_send_%04d.pcap", serial++);
- fail_unless(n != -1, "unable to compute filename");
+ if (n == -1) {
+ fail("unable to compute filename");
+ return;
+ }
dump = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0644);
- fail_unless(dump != -1);
+ if (dump == -1) {
+ fail("unable to open %s", filename);
+ return;
+ }
/* Write a PCAP header */
hdr.magic_number = 0xa1b2c3d4;
hdr.version_major = 2;
hdr.snaplen = 65535;
hdr.network = 1;
n = write(dump, &hdr, sizeof(hdr));
- fail_unless(n != -1, "unable to write pcap header to %s", filename);
+ if (n == -1) {
+ fail("unable to write pcap header to %s", filename);
+ return;
+ }
/* Prepare hardware */
memset(&hardware, 0, sizeof(struct lldpd_hardware));
TAILQ_INIT(&hardware.h_rports);
/* Build packet */
n = lldp_send(NULL, &hardware);
- fail_unless(n == 0, "unable to build packet");
- fail_unless(!TAILQ_EMPTY(&pkts));
+ if (n != 0) {
+ fail("unable to build packet");
+ return;
+ }
+ if (TAILQ_EMPTY(&pkts)) {
+ fail("no packets sent");
+ return;
+ }
pkt = TAILQ_FIRST(&pkts);
ck_assert_int_eq(pkt->size, sizeof(pkt1));
fail_unless(memcmp(pkt->data, pkt1, sizeof(pkt1)) == 0);
/* Build packet */
n = lldp_send(NULL, &hardware);
- fail_unless(n == 0, "unable to build packet");
- fail_unless(!TAILQ_EMPTY(&pkts));
+ if (n != 0) {
+ fail("unable to build packet");
+ return;
+ }
+ if (TAILQ_EMPTY(&pkts)) {
+ fail("no packets sent");
+ return;
+ }
pkt = TAILQ_FIRST(&pkts);
ck_assert_int_eq(pkt->size, sizeof(pkt1));
fail_unless(memcmp(pkt->data, pkt1, sizeof(pkt1)) == 0);
/* Build packet */
n = lldp_send(NULL, &hardware);
- fail_unless(n == 0, "unable to build packet");
- fail_unless(!TAILQ_EMPTY(&pkts));
+ if (n != 0) {
+ fail("unable to build packet");
+ return;
+ }
+ if (TAILQ_EMPTY(&pkts)) {
+ fail("no packets sent");
+ return;
+ }
pkt = TAILQ_FIRST(&pkts);
ck_assert_int_eq(pkt->size, sizeof(pkt1));
fail_unless(memcmp(pkt->data, pkt1, sizeof(pkt1)) == 0);
/* Build packet */
n = lldp_send(NULL, &hardware);
- fail_unless(n == 0, "unable to build packet");
- fail_unless(!TAILQ_EMPTY(&pkts));
+ if (n != 0) {
+ fail("unable to build packet");
+ return;
+ }
+ if (TAILQ_EMPTY(&pkts)) {
+ fail("no packets sent");
+ return;
+ }
pkt = TAILQ_FIRST(&pkts);
ck_assert_int_eq(pkt->size, sizeof(pkt1));
fail_unless(memcmp(pkt->data, pkt1, sizeof(pkt1)) == 0);
fail_unless(lldp_decode(NULL, pkt1, sizeof(pkt1), &hardware,
&nchassis, &nport) != -1);
- fail_unless(nchassis != NULL);
- fail_unless(nport != NULL);
+ if (!nchassis || !nport) {
+ fail("unable to decode packet");
+ return;
+ }
ck_assert_int_eq(nchassis->c_id_subtype,
LLDP_CHASSISID_SUBTYPE_LLADDR);
ck_assert_int_eq(nchassis->c_id_len, ETH_ALEN);
fail_unless(lldp_decode(NULL, pkt1, sizeof(pkt1), &hardware,
&nchassis, &nport) != -1);
- fail_unless(nchassis != NULL);
- fail_unless(nport != NULL);
+ if (!nchassis || !nport) {
+ fail("unable to decode packet");
+ return;
+ }
ck_assert_int_eq(nchassis->c_id_subtype,
LLDP_CHASSISID_SUBTYPE_LLADDR);
ck_assert_int_eq(nchassis->c_id_len, ETH_ALEN);
fail_unless(lldp_decode(NULL, pkt1, sizeof(pkt1), &hardware,
&nchassis, &nport) != -1);
- fail_unless(nchassis != NULL);
- fail_unless(nport != NULL);
+ if (!nchassis || !nport) {
+ fail("unable to decode packet");
+ return;
+ }
ck_assert_int_eq(nchassis->c_id_subtype,
LLDP_CHASSISID_SUBTYPE_LLADDR);
ck_assert_int_eq(nchassis->c_id_len, ETH_ALEN);
ck_assert_int_eq(nchassis->c_mgmt.s_addr,
(u_int32_t)inet_addr("172.20.3.2"));
ck_assert_int_eq(nchassis->c_mgmt_if, 0);
- fail_unless(!TAILQ_EMPTY(&nport->p_vlans));
+ if (TAILQ_EMPTY(&nport->p_vlans)) {
+ fail("no VLAN");
+ return;
+ }
vlan = TAILQ_FIRST(&nport->p_vlans);
ck_assert_int_eq(vlan->v_vid, 500);
ck_assert_str_eq(vlan->v_name, "TestVlan");
vlan = TAILQ_NEXT(vlan, v_entries);
- fail_unless(vlan != NULL);
+ if (!vlan) {
+ fail("no more VLAN");
+ return;
+ }
ck_assert_int_eq(vlan->v_vid, 501);
ck_assert_str_eq(vlan->v_name, "TestVlan2");
vlan = TAILQ_NEXT(vlan, v_entries);
- fail_unless(vlan != NULL);
+ if (!vlan) {
+ fail("no more VLAN");
+ return;
+ }
ck_assert_int_eq(vlan->v_vid, 502);
ck_assert_str_eq(vlan->v_name, "TestVlan3");
vlan = TAILQ_NEXT(vlan, v_entries);
fail_unless(lldp_decode(NULL, pkt1, sizeof(pkt1), &hardware,
&nchassis, &nport) != -1);
- fail_unless(nchassis != NULL);
- fail_unless(nport != NULL);
+ if (!nchassis || !nport) {
+ fail("unable to decode packet");
+ return;
+ }
ck_assert_int_eq(nchassis->c_id_subtype,
LLDP_CHASSISID_SUBTYPE_LLADDR);
ck_assert_int_eq(nchassis->c_id_len, ETH_ALEN);
char byte = 18;
void *p;
p = (char*)&h->data;
- fail_unless(ctl_msg_pack_structure("b", &byte, sizeof(char),
- h, &p) != -1);
+ if (ctl_msg_pack_structure("b", &byte, sizeof(char),
+ h, &p) == -1) {
+ fail("unable to pack");
+ return;
+ }
mark_point();
p = (char*)&h->data;
- fail_unless(ctl_msg_unpack_structure("b", &byte, sizeof(char),
- h, &p) != -1);
+ if (ctl_msg_unpack_structure("b", &byte, sizeof(char),
+ h, &p) == -1) {
+ fail("unable to unpack");
+ return;
+ }
ck_assert_int_eq(byte, 18);
}
END_TEST
u_int16_t word = 7874;
void *p;
p = (char*)&h->data;
- fail_unless(ctl_msg_pack_structure("w", &word, sizeof(u_int16_t),
- h, &p) != -1);
+ if (ctl_msg_pack_structure("w", &word, sizeof(u_int16_t),
+ h, &p) == -1) {
+ fail("unable to pack");
+ return;
+ }
mark_point();
p = (char*)&h->data;
- fail_unless(ctl_msg_unpack_structure("w", &word, sizeof(u_int16_t),
- h, &p) != -1);
+ if (ctl_msg_unpack_structure("w", &word, sizeof(u_int16_t),
+ h, &p) == -1) {
+ fail("unable to unpack");
+ return;
+ }
ck_assert_int_eq(word, 7874);
}
END_TEST
u_int32_t l = 14523657;
void *p;
p = (char*)&h->data;
- fail_unless(ctl_msg_pack_structure("l", &l, sizeof(u_int32_t),
- h, &p) != -1);
+ if (ctl_msg_pack_structure("l", &l, sizeof(u_int32_t),
+ h, &p) == -1) {
+ fail("unable to pack");
+ return;
+ }
mark_point();
p = (char*)&h->data;
- fail_unless(ctl_msg_unpack_structure("l", &l, sizeof(u_int32_t),
- h, &p) != -1);
+ if (ctl_msg_unpack_structure("l", &l, sizeof(u_int32_t),
+ h, &p) == -1) {
+ fail("unable to unpack");
+ return;
+ }
ck_assert_int_eq(l, 14523657);
}
END_TEST
void *p;
t2 = t;
p = (char*)&h->data;
- fail_unless(ctl_msg_pack_structure("t", &t, sizeof(time_t),
- h, &p) != -1);
+ if (ctl_msg_pack_structure("t", &t, sizeof(time_t),
+ h, &p) == -1) {
+ fail("unable to pack");
+ return;
+ }
mark_point();
p = (char*)&h->data;
- fail_unless(ctl_msg_unpack_structure("t", &t, sizeof(time_t),
- h, &p) != -1);
+ if (ctl_msg_unpack_structure("t", &t, sizeof(time_t),
+ h, &p) == -1) {
+ fail("unable to unpack");
+ return;
+ }
ck_assert_int_eq(t, t2);
}
END_TEST
char *rs;
void *p;
p = (char*)&h->data;
- fail_unless(ctl_msg_pack_structure("s", &s, sizeof(char *),
- h, &p) != -1);
+ if (ctl_msg_pack_structure("s", &s, sizeof(char *),
+ h, &p) == -1) {
+ fail("unable to pack");
+ return;
+ }
mark_point();
p = (char*)&h->data;
- fail_unless(ctl_msg_unpack_structure("s", &rs, sizeof(char *),
- h, &p) != -1);
+ if (ctl_msg_unpack_structure("s", &rs, sizeof(char *),
+ h, &p) == -1) {
+ fail("unable to unpack");
+ return;
+ }
ck_assert_str_eq(s, rs);
ck_assert_str_eq(rs, "My simple string");
free(rs);
char *rs;
void *p;
p = (char*)&h->data;
- fail_unless(ctl_msg_pack_structure("s", &s, sizeof(char *),
- h, &p) != -1);
+ if (ctl_msg_pack_structure("s", &s, sizeof(char *),
+ h, &p) == -1) {
+ fail("unable to pack");
+ return;
+ }
mark_point();
p = (char*)&h->data;
- fail_unless(ctl_msg_unpack_structure("s", &rs, sizeof(char *),
- h, &p) != -1);
+ if (ctl_msg_unpack_structure("s", &rs, sizeof(char *),
+ h, &p) == -1) {
+ fail("unable to unpack");
+ return;
+ }
ck_assert_str_eq(s, rs);
ck_assert_int_eq(strlen(rs), 0);
free(rs);
t.l = strlen(t.s);
p = (char*)&h->data;
- fail_unless(ctl_msg_pack_structure("C", &t, sizeof(struct tpls),
- h, &p) != -1);
+ if (ctl_msg_pack_structure("C", &t, sizeof(struct tpls),
+ h, &p) == -1) {
+ fail("unable to pack");
+ return;
+ }
mark_point();
p = (char*)&h->data;
- fail_unless(ctl_msg_unpack_structure("C", &t, sizeof(struct tpls),
- h, &p) != -1);
+ if (ctl_msg_unpack_structure("C", &t, sizeof(struct tpls),
+ h, &p) == -1) {
+ fail("unable to unpack");
+ return;
+ }
ck_assert_int_eq(t.l, strlen("My string"));
fail_unless(memcmp(t.s, "My string", t.l) == 0);
free(t.s);
t.g = 1246799447;
p = (char*)&h->data;
- fail_unless(ctl_msg_pack_structure("bwlbPbt", &t, sizeof(struct tps1),
- h, &p) != -1);
+ if (ctl_msg_pack_structure("bwlbPbt", &t, sizeof(struct tps1),
+ h, &p) == -1) {
+ fail("unable to pack");
+ return;
+ }
mark_point();
p = (char*)&h->data;
- fail_unless(ctl_msg_unpack_structure("bwlbPbt", &t, sizeof(struct tps1),
- h, &p) != -1);
+ if (ctl_msg_unpack_structure("bwlbPbt", &t, sizeof(struct tps1),
+ h, &p) == -1) {
+ fail("unable to unpack");
+ return;
+ }
ck_assert_int_eq(t.a, 129);
ck_assert_int_eq(t.b, 37814);
ck_assert_int_eq(t.c, 3456781258);
t.i = 12;
p = (char*)&h->data;
- fail_unless(ctl_msg_pack_structure("bPwPlPtPb", &t, sizeof(struct tps2),
- h, &p) != -1);
+ if (ctl_msg_pack_structure("bPwPlPtPb", &t, sizeof(struct tps2),
+ h, &p) == -1) {
+ fail("unable to pack");
+ return;
+ }
mark_point();
p = (char*)&h->data;
- fail_unless(ctl_msg_unpack_structure("bPwPlPtPb", &t, sizeof(struct tps2),
- h, &p) != -1);
+ if (ctl_msg_unpack_structure("bPwPlPtPb", &t, sizeof(struct tps2),
+ h, &p) == -1) {
+ fail("unable to unpack");
+ return;
+ }
ck_assert_int_eq(t.a, 129);
ck_assert_int_eq(t.c, 37814);
ck_assert_int_eq(t.e, 3456781258);
t.m = "Last string";
p = (char*)&h->data;
- fail_unless(ctl_msg_pack_structure("bswslstsbCbs", &t, sizeof(struct tps3),
- h, &p) != -1);
+ if (ctl_msg_pack_structure("bswslstsbCbs", &t, sizeof(struct tps3),
+ h, &p) == -1) {
+ fail("unable to pack");
+ return;
+ }
mark_point();
p = (char*)&h->data;
- fail_unless(ctl_msg_unpack_structure("bswslstsbCbs", &t, sizeof(struct tps3),
- h, &p) != -1);
+ if (ctl_msg_unpack_structure("bswslstsbCbs", &t, sizeof(struct tps3),
+ h, &p) == -1) {
+ fail("unable to unpack");
+ return;
+ }
ck_assert_int_eq(t.a, 129);
ck_assert_str_eq(t.b, "First string");
ck_assert_int_eq(t.c, 37814);
t.j = 12;
p = (char*)&h->data;
- fail_unless(ctl_msg_pack_structure(TPS4, &t, sizeof(struct tps4),
- h, &p) != -1);
+ if (ctl_msg_pack_structure(TPS4, &t, sizeof(struct tps4),
+ h, &p) == -1) {
+ fail("unable to pack");
+ return;
+ }
mark_point();
p = (char*)&h->data;
- fail_unless(ctl_msg_unpack_structure(TPS4, &t, sizeof(struct tps4),
- h, &p) != -1);
+ if (ctl_msg_unpack_structure(TPS4, &t, sizeof(struct tps4),
+ h, &p) == -1) {
+ fail("unable to unpack");
+ return;
+ }
ck_assert_int_eq(t.a, 129);
ck_assert_int_eq(t.b.a, 178);
void *p;
f = open("/dev/urandom", O_RDONLY);
- fail_unless(f != -1);
+ if (f == -1) {
+ fail("unable to open /dev/urandom");
+ return;
+ }
n = read(f, &t, sizeof(struct tps5));
- fail_unless(n == sizeof(struct tps5),
- "Should have read %d bytes from /dev/random but got %d",
- sizeof(struct tps5), n);
+ if (n != sizeof(struct tps5)) {
+ fail("Should have read %d bytes from /dev/random but got %d",
+ sizeof(struct tps5), n);
+ close(f);
+ return;
+ }
memcpy(&tc, &t, sizeof(struct tps5));
close(f);
p = (char*)&h->data;
- fail_unless(ctl_msg_pack_structure(TPS5, &t, sizeof(struct tps5),
- h, &p) != -1);
+ if (ctl_msg_pack_structure(TPS5, &t, sizeof(struct tps5),
+ h, &p) == -1) {
+ fail("unable to pack");
+ return;
+ }
mark_point();
p = (char*)&h->data;
- fail_unless(ctl_msg_unpack_structure(TPS5, &t, sizeof(struct tps5),
- h, &p) != -1);
+ if (ctl_msg_unpack_structure(TPS5, &t, sizeof(struct tps5),
+ h, &p) == -1) {
+ fail("unable to unpack");
+ return;
+ }
fail_unless(memcmp(&t, &tc, sizeof(struct tps5)) == 0);
}
TAILQ_INIT(&l);
p = (char*)&h->data;
- fail_unless(ctl_msg_pack_list(TPL, &l, sizeof(struct tpl),
- h, &p) != -1);
+ if (ctl_msg_pack_list(TPL, &l, sizeof(struct tpl),
+ h, &p) == -1) {
+ fail("unable to pack");
+ return;
+ }
mark_point();
p = (char*)&h->data;
- fail_unless(ctl_msg_unpack_list(TPL, &l, sizeof(struct tpl),
- h, &p) != -1);
+ if (ctl_msg_unpack_list(TPL, &l, sizeof(struct tpl),
+ h, &p) == -1) {
+ fail("unable to unpack");
+ return;
+ }
fail_unless(TAILQ_EMPTY(&l));
}
mark_point();
p = (char*)&h->data;
- fail_unless(ctl_msg_pack_list(TPL, &l, sizeof(struct tpl),
- h, &p) != -1);
+ if (ctl_msg_pack_list(TPL, &l, sizeof(struct tpl),
+ h, &p) == -1) {
+ fail("unable to pack");
+ return;
+ }
mark_point();
p = (char*)&h->data;
- fail_unless(ctl_msg_unpack_list(TPL, &l, sizeof(struct tpl),
- h, &p) != -1);
+ if (ctl_msg_unpack_list(TPL, &l, sizeof(struct tpl),
+ h, &p) == -1) {
+ fail("unable to unpack");
+ return;
+ }
count = 0;
TAILQ_FOREACH(tpl4, &l, next) {