XINU
Functions
dot2ip.c File Reference
#include <xinu.h>
Include dependency graph for dot2ip.c:

Go to the source code of this file.

Functions

uint32 dot2ip (char *dotted, uint32 *result)
 

Function Documentation

◆ dot2ip()

uint32 dot2ip ( char *  dotted,
uint32 result 
)

Definition at line 9 of file dot2ip.c.

References NULLCH, OK, and SYSERR.

Referenced by getlocalip(), getutime(), rdsinit(), rfsinit(), xsh_ping(), and xsh_udpecho().

15 {
16  int32 seg; /* Counts segments */
17  int32 nch; /* Counts chars within segment */
18  char ch; /* Next character */
19  uint32 ipaddr; /* IP address in binary */
20  int32 val; /* Binary value of one segment */
21 
22  /* Input must have the form X.X.X.X, where X is 1 to 3 digits */
23 
24  ipaddr = 0;
25  for (seg=0 ; seg<4 ; seg++) { /* For each segment */
26  val = 0;
27  for (nch=0 ; nch<4; nch++) { /* Up to four chars per segment*/
28  ch = *dotted++;
29  if ( (ch==NULLCH) || (ch == '.') ) {
30  if (nch == 0) {
31  return SYSERR;
32  } else {
33  break;
34  }
35  }
36 
37  /* Non-digit is an error */
38 
39  if ( (ch<'0') || (ch>'9') ) {
40  return SYSERR;
41  }
42 
43  val = 10*val + (ch-'0');
44  }
45 
46  if (val > 255) { /* Out of valid range */
47  return SYSERR;
48  }
49  ipaddr = (ipaddr << 8) | val;
50 
51  if (ch == NULLCH) {
52  break;
53  }
54  }
55  if ( (seg != 3) || (ch != NULLCH) ) {
56  return SYSERR;
57  }
58  *result = ipaddr;
59  return OK;
60 }
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
#define OK
処理が成功した場合
Definition: kernel.h:77
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
unsigned int uint32
符号なし32ビット整数(unsigned int)
Definition: kernel.h:15
#define NULLCH
NULL文字(NULL終端)
Definition: kernel.h:70
Here is the caller graph for this function: