From 4df924b253dbe3dec734fba4a1d7b88f35c03df4 Mon Sep 17 00:00:00 2001 From: Jiri Benc Date: Tue, 22 Apr 2014 16:01:00 +0200 Subject: [PATCH] Implement transport_sendto Also, document transport_send, transport_peer and transport_sendto usage. Signed-off-by: Jiri Benc --- transport.c | 8 ++++++++ transport.h | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/transport.c b/transport.c index b2d4dd1..fc18740 100644 --- a/transport.c +++ b/transport.c @@ -58,6 +58,14 @@ int transport_peer(struct transport *t, struct fdarray *fda, int event, return t->send(t, fda, event, 1, msg, len, NULL, &msg->hwts); } +int transport_sendto(struct transport *t, struct fdarray *fda, int event, + struct ptp_message *msg) +{ + int len = ntohs(msg->header.messageLength); + + return t->send(t, fda, event, 0, msg, len, &msg->address, &msg->hwts); +} + int transport_physical_addr(struct transport *t, uint8_t *addr) { if (t->physical_addr) { diff --git a/transport.h b/transport.h index 5153c46..8e0d421 100644 --- a/transport.h +++ b/transport.h @@ -57,12 +57,45 @@ int transport_open(struct transport *t, const char *name, int transport_recv(struct transport *t, int fd, struct ptp_message *msg); +/** + * Sends the PTP message using the given transport. The message is sent to + * the default (usually multicast) address, any address field in the + * ptp_message itself is ignored. + * @param t The transport. + * @param fda The array of descriptors filled in by transport_open. + * @param event 1 for event message, 0 for general message. + * @param msg The message to send. + * @return Number of bytes send, or negative value in case of an error. + */ int transport_send(struct transport *t, struct fdarray *fda, int event, struct ptp_message *msg); +/** + * Sends the PTP message using the given transport. The message is sent to + * the address used for p2p delay measurements (usually a multicast + * address), any address field in the ptp_message itself is ignored. + * @param t The transport. + * @param fda The array of descriptors filled in by transport_open. + * @param event 1 for event message, 0 for general message. + * @param msg The message to send. + * @return Number of bytes send, or negative value in case of an error. + */ int transport_peer(struct transport *t, struct fdarray *fda, int event, struct ptp_message *msg); +/** + * Sends the PTP message using the given transport. The address has to be + * provided in the address field of the message. + * @param t The transport. + * @param fda The array of descriptors filled in by transport_open. + * @param event 1 for event message, 0 for general message. + * @param msg The message to send. The address of the destination has to + * be set in the address field. + * @return Number of bytes send, or negative value in case of an error. + */ +int transport_sendto(struct transport *t, struct fdarray *fda, int event, + struct ptp_message *msg); + /** * Returns the transport's type. */