Skip to content

Commit

Permalink
ptp4l: pull iface into the configure settings
Browse files Browse the repository at this point in the history
this patch modifies the ptp4l.c and config settings so that the iface list is
inside the cfg_settings structure

-v2
* Moved "struct interface" into config.h

Signed-off-by: Jacob Keller <[email protected]>
  • Loading branch information
jacob-keller authored and richardcochran committed Aug 21, 2012
1 parent 64dcf25 commit 08a6a14
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 18 deletions.
10 changes: 1 addition & 9 deletions clock.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,13 @@

#include "dm.h"
#include "ds.h"
#include "config.h"
#include "servo.h"
#include "tmv.h"
#include "transport.h"

struct ptp_message; /*forward declaration*/

#define MAX_PORTS 8

/** Defines a network interface, with PTP options. */
struct interface {
char *name;
enum delay_mechanism dm;
enum transport_type transport;
};

/** Opaque type. */
struct clock;

Expand Down
15 changes: 15 additions & 0 deletions config.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,23 @@
#define HAVE_CONFIG_H

#include "ds.h"
#include "dm.h"
#include "transport.h"

#define MAX_PORTS 8

/** Defines a network interface, with PTP options. */
struct interface {
char *name;
enum delay_mechanism dm;
enum transport_type transport;
};

struct config {
/* configured interfaces */
struct interface iface[MAX_PORTS];
int nports;

struct defaultDS *dds;
struct port_defaults *pod;
int *assume_two_step;
Expand Down
19 changes: 10 additions & 9 deletions ptp4l.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ static void usage(char *progname)
int main(int argc, char *argv[])
{
char *config = NULL, *req_phc = NULL, *progname;
int c, nports = 0, slaveonly = 0;
struct interface iface[MAX_PORTS];
int c, slaveonly = 0;
struct interface *iface = cfg_settings.iface;
int *nports = &cfg_settings.nports;
enum delay_mechanism dm = DM_E2E;
enum transport_type transport = TRANS_UDP_IPV4;
enum timestamp_type timestamping = TS_HARDWARE;
Expand Down Expand Up @@ -117,11 +118,11 @@ int main(int argc, char *argv[])
config = optarg;
break;
case 'i':
if (nports < MAX_PORTS) {
iface[nports].name = optarg;
iface[nports].dm = dm;
iface[nports].transport = transport;
nports++;
if (*nports < MAX_PORTS) {
iface[*nports].name = optarg;
iface[*nports].dm = dm;
iface[*nports].transport = transport;
(*nports)++;
} else {
fprintf(stderr, "too many interfaces\n");
return -1;
Expand Down Expand Up @@ -154,7 +155,7 @@ int main(int argc, char *argv[])
}
}

if (!nports) {
if (!*nports) {
fprintf(stderr, "no interface specified\n");
usage(progname);
return -1;
Expand Down Expand Up @@ -219,7 +220,7 @@ int main(int argc, char *argv[])
ds.clockQuality.clockClass = 255;
}

clock = clock_create(phc_index, iface, nports, timestamping, &ds, &pod);
clock = clock_create(phc_index, iface, *nports, timestamping, &ds, &pod);
if (!clock) {
fprintf(stderr, "failed to create a clock\n");
return -1;
Expand Down

0 comments on commit 08a6a14

Please sign in to comment.