Make functions and structs dealing with string literals const correct.
This allows the compiler to check if someone writes into string literals. Signed-off-by: Stephan Gatzka <stephan.gatzka@gmail.com>master
parent
886112e202
commit
110849d422
2
msg.c
2
msg.c
|
@ -379,7 +379,7 @@ int msg_pre_send(struct ptp_message *m)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *msg_type_string(int type)
|
const char *msg_type_string(int type)
|
||||||
{
|
{
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case SYNC:
|
case SYNC:
|
||||||
|
|
2
msg.h
2
msg.h
|
@ -298,7 +298,7 @@ int msg_pre_send(struct ptp_message *m);
|
||||||
* @param type Value of the messageType field as returned by @ref msg_type().
|
* @param type Value of the messageType field as returned by @ref msg_type().
|
||||||
* @return String describing the message type.
|
* @return String describing the message type.
|
||||||
*/
|
*/
|
||||||
char *msg_type_string(int type);
|
const char *msg_type_string(int type);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Print messages for debugging purposes.
|
* Print messages for debugging purposes.
|
||||||
|
|
5
pmc.c
5
pmc.c
|
@ -109,7 +109,7 @@ struct management_id idtab[] = {
|
||||||
{ "PORT_DATA_SET_NP", PORT_DATA_SET_NP, do_set_action },
|
{ "PORT_DATA_SET_NP", PORT_DATA_SET_NP, do_set_action },
|
||||||
};
|
};
|
||||||
|
|
||||||
static char *action_string[] = {
|
static const char *action_string[] = {
|
||||||
"GET",
|
"GET",
|
||||||
"SET",
|
"SET",
|
||||||
"RESPONSE",
|
"RESPONSE",
|
||||||
|
@ -711,7 +711,8 @@ static void usage(char *progname)
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
char *iface_name = NULL, *progname;
|
const char *iface_name = NULL;
|
||||||
|
char *progname;
|
||||||
int c, cnt, length, tmo = -1, batch_mode = 0, zero_datalen = 0;
|
int c, cnt, length, tmo = -1, batch_mode = 0, zero_datalen = 0;
|
||||||
char line[1024], *command = NULL;
|
char line[1024], *command = NULL;
|
||||||
enum transport_type transport_type = TRANS_UDP_IPV4;
|
enum transport_type transport_type = TRANS_UDP_IPV4;
|
||||||
|
|
|
@ -61,7 +61,7 @@ struct pmc {
|
||||||
int zero_length_gets;
|
int zero_length_gets;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct pmc *pmc_create(enum transport_type transport_type, char *iface_name,
|
struct pmc *pmc_create(enum transport_type transport_type, const char *iface_name,
|
||||||
UInteger8 boundary_hops, UInteger8 domain_number,
|
UInteger8 boundary_hops, UInteger8 domain_number,
|
||||||
UInteger8 transport_specific, int zero_datalen)
|
UInteger8 transport_specific, int zero_datalen)
|
||||||
{
|
{
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
|
|
||||||
struct pmc;
|
struct pmc;
|
||||||
|
|
||||||
struct pmc *pmc_create(enum transport_type transport_type, char *iface_name,
|
struct pmc *pmc_create(enum transport_type transport_type, const char *iface_name,
|
||||||
UInteger8 boundary_hops, UInteger8 domain_number,
|
UInteger8 boundary_hops, UInteger8 domain_number,
|
||||||
UInteger8 transport_specific, int zero_datalen);
|
UInteger8 transport_specific, int zero_datalen);
|
||||||
|
|
||||||
|
|
4
raw.c
4
raw.c
|
@ -148,7 +148,7 @@ static int raw_close(struct transport *t, struct fdarray *fda)
|
||||||
unsigned char ptp_dst_mac[MAC_LEN] = { PTP_DST_MAC };
|
unsigned char ptp_dst_mac[MAC_LEN] = { PTP_DST_MAC };
|
||||||
unsigned char p2p_dst_mac[MAC_LEN] = { P2P_DST_MAC };
|
unsigned char p2p_dst_mac[MAC_LEN] = { P2P_DST_MAC };
|
||||||
|
|
||||||
static int open_socket(char *name, int event)
|
static int open_socket(const char *name, int event)
|
||||||
{
|
{
|
||||||
struct sockaddr_ll addr;
|
struct sockaddr_ll addr;
|
||||||
int fd, index;
|
int fd, index;
|
||||||
|
@ -184,7 +184,7 @@ no_socket:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int raw_open(struct transport *t, char *name,
|
static int raw_open(struct transport *t, const char *name,
|
||||||
struct fdarray *fda, enum timestamp_type ts_type)
|
struct fdarray *fda, enum timestamp_type ts_type)
|
||||||
{
|
{
|
||||||
struct raw *raw = container_of(t, struct raw, t);
|
struct raw *raw = container_of(t, struct raw, t);
|
||||||
|
|
12
sk.c
12
sk.c
|
@ -40,7 +40,7 @@ int sk_check_fupsync;
|
||||||
|
|
||||||
/* private methods */
|
/* private methods */
|
||||||
|
|
||||||
static int hwts_init(int fd, char *device, int rx_filter, int one_step)
|
static int hwts_init(int fd, const char *device, int rx_filter, int one_step)
|
||||||
{
|
{
|
||||||
struct ifreq ifreq;
|
struct ifreq ifreq;
|
||||||
struct hwtstamp_config cfg, req;
|
struct hwtstamp_config cfg, req;
|
||||||
|
@ -77,7 +77,7 @@ static int hwts_init(int fd, char *device, int rx_filter, int one_step)
|
||||||
|
|
||||||
/* public methods */
|
/* public methods */
|
||||||
|
|
||||||
int sk_interface_index(int fd, char *name)
|
int sk_interface_index(int fd, const char *name)
|
||||||
{
|
{
|
||||||
struct ifreq ifreq;
|
struct ifreq ifreq;
|
||||||
int err;
|
int err;
|
||||||
|
@ -102,7 +102,7 @@ int sk_general_init(int fd)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int sk_get_ts_info(char *name, struct sk_ts_info *sk_info)
|
int sk_get_ts_info(const char *name, struct sk_ts_info *sk_info)
|
||||||
{
|
{
|
||||||
#ifdef ETHTOOL_GET_TS_INFO
|
#ifdef ETHTOOL_GET_TS_INFO
|
||||||
struct ethtool_ts_info info;
|
struct ethtool_ts_info info;
|
||||||
|
@ -146,7 +146,7 @@ failed:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int sk_interface_macaddr(char *name, unsigned char *mac, int len)
|
int sk_interface_macaddr(const char *name, unsigned char *mac, int len)
|
||||||
{
|
{
|
||||||
struct ifreq ifreq;
|
struct ifreq ifreq;
|
||||||
int err, fd;
|
int err, fd;
|
||||||
|
@ -172,7 +172,7 @@ int sk_interface_macaddr(char *name, unsigned char *mac, int len)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int sk_interface_addr(char *name, int family, uint8_t *addr, int len)
|
int sk_interface_addr(const char *name, int family, uint8_t *addr, int len)
|
||||||
{
|
{
|
||||||
struct ifaddrs *ifaddr, *i;
|
struct ifaddrs *ifaddr, *i;
|
||||||
int copy_len, result = -1;
|
int copy_len, result = -1;
|
||||||
|
@ -285,7 +285,7 @@ int sk_receive(int fd, void *buf, int buflen,
|
||||||
return cnt;
|
return cnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
int sk_timestamping_init(int fd, char *device, enum timestamp_type type,
|
int sk_timestamping_init(int fd, const char *device, enum timestamp_type type,
|
||||||
enum transport_type transport)
|
enum transport_type transport)
|
||||||
{
|
{
|
||||||
int err, filter1, filter2 = 0, flags, one_step;
|
int err, filter1, filter2 = 0, flags, one_step;
|
||||||
|
|
10
sk.h
10
sk.h
|
@ -44,7 +44,7 @@ struct sk_ts_info {
|
||||||
* @param device The name of the network interface of interest.
|
* @param device The name of the network interface of interest.
|
||||||
* @return The result from the SIOCGIFINDEX ioctl.
|
* @return The result from the SIOCGIFINDEX ioctl.
|
||||||
*/
|
*/
|
||||||
int sk_interface_index(int fd, char *device);
|
int sk_interface_index(int fd, const char *device);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prepare a given socket for PTP "general" messages.
|
* Prepare a given socket for PTP "general" messages.
|
||||||
|
@ -59,7 +59,7 @@ int sk_general_init(int fd);
|
||||||
* @param info Struct containing obtained timestamping information.
|
* @param info Struct containing obtained timestamping information.
|
||||||
* @return zero on success, negative on failure.
|
* @return zero on success, negative on failure.
|
||||||
*/
|
*/
|
||||||
int sk_get_ts_info(char *name, struct sk_ts_info *sk_info);
|
int sk_get_ts_info(const char *name, struct sk_ts_info *sk_info);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Obtain the MAC address of a network interface.
|
* Obtain the MAC address of a network interface.
|
||||||
|
@ -68,7 +68,7 @@ int sk_get_ts_info(char *name, struct sk_ts_info *sk_info);
|
||||||
* @param len Length of 'mac'
|
* @param len Length of 'mac'
|
||||||
* @return Zero on success, non-zero otherwise.
|
* @return Zero on success, non-zero otherwise.
|
||||||
*/
|
*/
|
||||||
int sk_interface_macaddr(char *name, unsigned char *mac, int len);
|
int sk_interface_macaddr(const char *name, unsigned char *mac, int len);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Obtains the first IP address assigned to a network interface.
|
* Obtains the first IP address assigned to a network interface.
|
||||||
|
@ -78,7 +78,7 @@ int sk_interface_macaddr(char *name, unsigned char *mac, int len);
|
||||||
* @param len Length of 'addr'
|
* @param len Length of 'addr'
|
||||||
* @return The number of bytes written to addr on success, -1 otherwise.
|
* @return The number of bytes written to addr on success, -1 otherwise.
|
||||||
*/
|
*/
|
||||||
int sk_interface_addr(char *name, int family, uint8_t *addr, int len);
|
int sk_interface_addr(const char *name, int family, uint8_t *addr, int len);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read a message from a socket.
|
* Read a message from a socket.
|
||||||
|
@ -100,7 +100,7 @@ int sk_receive(int fd, void *buf, int buflen,
|
||||||
* @param transport The type of transport used.
|
* @param transport The type of transport used.
|
||||||
* @return Zero on success, non-zero otherwise.
|
* @return Zero on success, non-zero otherwise.
|
||||||
*/
|
*/
|
||||||
int sk_timestamping_init(int fd, char *device, enum timestamp_type type,
|
int sk_timestamping_init(int fd, const char *device, enum timestamp_type type,
|
||||||
enum transport_type transport);
|
enum transport_type transport);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -29,7 +29,7 @@ int transport_close(struct transport *t, struct fdarray *fda)
|
||||||
return t->close(t, fda);
|
return t->close(t, fda);
|
||||||
}
|
}
|
||||||
|
|
||||||
int transport_open(struct transport *t, char *name,
|
int transport_open(struct transport *t, const char *name,
|
||||||
struct fdarray *fda, enum timestamp_type tt)
|
struct fdarray *fda, enum timestamp_type tt)
|
||||||
{
|
{
|
||||||
return t->open(t, name, fda, tt);
|
return t->open(t, name, fda, tt);
|
||||||
|
|
|
@ -64,7 +64,7 @@ struct transport;
|
||||||
|
|
||||||
int transport_close(struct transport *t, struct fdarray *fda);
|
int transport_close(struct transport *t, struct fdarray *fda);
|
||||||
|
|
||||||
int transport_open(struct transport *t, char *name,
|
int transport_open(struct transport *t, const char *name,
|
||||||
struct fdarray *fda, enum timestamp_type tt);
|
struct fdarray *fda, enum timestamp_type tt);
|
||||||
|
|
||||||
int transport_recv(struct transport *t, int fd,
|
int transport_recv(struct transport *t, int fd,
|
||||||
|
|
|
@ -30,7 +30,7 @@ struct transport {
|
||||||
|
|
||||||
int (*close)(struct transport *t, struct fdarray *fda);
|
int (*close)(struct transport *t, struct fdarray *fda);
|
||||||
|
|
||||||
int (*open)(struct transport *t, char *name, struct fdarray *fda,
|
int (*open)(struct transport *t, const char *name, struct fdarray *fda,
|
||||||
enum timestamp_type tt);
|
enum timestamp_type tt);
|
||||||
|
|
||||||
int (*recv)(struct transport *t, int fd, void *buf, int buflen,
|
int (*recv)(struct transport *t, int fd, void *buf, int buflen,
|
||||||
|
|
4
udp.c
4
udp.c
|
@ -93,7 +93,7 @@ static int udp_close(struct transport *t, struct fdarray *fda)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int open_socket(char *name, struct in_addr mc_addr[2], short port)
|
static int open_socket(const char *name, struct in_addr mc_addr[2], short port)
|
||||||
{
|
{
|
||||||
struct sockaddr_in addr;
|
struct sockaddr_in addr;
|
||||||
int fd, index, on = 1;
|
int fd, index, on = 1;
|
||||||
|
@ -148,7 +148,7 @@ enum { MC_PRIMARY, MC_PDELAY };
|
||||||
|
|
||||||
static struct in_addr mcast_addr[2];
|
static struct in_addr mcast_addr[2];
|
||||||
|
|
||||||
static int udp_open(struct transport *t, char *name, struct fdarray *fda,
|
static int udp_open(struct transport *t, const char *name, struct fdarray *fda,
|
||||||
enum timestamp_type ts_type)
|
enum timestamp_type ts_type)
|
||||||
{
|
{
|
||||||
struct udp *udp = container_of(t, struct udp, t);
|
struct udp *udp = container_of(t, struct udp, t);
|
||||||
|
|
4
udp6.c
4
udp6.c
|
@ -100,7 +100,7 @@ static int udp6_close(struct transport *t, struct fdarray *fda)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int open_socket_ipv6(char *name, struct in6_addr mc_addr[2], short port,
|
static int open_socket_ipv6(const char *name, struct in6_addr mc_addr[2], short port,
|
||||||
int *interface_index)
|
int *interface_index)
|
||||||
{
|
{
|
||||||
struct sockaddr_in6 addr;
|
struct sockaddr_in6 addr;
|
||||||
|
@ -158,7 +158,7 @@ enum { MC_PRIMARY, MC_PDELAY };
|
||||||
|
|
||||||
static struct in6_addr mc6_addr[2];
|
static struct in6_addr mc6_addr[2];
|
||||||
|
|
||||||
static int udp6_open(struct transport *t, char *name, struct fdarray *fda,
|
static int udp6_open(struct transport *t, const char *name, struct fdarray *fda,
|
||||||
enum timestamp_type ts_type)
|
enum timestamp_type ts_type)
|
||||||
{
|
{
|
||||||
struct udp6 *udp6 = container_of(t, struct udp6, t);
|
struct udp6 *udp6 = container_of(t, struct udp6, t);
|
||||||
|
|
2
uds.c
2
uds.c
|
@ -46,7 +46,7 @@ static int uds_close(struct transport *t, struct fdarray *fda)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int uds_open(struct transport *t, char *name, struct fdarray *fda,
|
static int uds_open(struct transport *t, const char *name, struct fdarray *fda,
|
||||||
enum timestamp_type tt)
|
enum timestamp_type tt)
|
||||||
{
|
{
|
||||||
int fd, err;
|
int fd, err;
|
||||||
|
|
6
util.c
6
util.c
|
@ -28,7 +28,7 @@
|
||||||
#define NS_PER_HOUR (3600 * NS_PER_SEC)
|
#define NS_PER_HOUR (3600 * NS_PER_SEC)
|
||||||
#define NS_PER_DAY (24 * NS_PER_HOUR)
|
#define NS_PER_DAY (24 * NS_PER_HOUR)
|
||||||
|
|
||||||
char *ps_str[] = {
|
const char *ps_str[] = {
|
||||||
"NONE",
|
"NONE",
|
||||||
"INITIALIZING",
|
"INITIALIZING",
|
||||||
"FAULTY",
|
"FAULTY",
|
||||||
|
@ -42,7 +42,7 @@ char *ps_str[] = {
|
||||||
"GRAND_MASTER",
|
"GRAND_MASTER",
|
||||||
};
|
};
|
||||||
|
|
||||||
char *ev_str[] = {
|
const char *ev_str[] = {
|
||||||
"NONE",
|
"NONE",
|
||||||
"POWERUP",
|
"POWERUP",
|
||||||
"INITIALIZE",
|
"INITIALIZE",
|
||||||
|
@ -98,7 +98,7 @@ int str2pid(const char *s, struct PortIdentity *result)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int generate_clock_identity(struct ClockIdentity *ci, char *name)
|
int generate_clock_identity(struct ClockIdentity *ci, const char *name)
|
||||||
{
|
{
|
||||||
unsigned char mac[6];
|
unsigned char mac[6];
|
||||||
if (sk_interface_macaddr(name, mac, sizeof(mac)))
|
if (sk_interface_macaddr(name, mac, sizeof(mac)))
|
||||||
|
|
6
util.h
6
util.h
|
@ -26,12 +26,12 @@
|
||||||
/**
|
/**
|
||||||
* Table of human readable strings, one for each port state.
|
* Table of human readable strings, one for each port state.
|
||||||
*/
|
*/
|
||||||
extern char *ps_str[];
|
extern const char *ps_str[];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Table of human readable strings, one for each port event.
|
* Table of human readable strings, one for each port event.
|
||||||
*/
|
*/
|
||||||
extern char *ev_str[];
|
extern const char *ev_str[];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a clock identity into a human readable string.
|
* Convert a clock identity into a human readable string.
|
||||||
|
@ -64,7 +64,7 @@ char *pid2str(struct PortIdentity *id);
|
||||||
*/
|
*/
|
||||||
int str2pid(const char *s, struct PortIdentity *result);
|
int str2pid(const char *s, struct PortIdentity *result);
|
||||||
|
|
||||||
int generate_clock_identity(struct ClockIdentity *ci, char *name);
|
int generate_clock_identity(struct ClockIdentity *ci, const char *name);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copies a PTPText to a static_ptp_text. This copies the text into
|
* Copies a PTPText to a static_ptp_text. This copies the text into
|
||||||
|
|
Loading…
Reference in New Issue