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 * This file implements the various access functions for the 7 * PROC file system. It is mainly used for debugging and 8 * statistics. 9 * 10 * Version: @(#)proc.c 1.0.5 05/27/93 11 * 12 * Authors: Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG> 13 * Gerald J. Heim, <heim@peanuts.informatik.uni-tuebingen.de> 14 * Fred Baumgarten, <dc6iq@insu1.etec.uni-karlsruhe.de> 15 * 16 * This program is free software; you can redistribute it and/or 17 * modify it under the terms of the GNU General Public License 18 * as published by the Free Software Foundation; either version 19 * 2 of the License, or (at your option) any later version. 20 */ 21 #include <asm/system.h>
22 #include <linux/autoconf.h>
23 #include <linux/sched.h>
24 #include <linux/socket.h>
25 #include <linux/net.h>
26 #include <linux/un.h>
27 #include <linux/in.h>
28 #include <linux/param.h>
29 #include "inet.h"
30 #include "dev.h"
31 #include "ip.h"
32 #include "protocol.h"
33 #include "tcp.h"
34 #include "udp.h"
35 #include "skbuff.h"
36 #include "sock.h"
37 #include "raw.h"
38
39 /* 40 * Get__netinfo returns the length of that string. 41 * 42 * KNOWN BUGS 43 * As in get_unix_netinfo, the buffer might be too small. If this 44 * happens, get__netinfo returns only part of the available infos. 45 */ 46 staticint 47 get__netinfo(structproto *pro, char *buffer)
/* */ 48 { 49 structsock **s_array;
50 structsock *sp;
51 char *pos=buffer;
52 inti;
53 inttimer_active;
54 unsignedlongdest, src;
55 unsignedshortdestp, srcp;
56
57 s_array = pro->sock_array;
58 pos+=sprintf(pos, "sl local_address rem_address st tx_queue rx_queue tr tm->when\n");
59 for(i = 0; i < SOCK_ARRAY_SIZE; i++) { 60 sp = s_array[i];
61 while(sp != NULL) { 62 dest = sp->daddr;
63 src = sp->saddr;
64 destp = sp->dummy_th.dest;
65 srcp = sp->dummy_th.source;
66
67 /* Since we are Little Endian we need to swap the bytes :-( */ 68 destp = ntohs(destp);
69 srcp = ntohs(srcp);
70
71 timer_active = del_timer(&sp->timer);
72 if (!timer_active)
73 sp->timer.expires = 0;
74 pos+=sprintf(pos, "%2d: %08X:%04X %08X:%04X %02X %08X:%08X %02X:%08X %02X\n",
75 i, src, srcp, dest, destp, sp->state,
76 sp->send_seq-sp->rcv_ack_seq, sp->acked_seq-sp->copied_seq,
77 timer_active, sp->timer.expires, sp->retransmits);
78 if (timer_active)
79 add_timer(&sp->timer);
80
81 /* Is place in buffer too rare? then abort. */ 82 if (pos > buffer+PAGE_SIZE-80) { 83 printk("oops, too many %s sockets for netinfo.\n",
84 pro->name);
85 return(strlen(buffer));
86 } 87
88 /* 89 * All sockets with (port mod SOCK_ARRAY_SIZE) = i 90 * are kept in sock_array[i], so we must follow the 91 * 'next' link to get them all. 92 */ 93 sp = sp->next;
94 } 95 } 96 return(strlen(buffer));
97 } 98
99
100 inttcp_get_info(char *buffer)
/* */ 101 { 102 returnget__netinfo(&tcp_prot, buffer);
103 } 104
105
106 intudp_get_info(char *buffer)
/* */ 107 { 108 returnget__netinfo(&udp_prot, buffer);
109 } 110
111
112 intraw_get_info(char *buffer)
/* */ 113 { 114 returnget__netinfo(&raw_prot, buffer);
115 }