FreeSWITCH API Documentation  1.7.0
Macros | Functions
inet_pton.c File Reference
#include <string.h>
#include <errno.h>
#include <switch.h>
+ Include dependency graph for inet_pton.c:

Go to the source code of this file.

Macros

#define IN6ADDRSZ   16
 
#define INADDRSZ   4
 
#define INT16SZ   2
 

Functions

static int inet_pton4 (const char *src, unsigned char *dst)
 
int switch_inet_pton (int af, const char *src, void *dst)
 

Macro Definition Documentation

#define IN6ADDRSZ   16

Definition at line 39 of file inet_pton.c.

#define INADDRSZ   4

Definition at line 40 of file inet_pton.c.

Referenced by inet_pton4().

#define INT16SZ   2

Definition at line 41 of file inet_pton.c.

Function Documentation

static int inet_pton4 ( const char *  src,
unsigned char *  dst 
)
static

Definition at line 103 of file inet_pton.c.

References INADDRSZ.

Referenced by switch_inet_pton().

104 {
105  static const char digits[] = "0123456789";
106  int saw_digit, octets, ch;
107  unsigned char tmp[INADDRSZ], *tp;
108 
109  saw_digit = 0;
110  octets = 0;
111  tp = tmp;
112  *tp = 0;
113  while ((ch = *src++) != '\0') {
114  const char *pch;
115 
116  if ((pch = strchr(digits, ch)) != NULL) {
117  unsigned int val = *tp * 10 + (unsigned int) (pch - digits);
118 
119  if (val > 255)
120  return (0);
121  *tp = (unsigned char) val;
122  if (!saw_digit) {
123  if (++octets > 4)
124  return (0);
125  saw_digit = 1;
126  }
127  } else if (ch == '.' && saw_digit) {
128  if (octets == 4)
129  return (0);
130  *++tp = 0;
131  saw_digit = 0;
132  } else
133  return (0);
134  }
135  if (octets < 4)
136  return (0);
137  /* bcopy(tmp, dst, INADDRSZ); */
138  memcpy(dst, tmp, INADDRSZ);
139  return (1);
140 }
#define INADDRSZ
Definition: inet_pton.c:40
int switch_inet_pton ( int  af,
const char *  src,
void *  dst 
)

Definition at line 74 of file inet_pton.c.

References inet_pton4().

75 {
76  switch (af) {
77  case AF_INET:
78  return (inet_pton4(src, (unsigned char *) dst));
79 #ifdef ENABLE_IPV6
80 #ifndef AF_INET6
81 #define AF_INET6 (AF_MAX+1) /* just to let this compile */
82 #endif
83  case AF_INET6:
84  return (inet_pton6(src, (unsigned char *) dst));
85 #endif
86  default:
87  errno = EAFNOSUPPORT;
88  return (-1);
89  }
90  /* NOTREACHED */
91 }
static int inet_pton4(const char *src, unsigned char *dst)
Definition: inet_pton.c:103