#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include <stdio.h>
#include <string>
#include <iostream>
#include <cstring>
using namespace std;
void peek_interfaces(int fd);
void print_hw_addr(int fd, const char* if_name);
int main() {
int fd = socket(AF_INET, SOCK_DGRAM, 0);
if(-1 == fd) {
perror("Failed create socket.");
return -1;
}
peek_interfaces(fd);
close(fd);
return 0;
}
void peek_interfaces(int fd) {
ifreq ifs[16] = {0};
ifconf conf = {sizeof(ifs)};
conf.ifc_req = ifs;
if(-1 == ioctl(fd, SIOCGIFCONF, &conf)) {
perror("Failed IOCTL SIOCGIFCONF.");
return;
}
if(conf.ifc_len >= sizeof(ifs)) {
perror("Buffer too small for IOCTL SIOCGIFCONF.");
return;
}
int num = conf.ifc_len / sizeof(ifreq);
cout << num << " interface entry retrieved." << endl;
for(int i = 0; i < num; ......
操作系统 Fedora 10
mysql安装包 mysql-5.0.85.tar.gz
1、创建mysql用户组和用户名
# groupadd mysqlGroup
(创建组)
# useradd -g mysqlGroup mysqlUser
(创建一帐号)
2、解压安装包 ,当前目录为 /home/hust/down/mysql/
# tar -xvzf mysql-5.0.85.tar.gz
解压后目录为:/home/hust/down/mysql/
mysql-5.0.85
注意安装文档 /home/hust/down/mysql/
mysql-5.0.85/INSTALL-SOURCE
3、建立mysql安装目录,将mysql 安装到 /usr/local/mysql5 下
# cd /usr/local
#ls
如果没有mysql5目录,建立mysql5目录
# mkdir mysql5
否则重新建立一个新目录来安装mysql
4、假设建立好了目录 /usr/local/mysql5
转到 安装文件目录
# cd /home/hust/down/mysql/
mysql-5.0.85
# ./confiure --prefix=/usr/local/mysql5 \
(配置安装路径)
> --with-mysqld-user=mysqlUser
&n ......
操作系统 Fedora 10
mysql安装包 mysql-5.0.85.tar.gz
1、创建mysql用户组和用户名
# groupadd mysqlGroup
(创建组)
# useradd -g mysqlGroup mysqlUser
(创建一帐号)
2、解压安装包 ,当前目录为 /home/hust/down/mysql/
# tar -xvzf mysql-5.0.85.tar.gz
解压后目录为:/home/hust/down/mysql/
mysql-5.0.85
注意安装文档 /home/hust/down/mysql/
mysql-5.0.85/INSTALL-SOURCE
3、建立mysql安装目录,将mysql 安装到 /usr/local/mysql5 下
# cd /usr/local
#ls
如果没有mysql5目录,建立mysql5目录
# mkdir mysql5
否则重新建立一个新目录来安装mysql
4、假设建立好了目录 /usr/local/mysql5
转到 安装文件目录
# cd /home/hust/down/mysql/
mysql-5.0.85
# ./confiure --prefix=/usr/local/mysql5 \
(配置安装路径)
> --with-mysqld-user=mysqlUser
&n ......
Linux提供了大量的命令,利用它可以有效地完成大量的工
作,如磁盘操作、文件存取、目录操作、进程管理、文件权限设定等。所以,在Linux系统上工作离不开使用系统提供的命令。要想真正理解Linux系统,
就必须从Linux命令学起,通过基础的命令学习可以进一步理解Linux系统。
不同Linux发行版的命令数量不一样,但Linux发行版本最少的命令也有200多个。这里笔者把比较重要和使用频率最多的命令,按照它们在系统中的作用分成下面六个部分一一介绍。
◆ 安装和登录命令:
login、shutdown、halt、reboot、install、mount、umount、chsh、exit、last;
◆ 文件处理命令:
file、mkdir、grep、dd、find、mv、ls、diff、cat、ln;
◆ 系统管理相关命令:
df、top、free、quota、at、lp、adduser、groupadd、kill、crontab;
◆ 网络操作命令:
ifconfig、ip、ping、netstat、telnet、ftp、route、rlogin、rcp、finger、mail、 nslookup;
◆ 系统安全相关命令:
passwd、su、umask、chgrp、chmod、chown、chattr、sudo ps、who;
◆ 其它命令:
tar、unzip、gunzip、unarj、mtools、man、unendcode、uudecode。
本文以Mandrake Linux 9.1(Kenrel 2.4.21)为例,介绍Li ......
#ifndef __KERNEL__
#define __KERNEL__
#endif
#ifndef MODULE
#define MODULE
#endif
#include<linux/config.h>
#include<linux/module.h>
#include<linux/version.h>
#include<linux/init.h>
#include<linux/kernel.h>
#include<linux/errno.h>
#include<linux/sched.h>//声明中断
#include<linux/fs.h>//声明file文件
#include<asm/system.h>/*cli(),*_flages*/
#include<linux/poll.h>
#include<linux/types.h>
#include<linux/slab.h>
#include <asm/arch/S3C2410.h>
#include <asm/hardware.h>//devf
//-------------------------------
#include <asm/io.h>/* ioremap */
#include <linux/delay.h>
#include <asm/delay.h>
//--------------------------------
#include <asm-arm/arch-s3c2410/smdk.h>
#include <linux/ioport.h>
#include <asm/irq.h>
#include <asm/mach/irq.h>
//define the interrupt No.
#define interrupt_k4 IRQ_EINT0
#define interrupt_k3 IRQ_EI ......
#ifndef __KERNEL__
#define __KERNEL__
#endif
#ifndef MODULE
#define MODULE
#endif
#include<linux/config.h>
#include<linux/module.h>
#include<linux/version.h>
#include<linux/init.h>
#include<linux/kernel.h>
#include<linux/errno.h>
#include<linux/sched.h>//声明中断
#include<linux/fs.h>//声明file文件
#include<asm/system.h>/*cli(),*_flages*/
#include<linux/poll.h>
#include<linux/types.h>
#include<linux/slab.h>
#include <asm/arch/S3C2410.h>
#include <asm/hardware.h>//devf
//-------------------------------
#include <asm/io.h>/* ioremap */
#include <linux/delay.h>
#include <asm/delay.h>
//--------------------------------
#include <asm-arm/arch-s3c2410/smdk.h>
#include <linux/ioport.h>
#include <asm/irq.h>
#include <asm/mach/irq.h>
//define the interrupt No.
#define interrupt_k4 IRQ_EINT0
#define interrupt_k3 IRQ_EI ......
#!/bin/bash
while getopts "ab:cd:" Option
# b and d take arguments
#
do
case $Option in
a) echo -e "a = $OPTIND";;
b) echo -e "b = $OPTIND $OPTARG";;
c) echo -e "c = $OPTIND";;
d) echo -e "d = $OPTIND $OPTARG";;
esac
done
shift $(($OPTIND - 1)) ......
from:http://blog.chinaunix.net/u2/62281/showart_1096746.html
sock_raw原始套接字编程可以接收到本机网卡上的数据帧或者数据包,对与监听网络的流量和分析是很有作用的.一共可以有3种方式创建这种socket
1.socket(AF_INET, SOCK_RAW, IPPROTO_TCP|IPPROTO_UDP|IPPROTO_ICMP)发送接收ip数据包
2.socket(PF_PACKET, SOCK_RAW, htons(ETH_P_IP|ETH_P_ARP|ETH_P_ALL))发送接收以太网数据帧
3.socket(AF_INET, SOCK_PACKET, htons(ETH_P_IP|ETH_P_ARP|ETH_P_ALL))过时了,不要用啊
理解一下SOCK_RAW的原理, 比如网卡收到了一个 14+20+8+100+4 的udp的以太网数据帧.
首先,网卡对该数据帧进行硬过滤(根据网卡的模式不同会有不同的动作,如果设置了promisc混杂模式的话,则不做任何过滤直接交给下一层输
入例程,否则非本机mac或者广播mac会被直接丢弃).按照上面的例子,如果成功的话,会进入ip输入例程.但是在进入ip输入例程之前,系统会检查系
统中是否有通过socket(AF_PACKET, SOCK_RAW,
..)创建的套接字.如果有的话并且协议相符,在这个例子中就是需要ETH_P_IP或者ETH_P_ALL类型.系统就给每个这样的socket接收缓
冲区发送一个数据帧拷贝.然后进入下一 ......