--- /scp:root@sanders:/var/local/virtualmachine/kernels/linux-2.6.17.1/net/ipv4/proc.c +++ /var/local/src/linux-2.6.17.1/net/ipv4/proc.c @@ -44,6 +44,77 @@ #include #include + +//// New IP Address proc interface +#include +#include + +static int ipaddress_dev_ioctl(struct ifreq *ir, unsigned int cmd) +{ + int res; + mm_segment_t oldfs; + + oldfs = get_fs(); + set_fs(get_ds()); + res = devinet_ioctl(cmd, (struct ifreq __user *) ir); + set_fs(oldfs); + return res; +} + +static int ipaddress_seq_show(struct seq_file *seq, void *v) +{ + struct ifreq ir; + struct sockaddr_in * if_addr; + uint32_t local; + + memset(&ir, 0, sizeof(ir)); + strcpy(ir.ifr_ifrn.ifrn_name, "eth0"); + + ipaddress_dev_ioctl(&ir, SIOCGIFADDR); + + if_addr = (struct sockaddr_in *) ir.ifr_addr.sa_data; + local = if_addr->sin_addr.s_addr; + + seq_printf(seq, "eth0: %u\n", local); + + /* + ipaddress_dev_ioctl(&ir, SIOCGIFNETMASK); + if_addr = (struct sockaddr_in *) ir.ifr_addr.sa_data; + mask = if_addr->sin_addr.s_addr; + + ipaddress_dev_ioctl(&ir, SIOCGIFBRDADDR); + if_addr = (struct sockaddr_in *) ir.ifr_addr.sa_data; + broadcast = if_addr->sin_addr.s_addr; + + ipaddress_dev_ioctl(&ir, SIOCGIFDSTADDR); + if_addr = (struct sockaddr_in *) ir.ifr_addr.sa_data; + destination = if_addr->sin_addr.s_addr; + + seq_printf(seq, "ethx: %u %u %u %u\n", + local, + mask, + broadcast, + destination); + */ + return 0; +} + +static int ipaddress_seq_open(struct inode *inode, struct file *file) +{ + return single_open(file, ipaddress_seq_show, NULL); +} + +static struct file_operations ipaddress_seq_fops = { + .owner = THIS_MODULE, + .open = ipaddress_seq_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; + +//// End new IP Address proc interface + + static int fold_prot_inuse(struct proto *proto) { int res = 0; @@ -65,7 +136,7 @@ fold_prot_inuse(&tcp_prot), atomic_read(&tcp_orphan_count), tcp_death_row.tw_count, atomic_read(&tcp_sockets_allocated), atomic_read(&tcp_memory_allocated)); - seq_printf(seq, "UDP: inuse %d\n", fold_prot_inuse(&udp_prot)); + seq_printf(seq, "UDP: inuse %d\n", fold_prot_inuse(&udp_prot)); seq_printf(seq, "RAW: inuse %d\n", fold_prot_inuse(&raw_prot)); seq_printf(seq, "FRAG: inuse %d memory %d\n", ip_frag_nqueues, atomic_read(&ip_frag_mem)); @@ -365,8 +436,14 @@ if (!proc_net_fops_create("sockstat", S_IRUGO, &sockstat_seq_fops)) goto out_sockstat; + + if (!proc_net_fops_create("ipaddress", S_IRUGO, &ipaddress_seq_fops)) + goto out_ipaddress; + out: return rc; +out_ipadress: + proc_net_remove("sockstat"); out_sockstat: proc_net_remove("snmp"); out_snmp: Diff finished. Sat Oct 14 12:29:27 2006