Import 2.3.10pre5
[davej-history.git] / net / ipv4 / utils.c
blob5992cbc5543e1aa350241387b4306ba45610fc2c
1 /*
2 * INET An implementation of the TCP/IP protocol suite for the LINUX
3 * operating system. INET is implemented using the BSD Socket
4 * interface as the means of communication with the user level.
6 * Various kernel-resident INET utility functions; mainly
7 * for format conversion and debugging output.
9 * Version: $Id: utils.c,v 1.7 1999/06/09 10:11:05 davem Exp $
11 * Author: Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
13 * Fixes:
14 * Alan Cox : verify_area check.
15 * Alan Cox : removed old debugging.
16 * Andi Kleen : add net_ratelimit()
18 * This program is free software; you can redistribute it and/or
19 * modify it under the terms of the GNU General Public License
20 * as published by the Free Software Foundation; either version
21 * 2 of the License, or (at your option) any later version.
24 #include <asm/uaccess.h>
25 #include <asm/system.h>
26 #include <linux/types.h>
27 #include <linux/kernel.h>
28 #include <linux/sched.h>
29 #include <linux/string.h>
30 #include <linux/mm.h>
31 #include <linux/socket.h>
32 #include <linux/in.h>
33 #include <linux/errno.h>
34 #include <linux/stat.h>
35 #include <stdarg.h>
36 #include <linux/inet.h>
37 #include <linux/netdevice.h>
38 #include <linux/etherdevice.h>
39 #include <net/ip.h>
40 #include <net/protocol.h>
41 #include <net/tcp.h>
42 #include <linux/skbuff.h>
46 * Display an IP address in readable format.
49 char *in_ntoa(__u32 in)
51 static char buff[18];
52 char *p;
54 p = (char *) &in;
55 sprintf(buff, "%d.%d.%d.%d",
56 (p[0] & 255), (p[1] & 255), (p[2] & 255), (p[3] & 255));
57 return(buff);
60 char *in_ntoa2(__u32 in, char *buff)
62 sprintf(buff, "%d.%d.%d.%d", NIPQUAD(in));
63 return buff;
67 * Convert an ASCII string to binary IP.
70 __u32 in_aton(const char *str)
72 unsigned long l;
73 unsigned int val;
74 int i;
76 l = 0;
77 for (i = 0; i < 4; i++)
79 l <<= 8;
80 if (*str != '\0')
82 val = 0;
83 while (*str != '\0' && *str != '.')
85 val *= 10;
86 val += *str - '0';
87 str++;
89 l |= val;
90 if (*str != '\0')
91 str++;
94 return(htonl(l));