在Linux下面的调用ping
我们在网络编程的时候经常要检测系统是否得到了有效的IP,是否可以正确联通到网络里面。通常的检查方法就是使用PING命令。
而在程序里面如何自动让程序知道哩?有两种办法,
一种是利用系统的能力,直接调用系统的shell,如方法一就可以在linux系统中很好使用。
另外一种是直接在代码里面实现ping命令,通过调用函数的形式来获取系统的状态。
还有更好的办法么,如有请回复。
方法一、
#include<stdlib.h>
void main()
{
int i;
int count=0;
while(1)
{
i=system("ping -c 1 10.27.60.122");
printf("\ni=%d",i);
count++;
if(i==0)
{
i=system("settop install;settop odtest.out");
break;
}
if(count>3)
{
printf("\n error cannot reach 10.27.60.122");
system("cd /root;ls;settop install;settop odtest.out");
break;
}
}
}
方法二、
/*
* P I N G . C
*
* Using the InterNet Control Message Protocol (ICMP) "ECHO" facility,
* measure round-trip-delays and packet loss across network paths.
*
* Author -
* Mike Muuss
* U. S. Army Ballistic Research Laboratory
* December, 1983
* Modified at Uc Berkeley
*
* Changed argument to inet_ntoa() to be struct in_addr instead of u_long
* DFM BRL 1992
*
* Status -
* Public Domain. Distribution Unlimited.
*
* Bugs -
* More statistics could always be gathered.
* This program has to run SUID to ROOT to access the ICMP socket.
*/
#include <stdio.h>
#include <errno.h>
#include <sys/time.h>
#include <sys/param.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/file.h>
#include <netinet/in_systm.h>
#include <netinet/in.h>
#include <netinet/ip.h&g
相关文档:
在Linux操作系统下修改IP、DNS和路由配置
ifconfig eth0 新ip
然后编辑/etc/sysconfig/network-scripts/ifcfg-eth0,修改ip
一、修改IP地址
[aeolus@db1 network-scripts]$ vi ifcfg-eth0
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=static
IPADDR=219.136.241.211
NETMASK=255.255.255.128
......
Linux Grep命令使用的详细介绍
1. grep简介
grep (global search regular expression(RE) and print out the line,全面搜索正则表达式并把行
打印出来)是一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把匹配的行打印出来。Unix的
grep家族包括grep、 egrep和fgrep。egrep和fgrep的命令只跟grep有很小不 ......
1.首先是获得linux内核源码,好像是废话,下载地址如下:ftp://ftp.kernel.org/pub/linux/kernel/v2.6/下载:
linux-2.6.16.22.tar.bz2 patch-2.6.22.6.bz2
上面一步需要说明的是一般而言,linux内核的各个补丁文件是根据某个linux内核的版本号来作的patch。
将上面的两个压缩文件解压:
tar jxvf linux-2.6.22.ta ......
很久没有用linux了,由于要学习linux下的内核编程又要重新拾起linux,用了这么久的windows对linux都快忘完了。所以边看资料和操作来复习一下linux的基本操作。
一、linux的目录结构
首先,linux的文件系统即本身是由VFS即Virtual File System Switch(虚拟文件系统)来实文件管理的,VFS本身是一个文件档案管理系统的一个 ......
软件包:
httpd-2.23
下载地址
http://apache.justdn.org/httpd/httpd-2.2.3.tar.gz
apr-1.27
apr-util-1.27
http://apache.justdn.org/apr/,版号自已找,最好和我的所提供的版本号一样
Oracle Berkeley DB 4.0.14
下载地址
http://download.oracle.com/berkeley-db/db-4.0.14.tar.gz
subversion-1.4.0
下载地址
......