⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 inetaddr.c

📁 用于嵌入式系统的TCP/IP协议栈
💻 C
字号:
/***********************************************************************//*                                                                     *//*   Module:  inetaddr.c                                               *//*   Release: 2001.3                                                   *//*   Version: 99.0                                                     *//*   Purpose: inet_addr() implementation                               *//*                                                                     *//*---------------------------------------------------------------------*//*                                                                     *//*               Copyright 1999, Blunk Microsystems                    *//*                      ALL RIGHTS RESERVED                            *//*                                                                     *//*   Licensees have the non-exclusive right to use, modify, or extract *//*   this computer program for software development at a single site.  *//*   This program may be resold or disseminated in executable format   *//*   only. The source code may not be redistributed or resold.         *//*                                                                     *//***********************************************************************/#include "../tcp_ipp.h"#include <ctype.h>/***********************************************************************//* Global Function Definitions                                         *//***********************************************************************//***********************************************************************//*   inet_addr: Convert dotted-decimal address to integer              *//*                                                                     *//*       Input: ptr = pointer to dotted decimal IP address string      *//*                                                                     *//*     Returns: integer IP address                                     *//*                                                                     *//*        Note: Address is returned in network byte order              *//*                                                                     *//***********************************************************************/ui32 inet_addr(const char *ptr){  int i, n;  ui32 lword = 0;  /*-------------------------------------------------------------------*/  /* Loop once for each byte converted.                                */  /*-------------------------------------------------------------------*/  for (n = 4;; lword <<= 8)  {    /*-----------------------------------------------------------------*/    /* Convert one byte's worth and write OR to 32-bit word.           */    /*-----------------------------------------------------------------*/    for (i = 0; isdigit(*ptr); ++ptr)      i = (10 * i) + (*ptr - '0');    lword |= (i & 0xFF);    /*-----------------------------------------------------------------*/    /* If finished, return long word IP address.                       */    /*-----------------------------------------------------------------*/    if (--n == 0)      return htonl(lword);    /*-----------------------------------------------------------------*/    /* Check for '.' between each decimal number.                      */    /*-----------------------------------------------------------------*/    if (*ptr++ != '.')    {      NetError(NULL, EFAULT);      return (ui32)-1;    }  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -