Source code of all these network functions is available from a number of
sites on the internet and there is  nothing magic about it. I am
copying BSD source code for inet_aton(). You can look for other
functions at the following web site:
http://www.ajk.tele.fi/libc/code.html


/*  */
/* inet_aton */
int
inet_aton(cp, addr)
 register const char *cp;
 struct in_addr *addr;
{
 register u_long val;
 register int base, n;
 register char c;
 u_int parts[4];
 register u_int *pp = parts;

 c = *cp;
 for (;;) {
  /*
   * Collect number up to ``.''.
   * Values are specified as for C:
   * 0x=hex, 0=octal, isdigit=decimal.
   */
  if (!isdigit(c))
   return (0);
  val = 0; base = 10;
  if (c == '0') {
   c = *++cp;
   if (c == 'x' || c == 'X')
    base = 16, c = *++cp;
   else
    base = 8;
  }
  for (;;) {
   if (isascii(c) && isdigit(c)) {
    val = (val * base) + (c - '0');
    c = *++cp;
   } else if (base == 16 && isascii(c) && isxdigit(c)) {
    val = (val << 4) |
     (c + 10 - (islower(c) ? 'a' : 'A'));
    c = *++cp;
   } else
   break;
  }
  if (c == '.') {
   /*
    * Internet format:
    * a.b.c.d
    * a.b.c (with c treated as 16 bits)
    * a.b (with b treated as 24 bits)
    */
   if (pp >= parts + 3)
    return (0);
   *pp++ = val;
   c = *++cp;
  } else
   break;
 }
 /*
  * Check for trailing characters.
  */
 if (c != '\0' && (!isascii(c) || !isspace(c)))
  return (0);
 /*
  * Concoct the address according to
  * the number of parts specified.
  */
 n = pp - parts + 1;
 switch (n) {

 case 0:
  return (0);  /* initial nondigit */

 case 1:    /* a -- 32 bits */
  break;

 case 2:    /* a.b -- 8.24 bits */
  if (val > 0xffffff)
   return (0);
  val |= parts[0] << 24;
  break;

 case 3:    /* a.b.c -- 8.8.16 bits */
  if (val > 0xffff)
   return (0);
  val |= (parts[0] << 24) | (parts[1] << 16);
  break;

 case 4:    /* a.b.c.d -- 8.8.8.8 bits */
  if (val > 0xff)
   return (0);
  val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8);
  break;
 }
 if (addr)
  addr->s_addr = htonl(val);
 return (1);
}

------------------------------------------------------------------
Rafeeq Ur Rehman

http://vig.prenhall.com/academic/product/1,3411,0130183741,00.html
------------------------------------------------------------------
----- Original Message ----- 
From: Randolph Lee 
To: [EMAIL PROTECTED] 
Sent: Monday, December 04, 2000 12:05 AM
Subject: [rtl] rtnet


Hello,

Currently I'm working on a project using RT Linux for networking. I'm using
Rtnet V0.9.0. I was wondering if there is an RT function that is similar to
inet_addr or inet_aton (in arpa/inet.h).

Thanks,
Randolph
-- [rtl] ---
To unsubscribe:
echo "unsubscribe rtl" | mail [EMAIL PROTECTED] OR
echo "unsubscribe rtl <Your_email>" | mail [EMAIL PROTECTED]
---
For more information on Real-Time Linux see:
http://www.rtlinux.org/rtlinux/


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com

-- [rtl] ---
To unsubscribe:
echo "unsubscribe rtl" | mail [EMAIL PROTECTED] OR
echo "unsubscribe rtl <Your_email>" | mail [EMAIL PROTECTED]
---
For more information on Real-Time Linux see:
http://www.rtlinux.org/rtlinux/

Reply via email to