~clint-fewbar/+junk/ceph-packaging

« back to all changes in this revision

Viewing changes to src/msg/tcp.h

  • Committer: Clint Byrum
  • Date: 2010-07-21 04:26:29 UTC
  • Revision ID: clint@ubuntu.com-20100721042629-srvi3wzjib97px3o
importingĀ upstreamĀ v0.20.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- 
 
2
// vim: ts=8 sw=2 smarttab
 
3
#ifndef __TCP_H
 
4
#define __TCP_H
 
5
 
 
6
#include <sys/socket.h>
 
7
#include <netinet/in.h>
 
8
#include <arpa/inet.h>
 
9
#include <string.h>
 
10
#include <sys/socket.h>
 
11
#include <netdb.h>
 
12
 
 
13
using std::ostream;
 
14
 
 
15
inline ostream& operator<<(ostream& out, const sockaddr_storage &ss)
 
16
{
 
17
  char buf[NI_MAXHOST] = { 0 };
 
18
  char serv[20] = { 0 };
 
19
  getnameinfo((struct sockaddr *)&ss, sizeof(ss), buf, sizeof(buf),
 
20
              serv, sizeof(serv),
 
21
              NI_NUMERICHOST | NI_NUMERICSERV);
 
22
  return out //<< ss.ss_family << ":"
 
23
             << buf << ':' << serv;
 
24
}
 
25
 
 
26
inline ostream& operator<<(ostream& out, const sockaddr_in &ss)
 
27
{
 
28
  char buf[NI_MAXHOST] = { 0 };
 
29
  char serv[20] = { 0 };
 
30
  getnameinfo((struct sockaddr *)&ss, sizeof(ss), buf, sizeof(buf),
 
31
              serv, sizeof(serv),
 
32
              NI_NUMERICHOST | NI_NUMERICSERV);
 
33
  return out //<< ss.sin_family << ":"
 
34
             << buf << ':' << serv;
 
35
}
 
36
 
 
37
 
 
38
extern int tcp_read(int sd, char *buf, int len);
 
39
extern int tcp_write(int sd, const char *buf, int len);
 
40
 
 
41
 
 
42
extern int tcp_hostlookup(char *str, sockaddr_in& ta);
 
43
 
 
44
inline bool operator==(const sockaddr_in& a, const sockaddr_in& b) {
 
45
  return strncmp((const char*)&a, (const char*)&b, sizeof(a)) == 0;
 
46
}
 
47
inline bool operator!=(const sockaddr_in& a, const sockaddr_in& b) {
 
48
  return strncmp((const char*)&a, (const char*)&b, sizeof(a)) != 0;
 
49
}
 
50
 
 
51
 
 
52
#endif