19 #ifndef __PTPMGMT_SOCK_H
20 #define __PTPMGMT_SOCK_H
24 #ifdef __PTPMGMT_HAVE_SYS_UN_H
27 #ifdef __PTPMGMT_HAVE_NETINET_IN_H
28 #include <netinet/in.h>
31 #include <linux/if_packet.h>
36 __PTPMGMT_NAMESPACE_BEGIN
48 bool m_isInit =
false;
50 bool sendReply(ssize_t cnt,
size_t len)
const;
51 virtual bool sendBase(
const void *msg,
size_t len) = 0;
52 virtual ssize_t rcvBase(
void *buf,
size_t bufSize,
bool block) = 0;
53 virtual bool initBase() = 0;
54 virtual void closeChild() {}
69 bool init() {
return initBase(); }
78 bool send(
const void *msg,
size_t len)
79 {
return sendBase(msg, len); }
89 {
return sendBase(buf.
get(), len); }
100 {
return sendBase(buf.
get(), len); }
110 ssize_t
rcv(
void *buf,
size_t bufSize,
bool block =
false)
111 {
return rcvBase(buf, bufSize, block); }
120 ssize_t
rcv(
Buf &buf,
bool block =
false)
121 {
return rcvBase(buf.
get(), buf.
size(), block); }
132 {
return rcvBase(buf.
get(), buf.
size(), block); }
149 #ifdef __PTPMGMT_SWIG_THREAD_START
150 __PTPMGMT_SWIG_THREAD_START;
166 bool poll(uint64_t timeout_ms = 0)
const;
184 bool tpoll(uint64_t &timeout_ms)
const;
185 #ifdef __PTPMGMT_SWIG_THREAD_END
186 __PTPMGMT_SWIG_THREAD_END;
199 std::string m_me, m_peer, m_homeDir, m_lastFrom;
200 sockaddr_un m_peerAddr;
201 bool setPeerInternal(
const std::string &str,
bool useAbstract);
202 bool sendAny(
const void *msg,
size_t len,
const sockaddr_un &addr)
const;
203 static void setUnixAddr(sockaddr_un &addr,
const std::string &str);
206 bool sendBase(
const void *msg,
size_t len)
override final;
207 ssize_t rcvBase(
void *buf,
size_t bufSize,
bool block)
override final;
208 bool initBase()
override final;
209 void closeChild()
override final;
238 return setPeerInternal(
string, useAbstract);
248 return setPeerInternal(cfg.
uds_address(section),
false);
297 const std::string &useDef =
"");
318 bool sendTo(
const void *msg,
size_t len,
const std::string &addrStr)
const;
331 bool sendTo(
const void *msg,
size_t len,
const std::string &addrStr,
332 bool useAbstract)
const;
345 bool sendTo(
Buf &buf,
size_t len,
const std::string &addrStr,
346 bool useAbstract =
false)
const
347 {
return sendTo(buf.
get(), len, addrStr, useAbstract); }
359 ssize_t
rcvFrom(
void *buf,
size_t bufSize, std::string &from,
360 bool block =
false)
const;
371 ssize_t
rcvFrom(
Buf &buf, std::string &from,
bool block =
false)
const
383 ssize_t
rcvFrom(
void *buf,
size_t bufSize,
bool block =
false)
384 {
return rcvFrom(buf, bufSize, m_lastFrom, block); }
435 return !addr.empty() && addr[0] == 0;
448 std::string m_ifName;
451 bool m_have_if =
false;
452 bool setInt(
const IfInfo &ifObj);
454 virtual bool setAllBase(
const ConfigFile &cfg,
const std::string §ion) = 0;
498 const std::string §ion =
"") {
499 return setIf(ifObj) && setAllBase(cfg, section);
514 const std::string §ion =
"") {
515 return setAll(ifObj, cfg, section) && initBase();
529 int m_domain, m_udp_ttl = -1;
533 const char *m_mcast_str;
535 SockIp(
int domain,
const char *mcast, sockaddr *addr,
size_t len);
536 virtual bool initIp() = 0;
537 bool sendBase(
const void *msg,
size_t len)
override final;
538 ssize_t rcvBase(
void *buf,
size_t bufSize,
bool block)
override final;
539 bool initBase()
override final;
577 bool initIp()
override final;
579 const std::string §ion)
override final;
592 sockaddr_in6 m_addr6;
593 int m_udp6_scope = -1;
597 bool initIp()
override final;
599 const std::string §ion)
override final;
635 int m_socket_priority = -1;
636 sockaddr_ll m_addr = {0};
637 iovec m_iov_tx[2], m_iov_rx[2];
638 msghdr m_msg_tx = {0}, m_msg_rx = {0};
640 uint8_t m_rx_buf[
sizeof(ethhdr)];
645 const std::string §ion)
override final;
646 bool sendBase(
const void *msg,
size_t len)
override final;
647 ssize_t rcvBase(
void *buf,
size_t bufSize,
bool block)
override final;
648 bool initBase()
override final;
729 __PTPMGMT_NAMESPACE_END
Buffer for send, receive, build, and parse.
C interface to configuration class.
C interface to network and PHC classes.
C interface to sockets classes.
Hold octets.
Definition: bin.h:28
size_t size() const
Definition: buf.h:58
void * get() const
Definition: buf.h:48
Hold configuration parameters.
Definition: cfg.h:89
const std::string & uds_address(const std::string §ion="") const
Network interface information.
Definition: ptp.h:44
Base for socket that uses network interface directly.
Definition: sock.h:445
bool setIfUsingIndex(int ifIndex)
bool setIf(const IfInfo &ifObj)
bool setIfUsingName(const std::string &ifName)
bool setAllInit(const IfInfo &ifObj, const ConfigFile &cfg, const std::string §ion="")
Definition: sock.h:513
bool setAll(const IfInfo &ifObj, const ConfigFile &cfg, const std::string §ion="")
Definition: sock.h:497
Base class for all sockets.
Definition: sock.h:44
int fileno() const
Definition: sock.h:148
ssize_t rcvBuf(Buf &buf, bool block=false)
Definition: sock.h:131
bool init()
Definition: sock.h:69
bool send(const void *msg, size_t len)
Definition: sock.h:78
int getFd() const
Definition: sock.h:140
bool send(Buf &buf, size_t len)
Definition: sock.h:88
bool tpoll(uint64_t &timeout_ms) const
bool sendBuf(Buf &buf, size_t len)
Definition: sock.h:99
ssize_t rcv(void *buf, size_t bufSize, bool block=false)
Definition: sock.h:110
ssize_t rcv(Buf &buf, bool block=false)
Definition: sock.h:120
bool poll(uint64_t timeout_ms=0) const
void close()
Definition: sock.h:64
UDP over IP version 4 socket.
Definition: sock.h:571
UDP over IP version 6 socket.
Definition: sock.h:590
bool setScope(const ConfigFile &cfg, const std::string §ion="")
bool setScope(uint8_t udp6_scope)
Base for UDP sockets.
Definition: sock.h:526
bool setUdpTtl(const ConfigFile &cfg, const std::string §ion="")
bool setUdpTtl(uint8_t udp_ttl)
Raw socket that uses PTP over Ethernet.
Definition: sock.h:632
bool setPtpDstMac(const void *ptp_dst_mac, size_t len)
bool setPtpDstMac(const ConfigFile &cfg, const std::string §ion="")
bool setPtpDstMac(const uint8_t *ptp_dst_mac, size_t len)
bool setSocketPriority(const ConfigFile &cfg, const std::string §ion="")
bool setPtpDstMacStr(const std::string &string)
bool setPtpDstMac(const Binary &ptp_dst_mac)
bool setSocketPriority(uint8_t socket_priority)
Unix socket.
Definition: sock.h:197
ssize_t rcvFrom(void *buf, size_t bufSize, std::string &from, bool block=false) const
const char * getSelfAddress_c() const
Definition: sock.h:259
bool setPeerAddress(const ConfigFile &cfg, const std::string §ion="")
Definition: sock.h:247
bool sendTo(const void *msg, size_t len, const std::string &addrStr) const
bool sendTo(Buf &buf, size_t len, const std::string &addrStr, bool useAbstract=false) const
Definition: sock.h:345
SockUnix()
Definition: sock.h:213
bool setSelfAddress(const std::string &string)
ssize_t rcvFrom(Buf &buf, bool block=false)
Definition: sock.h:394
static bool isAddressAbstract(const std::string &addr)
Definition: sock.h:434
bool setDefSelfAddress(const std::string &rootBase="", const std::string &useDef="")
ssize_t rcvBufFrom(Buf &buf, bool block=false)
Definition: sock.h:406
bool sendTo(const void *msg, size_t len, const std::string &addrStr, bool useAbstract) const
bool isPeerAddressAbstract() const
Definition: sock.h:228
ssize_t rcvFrom(void *buf, size_t bufSize, bool block=false)
Definition: sock.h:383
bool setSelfAddress(const std::string &string, bool useAbstract)
bool isSelfAddressAbstract() const
Definition: sock.h:264
const char * getPeerAddress_c() const
Definition: sock.h:223
const std::string & getHomeDir()
const std::string & getSelfAddress() const
Definition: sock.h:254
const std::string & getPeerAddress() const
Definition: sock.h:218
bool isLastFromAbstract() const
Definition: sock.h:428
ssize_t rcvFrom(Buf &buf, std::string &from, bool block=false) const
Definition: sock.h:371
const char * getHomeDir_c()
bool setPeerAddress(const std::string &string, bool useAbstract=false)
Definition: sock.h:237
const char * getLastFrom_c() const
Definition: sock.h:423
const std::string & getLastFrom() const
Definition: sock.h:415