mirror of
https://github.com/ceph/ceph
synced 2024-12-24 04:14:07 +00:00
18268f7793
git-svn-id: https://ceph.svn.sf.net/svnroot/ceph@1084 29311d96-e01e-0410-9327-a35deaab8ce9
38 lines
940 B
C++
38 lines
940 B
C++
#ifndef __TCP_H
|
|
#define __TCP_H
|
|
|
|
#include <sys/socket.h>
|
|
#include <netinet/in.h>
|
|
#include <arpa/inet.h>
|
|
#include <string.h>
|
|
|
|
typedef struct sockaddr_in tcpaddr_t;
|
|
|
|
using std::ostream;
|
|
|
|
inline ostream& operator<<(ostream& out, const tcpaddr_t &a)
|
|
{
|
|
unsigned char addr[4];
|
|
memcpy((char*)addr, (char*)&a.sin_addr.s_addr, 4);
|
|
out << (unsigned)addr[0] << "."
|
|
<< (unsigned)addr[1] << "."
|
|
<< (unsigned)addr[2] << "."
|
|
<< (unsigned)addr[3] << ":"
|
|
<< ntohs(a.sin_port);
|
|
return out;
|
|
}
|
|
|
|
extern bool tcp_read(int sd, char *buf, int len);
|
|
extern int tcp_write(int sd, char *buf, int len);
|
|
extern int tcp_hostlookup(char *str, tcpaddr_t& ta);
|
|
|
|
inline bool operator==(const tcpaddr_t& a, const tcpaddr_t& b) {
|
|
return strncmp((const char*)&a, (const char*)&b, sizeof(a)) == 0;
|
|
}
|
|
inline bool operator!=(const tcpaddr_t& a, const tcpaddr_t& b) {
|
|
return strncmp((const char*)&a, (const char*)&b, sizeof(a)) != 0;
|
|
}
|
|
|
|
|
|
#endif
|