#include <string.h>#include <errno.h>#include <switch.h>Include dependency graph for inet_pton.c:
Go to the source code of this file.
Defines | |
| #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) |
| #define IN6ADDRSZ 16 |
Definition at line 39 of file inet_pton.c.
| #define INADDRSZ 4 |
| #define INT16SZ 2 |
Definition at line 41 of file inet_pton.c.
| static int inet_pton4 | ( | const char * | src, | |
| unsigned char * | dst | |||
| ) | [static] |
Definition at line 102 of file inet_pton.c.
References INADDRSZ.
Referenced by switch_inet_pton().
00103 { 00104 static const char digits[] = "0123456789"; 00105 int saw_digit, octets, ch; 00106 unsigned char tmp[INADDRSZ], *tp; 00107 00108 saw_digit = 0; 00109 octets = 0; 00110 tp = tmp; 00111 *tp = 0; 00112 while ((ch = *src++) != '\0') { 00113 const char *pch; 00114 00115 if ((pch = strchr(digits, ch)) != NULL) { 00116 unsigned int val = *tp * 10 + (unsigned int) (pch - digits); 00117 00118 if (val > 255) 00119 return (0); 00120 *tp = (unsigned char) val; 00121 if (!saw_digit) { 00122 if (++octets > 4) 00123 return (0); 00124 saw_digit = 1; 00125 } 00126 } else if (ch == '.' && saw_digit) { 00127 if (octets == 4) 00128 return (0); 00129 *++tp = 0; 00130 saw_digit = 0; 00131 } else 00132 return (0); 00133 } 00134 if (octets < 4) 00135 return (0); 00136 /* bcopy(tmp, dst, INADDRSZ); */ 00137 memcpy(dst, tmp, INADDRSZ); 00138 return (1); 00139 }
| int switch_inet_pton | ( | int | af, | |
| const char * | src, | |||
| void * | dst | |||
| ) |
Definition at line 73 of file inet_pton.c.
References inet_pton4().
00074 { 00075 switch (af) { 00076 case AF_INET: 00077 return (inet_pton4(src, (unsigned char *) dst)); 00078 #ifdef ENABLE_IPV6 00079 #ifndef AF_INET6 00080 #define AF_INET6 (AF_MAX+1) /* just to let this compile */ 00081 #endif 00082 case AF_INET6: 00083 return (inet_pton6(src, (unsigned char *) dst)); 00084 #endif 00085 default: 00086 errno = EAFNOSUPPORT; 00087 return (-1); 00088 } 00089 /* NOTREACHED */ 00090 }
1.4.7