Make the function to generate a clock identity a global function.

This will allow code reuse in the management client.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
master
Richard Cochran 2012-08-05 14:11:18 +02:00
parent b2072076bf
commit 582a8858d7
3 changed files with 20 additions and 16 deletions

17
ptp4l.c
View File

@ -27,6 +27,7 @@
#include "print.h" #include "print.h"
#include "sk.h" #include "sk.h"
#include "transport.h" #include "transport.h"
#include "util.h"
int assume_two_step; int assume_two_step;
double configured_pi_kp, configured_pi_ki; /*see pi.c*/ double configured_pi_kp, configured_pi_ki; /*see pi.c*/
@ -38,22 +39,6 @@ static struct defaultDS ds;
static struct port_defaults pod; static struct port_defaults pod;
static struct config cfg_settings; static struct config cfg_settings;
static int generate_clock_identity(struct ClockIdentity *ci, char *name)
{
unsigned char mac[6];
if (sk_interface_macaddr(name, mac, sizeof(mac)))
return -1;
ci->id[0] = mac[0];
ci->id[1] = mac[1];
ci->id[2] = mac[2];
ci->id[3] = 0xFF;
ci->id[4] = 0xFE;
ci->id[5] = mac[3];
ci->id[6] = mac[4];
ci->id[7] = mac[5];
return 0;
}
static void usage(char *progname) static void usage(char *progname)
{ {
fprintf(stderr, fprintf(stderr,

17
util.c
View File

@ -18,6 +18,7 @@
*/ */
#include <stdio.h> #include <stdio.h>
#include "sk.h"
#include "util.h" #include "util.h"
char *ps_str[] = { char *ps_str[] = {
@ -73,3 +74,19 @@ char *pid2str(struct PortIdentity *id)
id->portNumber); id->portNumber);
return buf; return buf;
} }
int generate_clock_identity(struct ClockIdentity *ci, char *name)
{
unsigned char mac[6];
if (sk_interface_macaddr(name, mac, sizeof(mac)))
return -1;
ci->id[0] = mac[0];
ci->id[1] = mac[1];
ci->id[2] = mac[2];
ci->id[3] = 0xFF;
ci->id[4] = 0xFE;
ci->id[5] = mac[3];
ci->id[6] = mac[4];
ci->id[7] = mac[5];
return 0;
}

2
util.h
View File

@ -54,4 +54,6 @@ char *cid2str(struct ClockIdentity *id);
*/ */
char *pid2str(struct PortIdentity *id); char *pid2str(struct PortIdentity *id);
int generate_clock_identity(struct ClockIdentity *ci, char *name);
#endif #endif