tcpflow  1.6.1
About: tcpflow is a TCP/IP packet demultiplexer that captures data transmitted as part of TCP connections (flows), and stores the data in a way that is convenient for protocol analysis and debugging.
  Fossies Dox: tcpflow-1.6.1.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

inet_ntop.c
Go to the documentation of this file.
1 /**
2  * private implementaiton if inet_ntop for systems that don't have it.
3  * Functionally, correct, this version doesn't do condensing of IPv6 addresses,
4  * and is kind of slow.
5  *
6  * This is included if the OS does not have inet_ntop.
7  *
8  * PUBLIC DOMAIN.
9  * Simson L. Garfinkel, Jan 20, 2013
10  */
11 
12 static const char *inet_ntop4(const struct in_addr *addr, char *buf, socklen_t buflen)
13 {
14  const uint8_t *a = (uint8_t *)addr;
15  snprintf(buf,buflen,"%03d.%03d.%03d.%03d", a[0], a[1], a[2], a[3]);
16  return buf;
17 }
18 
19 static const char *inet_ntop6(const struct private_in6_addr *addr, char *buf, socklen_t buflen)
20 {
21  const char *obuf=buf;
22  const uint8_t *a = (uint8_t *)addr;
23  for(size_t i=0;i<16;i++){
24  if(buflen<2) return 0; /* can't convert */
25  snprintf(buf,buflen,"%02x",a[i]);
26  buf+=2;
27  buflen-=2;
28  if(i>0 && i<15 && i%2==1){
29  if(buflen<1) return 0;
30  buf[0] = ':';
31  buf++;
32  buflen--;
33  }
34  }
35  if(buflen<1) return 0;
36  buf[0] = 0;
37  return obuf;
38 }
39 
40 const char *
41 inet_ntop(int af, const void *addr, char *buf, socklen_t len)
42 {
43  switch(af){
44  case AF_INET:
45  return inet_ntop4((const struct in_addr *)addr, buf, len);
46  case AF_INET6:
47  return inet_ntop6((const struct private_in6_addr *)addr, buf, len);
48  }
49  return NULL;
50 }
static const char * inet_ntop6(const struct private_in6_addr *addr, char *buf, socklen_t buflen)
Definition: inet_ntop.c:19
static const char * inet_ntop4(const struct in_addr *addr, char *buf, socklen_t buflen)
Definition: inet_ntop.c:12
const char * inet_ntop(int af, const void *addr, char *buf, socklen_t len)
Definition: inet_ntop.c:41
size_t socklen_t
Definition: tcpflow.h:216
unsigned char uint8_t
Definition: util.h:6