iputils.c

来自「这是一个开放源代码的与WINNT/WIN2K/WIN2003兼容的操作系统」· C语言 代码 · 共 60 行

C
60
字号
#include <headers.h>
#include <datatypes.h>
#include <options.h>
#include <utils.h>

int split_ip( char *text, u8b *dest, int place )
{
  int dotcount;

  /* Don't touch this, unless you like pointer aritmethic */

  *dest = 0;

  if( !text )
    return -1;

  for( dotcount = 0; (dotcount < place) && ( text ); text++ )
      if( *text == '.' )
	dotcount++;

  if( !text )
    return -2;

  while(( *text != '.' ) && ( *text != '\0' ))
    {
      *dest *= 10;
      *dest += (u8b)(*text-48);
      /* 48 is not a hack, is just the code of 0 */
      text++;
    }

  return 0;
}

int get_ip( char *text, u32b *dest )
{
  /* Don't touch this, unless you like pointer aritmethic */

  *dest = 0;

  if( !text )
    return -1;

  while( *text != '\0' )
    {
      if( *text == '.' )
	{
	  *dest = *dest << 8;
	  text++;
	  continue;
	}
      *dest *= 10;
      *dest += (u8b)(*text-48);
      /* 48 is not a hack, is just the code of 0 */
      text++;
    }

  return 0;
}

⌨️ 快捷键说明

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