inet_pton.c

ソースコードを見る。


関数

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

関数

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

参照元 inet_pton()inet_pton6().

static int inet_pton6 ( const char *  src,
unsigned char *  dst 
) [static]

参照元 inet_pton().

int inet_pton ( int  af,
const char *  src,
void *  dst 
)

inet_pton.c46 行で定義されています。

参照先 errnoinet_pton4()inet_pton6().

参照元 getaddrinfo()match_address().

00049 {
00050         switch (af) {
00051         case AF_INET:
00052                 return (inet_pton4(src, dst));
00053 #ifdef INET6
00054         case AF_INET6:
00055                 return (inet_pton6(src, dst));
00056 #endif
00057         default:
00058                 errno = EAFNOSUPPORT;
00059                 return (-1);
00060         }
00061         /* NOTREACHED */
00062 }

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

inet_pton.c75 行で定義されています。

00078 {
00079         static const char digits[] = "0123456789";
00080         int saw_digit, octets, ch;
00081         unsigned char tmp[NS_INADDRSZ], *tp;
00082 
00083         saw_digit = 0;
00084         octets = 0;
00085         *(tp = tmp) = 0;
00086         while ((ch = *src++) != '\0') {
00087                 const char *pch;
00088 
00089                 if ((pch = strchr(digits, ch)) != NULL) {
00090                         unsigned int new = *tp * 10 + (pch - digits);
00091 
00092                         if (new > 255)
00093                                 return (0);
00094                         *tp = new;
00095                         if (! saw_digit) {
00096                                 if (++octets > 4)
00097                                         return (0);
00098                                 saw_digit = 1;
00099                         }
00100                 } else if (ch == '.' && saw_digit) {
00101                         if (octets == 4)
00102                                 return (0);
00103                         *++tp = 0;
00104                         saw_digit = 0;
00105                 } else
00106                         return (0);
00107         }
00108         if (octets < 4)
00109                 return (0);
00110         memcpy(dst, tmp, NS_INADDRSZ);
00111         return (1);
00112 }

static int inet_pton6 ( char *  src,
unsigned char *  dst 
) const [static]

inet_pton.c129 行で定義されています。

参照先 inet_pton4().

00132 {
00133         static const char xdigits_l[] = "0123456789abcdef",
00134                           xdigits_u[] = "0123456789ABCDEF";
00135         unsigned char tmp[NS_IN6ADDRSZ], *tp, *endp, *colonp;
00136         const char *xdigits, *curtok;
00137         int ch, saw_xdigit;
00138         unsigned int val;
00139 
00140         memset((tp = tmp), '\0', NS_IN6ADDRSZ);
00141         endp = tp + NS_IN6ADDRSZ;
00142         colonp = NULL;
00143         /* Leading :: requires some special handling. */
00144         if (*src == ':')
00145                 if (*++src != ':')
00146                         return (0);
00147         curtok = src;
00148         saw_xdigit = 0;
00149         val = 0;
00150         while ((ch = *src++) != '\0') {
00151                 const char *pch;
00152 
00153                 if ((pch = strchr((xdigits = xdigits_l), ch)) == NULL)
00154                         pch = strchr((xdigits = xdigits_u), ch);
00155                 if (pch != NULL) {
00156                         val <<= 4;
00157                         val |= (pch - xdigits);
00158                         if (val > 0xffff)
00159                                 return (0);
00160                         saw_xdigit = 1;
00161                         continue;
00162                 }
00163                 if (ch == ':') {
00164                         curtok = src;
00165                         if (!saw_xdigit) {
00166                                 if (colonp)
00167                                         return (0);
00168                                 colonp = tp;
00169                                 continue;
00170                         }
00171                         if (tp + NS_INT16SZ > endp)
00172                                 return (0);
00173                         *tp++ = (unsigned char) (val >> 8) & 0xff;
00174                         *tp++ = (unsigned char) val & 0xff;
00175                         saw_xdigit = 0;
00176                         val = 0;
00177                         continue;
00178                 }
00179                 if (ch == '.' && ((tp + NS_INADDRSZ) <= endp) &&
00180                     inet_pton4(curtok, tp) > 0) {
00181                         tp += NS_INADDRSZ;
00182                         saw_xdigit = 0;
00183                         break;  /* '\0' was seen by inet_pton4(). */
00184                 }
00185                 return (0);
00186         }
00187         if (saw_xdigit) {
00188                 if (tp + NS_INT16SZ > endp)
00189                         return (0);
00190                 *tp++ = (unsigned char) (val >> 8) & 0xff;
00191                 *tp++ = (unsigned char) val & 0xff;
00192         }
00193         if (colonp != NULL) {
00194                 /*
00195                  * Since some memmove()'s erroneously fail to handle
00196                  * overlapping regions, we'll do the shift by hand.
00197                  */
00198                 const int n = tp - colonp;
00199                 int i;
00200 
00201                 for (i = 1; i <= n; i++) {
00202                         endp[- i] = colonp[n - i];
00203                         colonp[n - i] = 0;
00204                 }
00205                 tp = endp;
00206         }
00207         if (tp != endp)
00208                 return (0);
00209         memcpy(dst, tmp, NS_IN6ADDRSZ);
00210         return (1);
00211 }


rsyncに対してSat Dec 5 19:45:44 2009に生成されました。  doxygen 1.4.7