transport: adds interface for getting type, and physical/protocol address

Needed for CLOCK_DESCRIPTION management TLV.
master
Geoff Salmon 2013-01-08 19:21:24 -05:00 committed by Richard Cochran
parent 5c47cbfedf
commit e010937783
3 changed files with 65 additions and 5 deletions

View File

@ -53,23 +53,51 @@ int transport_peer(struct transport *t, struct fdarray *fda, int event,
return t->send(t, fda, event, 1, buf, buflen, hwts);
}
int transport_physical_addr(struct transport *t, uint8_t *addr)
{
if (t->physical_addr) {
return t->physical_addr(t, addr);
}
return 0;
}
int transport_protocol_addr(struct transport *t, uint8_t *addr)
{
if (t->protocol_addr) {
return t->protocol_addr(t, addr);
}
return 0;
}
enum transport_type transport_type(struct transport *t)
{
return t->type;
}
struct transport *transport_create(enum transport_type type)
{
struct transport *t = NULL;
switch (type) {
case TRANS_UDS:
return uds_transport_create();
t = uds_transport_create();
break;
case TRANS_UDP_IPV4:
return udp_transport_create();
t = udp_transport_create();
break;
case TRANS_UDP_IPV6:
return udp6_transport_create();
t = udp6_transport_create();
break;
case TRANS_IEEE_802_3:
return raw_transport_create();
t = raw_transport_create();
break;
case TRANS_DEVICENET:
case TRANS_CONTROLNET:
case TRANS_PROFINET:
break;
}
return NULL;
if (t)
t->type = type;
return t;
}
void transport_destroy(struct transport *t)

View File

@ -21,6 +21,7 @@
#define HAVE_TRANSPORT_H
#include <time.h>
#include <inttypes.h>
#include "fd.h"
@ -74,6 +75,31 @@ int transport_send(struct transport *t, struct fdarray *fda, int event,
int transport_peer(struct transport *t, struct fdarray *fda, int event,
void *buf, int buflen, struct hw_timestamp *hwts);
/**
* Returns the transport's type.
*/
enum transport_type transport_type(struct transport *t);
#define TRANSPORT_ADDR_LEN 16
/**
* Gets the transport's physical address.
* @param t The transport.
* @param addr The address will be written to this buffer.
* @return The number of bytes written to the buffer. Will be 0-16
* bytes
*/
int transport_physical_addr(struct transport *t, uint8_t *addr);
/**
* Gets the transport's protocol address.
* @param t The transport.
* @param addr The address will be written to this buffer.
* @return The number of bytes written to the buffer. Will be 0-16
* bytes
*/
int transport_protocol_addr(struct transport *t, uint8_t *addr);
/**
* Allocate an instance of the specified transport.
* @param type Which transport to obtain.

View File

@ -26,6 +26,8 @@
#include "transport.h"
struct transport {
enum transport_type type;
int (*close)(struct transport *t, struct fdarray *fda);
int (*open)(struct transport *t, char *name, struct fdarray *fda,
@ -38,6 +40,10 @@ struct transport {
void *buf, int buflen, struct hw_timestamp *hwts);
void (*release)(struct transport *t);
int (*physical_addr)(struct transport *t, uint8_t *addr);
int (*protocol_addr)(struct transport *t, uint8_t *addr);
};
#endif