易截截图软件、单文件、免安装、纯绿色、仅160KB

在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下php单服务器配置

操作系统CentOS 5.3
系统安装完成后,安装必要的包
yum install autoconf gcc gcc-c++ libjpeg libjpeg-level
libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs ......

Linux 下编译C程序

GCC 支持了许多不同的语言,包括 C、C++、Ada、Fortran、Objective C,Perl、Python 和 Ruby,甚至还有Java。
  Linux 内核和许多其他自由软件以及开放源码应用程序都是用 C 语言编写并使用 GCC 编译的。
  编译C++程序:
  -c 只编译不连接
  g++ file1 -c -o file1.o
  g++ file2 -c -o file2.o
  g++ f ......

Linux下GCC编程四个过程(2)


2)编译阶段
(Compiling)
第二步进行的是编译阶段,在这个阶段中,Gcc首先要检查代码的规范性、是否有语法错误等,以确定代码的实际要做的工作,在检查无误后,Gcc把代码翻译成汇编语言。用户可以使用”-S”选项来进行查看,该选项只进行编译而不进行汇编,生成汇编代码。
选项 -S
用法:[root]# gcc &ndash ......

1. Linux 基础命令

Unix基础
登录和退出
登陆:可以用Neterm、SecureCRT等终端登陆工具〔192.168.25.12 常用软件下有〕或者
telnet、ftp命令。
1.   telnet 远程终端访问
命令格式:telnet [hostname|IP address]
退出:ctrl+d  or  logout  or  exit
 
2.   ftp 远程文件传输
......

Linux解压命令,压缩命令

 许多刚刚接触Linux的人往往纠结于Linux的众多格式解压问题,今天 带给大家常用的Linux的解压命令,不妥之处,欢迎指正!
第一:以.tar.gz结尾的文件
tar xvzf file.tar.gz  或者 gzip -dc file.tar.gz | tar xvf -(这里用到了管道)
第二:以.zip结尾的文件
unzip file.zip
第三:以.tar.bz2结尾的文件
tar ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号