2011-06-01 23:34:35 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <strings.h>
|
|
|
|
|
|
|
|
#include "lint.h"
|
|
|
|
|
2011-06-02 11:14:43 +00:00
|
|
|
struct section *
|
|
|
|
read_section(struct epg *epg)
|
2011-06-01 23:34:35 +00:00
|
|
|
{
|
2011-06-02 11:14:43 +00:00
|
|
|
static struct section h;
|
2011-06-01 23:34:35 +00:00
|
|
|
|
|
|
|
if (epg->binsize - epg->offset < sizeof(h))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
memcpy(&h, epg->bin + epg->offset, sizeof(h));
|
2011-06-02 11:14:43 +00:00
|
|
|
if (memcmp(h.magic, SECTION_MAGIC, sizeof(h.magic)))
|
2011-06-01 23:34:35 +00:00
|
|
|
{
|
|
|
|
printf("Section header magic mismatch.\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-06-02 01:32:55 +00:00
|
|
|
h.total_length = _swap16(h.total_length);
|
|
|
|
h.service_id = _swap16(h.service_id);
|
|
|
|
h.transport_stream_id = _swap16(h.transport_stream_id);
|
|
|
|
h.original_network_id = _swap16(h.original_network_id);
|
|
|
|
|
|
|
|
h.u1.comp = _swap16(h.u1.comp);
|
|
|
|
|
2011-06-01 23:34:35 +00:00
|
|
|
epg->offset += sizeof(h);
|
|
|
|
|
|
|
|
return &h;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-06-02 11:14:43 +00:00
|
|
|
dump_section(struct section *h)
|
2011-06-01 23:34:35 +00:00
|
|
|
{
|
|
|
|
printf("Section header:\n");
|
|
|
|
DUMPINT(h, total_length);
|
|
|
|
DUMPINT(h, table_id);
|
2011-06-02 01:32:55 +00:00
|
|
|
DUMPINT(h, u1.u.syntax_indicator);
|
|
|
|
DUMPINT(h, u1.u.reserved);
|
|
|
|
DUMPINT(h, u1.u.length);
|
2011-06-01 23:34:35 +00:00
|
|
|
DUMPINT(h, service_id);
|
|
|
|
DUMPINT(h, reserved2);
|
|
|
|
DUMPINT(h, version_number);
|
|
|
|
DUMPINT(h, current_next_indicator);
|
|
|
|
DUMPINT(h, section_number);
|
|
|
|
DUMPINT(h, last_section_number);
|
|
|
|
DUMPINT(h, transport_stream_id);
|
|
|
|
DUMPINT(h, original_network_id);
|
|
|
|
DUMPINT(h, segment_last_section_number);
|
|
|
|
DUMPINT(h, last_table_id);
|
|
|
|
}
|
|
|
|
|
2011-06-02 11:14:43 +00:00
|
|
|
struct data *
|
|
|
|
read_data(struct epg *epg)
|
|
|
|
{
|
|
|
|
static struct data d;
|
|
|
|
|
|
|
|
if (epg->binsize - epg->offset < sizeof(d))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
memcpy(&d, epg->bin + epg->offset, sizeof(d));
|
|
|
|
|
|
|
|
d.event_id = _swap16(d.event_id);
|
|
|
|
d.start_date = _swap16(d.start_date);
|
|
|
|
d.u1.comp = _swap16(d.u1.comp);
|
|
|
|
|
|
|
|
epg->offset += sizeof(d);
|
|
|
|
|
|
|
|
return &d;
|
|
|
|
}
|
|
|
|
|
2011-06-01 23:34:35 +00:00
|
|
|
void
|
|
|
|
dump_data(struct data *d)
|
|
|
|
{
|
|
|
|
time_t tm;
|
|
|
|
|
|
|
|
printf("Data:\n");
|
|
|
|
DUMPINT(d, event_id);
|
|
|
|
|
|
|
|
tm = MJD_TO_UNIX(d->start_date);
|
2011-06-02 01:32:55 +00:00
|
|
|
printf(" %30s: %#x (%s)\n", "start_date",
|
|
|
|
d->start_date, ctime_nl(&tm));
|
|
|
|
|
|
|
|
printf(" %30s: %d:%02d:%02d\n", "start_time",
|
|
|
|
d->start_hour, d->start_min, d->start_sec);
|
|
|
|
printf(" %30s: %d:%02d:%02d\n", "duration",
|
|
|
|
d->dur_hour, d->dur_min, d->dur_sec);
|
|
|
|
|
|
|
|
DUMPINT(d, u1.u.running_status);
|
|
|
|
DUMPINT(d, u1.u.free_CA_mode);
|
|
|
|
DUMPINT(d, u1.u.descriptors_loop_length);
|
|
|
|
}
|
2011-06-01 23:34:35 +00:00
|
|
|
|