📄 utils.c
字号:
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.
5 *
6 * Various kernel-resident INET utility functions; mainly
7 * for format conversion and debugging output.
8 *
9 * Version: @(#)utils.c 1.0.7 05/18/93
10 *
11 * Author: Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
12 *
13 * Fixes:
14 * Alan Cox : verify_area check.
15 *
16 *
17 * This program is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU General Public License
19 * as published by the Free Software Foundation; either version
20 * 2 of the License, or (at your option) any later version.
21 */
22 #include <asm/segment.h>
23 #include <asm/system.h>
24 #include <linux/types.h>
25 #include <linux/kernel.h>
26 #include <linux/sched.h>
27 #include <linux/string.h>
28 #include <linux/mm.h>
29 #include <linux/socket.h>
30 #include <linux/in.h>
31 #include <linux/errno.h>
32 #include <linux/stat.h>
33 #include <stdarg.h>
34 #include "inet.h"
35 #include "dev.h"
36 #include "eth.h"
37 #include "ip.h"
38 #include "protocol.h"
39 #include "tcp.h"
40 #include "skbuff.h"
41 #include "arp.h"
42
43
44 /* Display an IP address in readable format. */
45 char *in_ntoa(unsigned long in)
46 {
47 static char buff[18];
48 register char *p;
49
50 p = (char *) ∈
51 sprintf(buff, "%d.%d.%d.%d",
52 (p[0] & 255), (p[1] & 255), (p[2] & 255), (p[3] & 255));
53 return(buff);
54 }
55
56
57 /* Convert an ASCII string to binary IP. */
58 unsigned long
59 in_aton(char *str)
60 {
61 unsigned long l;
62 unsigned int val;
63 int i;
64
65 l = 0;
66 for (i = 0; i < 4; i++) {
67 l <<= 8;
68 if (*str != '\0') {
69 val = 0;
70 while (*str != '\0' && *str != '.') {
71 val *= 10;
72 val += *str - '';
73 str++;
74 }
75 l |= val;
76 if (*str != '\0') str++;
77 }
78 }
79 return(htonl(l));
80 }
81
82
83 void
84 dprintf(int level, char *fmt, ...)
85 {
86 va_list args;
87 char *buff;
88 extern int vsprintf(char * buf, const char * fmt, va_list args);
89
90 if (level != inet_debug) return;
91
92 buff = (char *) kmalloc(256, GFP_ATOMIC);
93 if (buff != NULL) {
94 va_start(args, fmt);
95 vsprintf(buff, fmt, args);
96 va_end(args);
97 printk(buff);
98 kfree(buff);
99 }
100 }
101
102
103 int
104 dbg_ioctl(void *arg, int level)
105 {
106 int val;
107 int err;
108
109 if (!suser()) return(-EPERM);
110 err=verify_area(VERIFY_READ, (void *)arg, sizeof(int));
111 if(err)
112 return err;
113 val = get_fs_long((int *)arg);
114 switch(val) {
115 case 0: /* OFF */
116 inet_debug = DBG_OFF;
117 break;
118 case 1: /* ON, INET */
119 inet_debug = level;
120 break;
121
122 case DBG_RT: /* modules */
123 case DBG_DEV:
124 case DBG_ETH:
125 case DBG_PROTO:
126 case DBG_TMR:
127 case DBG_PKT:
128 case DBG_RAW:
129
130 case DBG_LOOPB: /* drivers */
131 case DBG_SLIP:
132
133 case DBG_ARP: /* protocols */
134 case DBG_IP:
135 case DBG_ICMP:
136 case DBG_TCP:
137 case DBG_UDP:
138
139 inet_debug = val;
140 break;
141
142 default:
143 return(-EINVAL);
144 }
145
146 return(0);
147 }
148
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -