OpenCores
URL https://opencores.org/ocsvn/or1k_old/or1k_old/trunk

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [uclinux/] [uC-libc/] [net/] [addr.c] - Blame information for rev 1782

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 199 simons
/* Copyright (C) 1995,1996 Robert de Bath <rdebath@cix.compulink.co.uk>
2
 * This file is part of the Linux-8086 C library and is distributed
3
 * under the GNU Library General Public License.
4
 */
5
 
6
#include <string.h>
7
#include <ctype.h>
8
#include <netinet/in.h>
9
 
10
 
11
#ifdef L_inet_aton
12
int
13
inet_aton(cp, inp)
14
const char *cp;
15
struct in_addr *inp;
16
{
17
  unsigned long addr;
18
  int value;
19
  int part;
20
 
21
  if (!inp)
22
    return 0;
23
 
24
  addr = 0;
25
  for (part=1;part<=4;part++) {
26
 
27
    if (!isdigit(*cp))
28
      return 0;
29
 
30
    value = 0;
31
    while (isdigit(*cp)) {
32
      value *= 10;
33
      value += *cp++ - '0';
34
      if (value > 255)
35
        return 0;
36
    }
37
 
38
    if (*cp++ != ((part == 4) ? '\0' : '.'))
39
      return 0;
40
 
41
    addr <<= 8;
42
    addr |= value;
43
  }
44
 
45
  inp->s_addr = htonl(addr);
46
 
47
  return 1;
48
}
49
#endif
50
 
51
#ifdef L_inet_addr
52
unsigned long
53
inet_addr(cp)
54
const char *cp;
55
{
56
  struct in_addr a;
57
  if (!inet_aton(cp, &a))
58
    return -1;
59
  else
60
    return a.s_addr;
61
}
62
#endif
63
 
64
#ifdef L_inet_ntoa
65
 
66
extern char * itoa(int);
67
 
68
char *
69
inet_ntoa(in)
70
struct in_addr in;
71
{
72
  static char buf[18];
73
  unsigned long addr = ntohl(in.s_addr);
74
 
75
  strcpy(buf, itoa((addr >> 24) & 0xff));
76
  strcat(buf, ".");
77
  strcat(buf, itoa((addr >> 16) & 0xff));
78
  strcat(buf, ".");
79
  strcat(buf, itoa((addr >> 8) & 0xff));
80
  strcat(buf, ".");
81
  strcat(buf, itoa(addr & 0xff));
82
 
83
  return buf;
84
}
85
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.