#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <pcap.h>

#include <arpa/inet.h>

#include "myerror.h"

int main(int argc, char* argv[])
{
struct in_addr net_ip_address; struct in_addr net_mask_address; u_int32_t net_ip; u_int32_t net_mask; char errbuff[PCAP_ERRBUF_SIZE]; char* net_ip_string; char* net_mask_string; char* net_interface_string; if((net_interface_string=pcap_lookupdev(errbuff))==NULL)
err_sys("lookup dev error"); if(pcap_lookupnet(net_interface_string,&net_ip,&net_mask,errbuff)!=)
err_sys("lookup net error"); net_ip_address.s_addr=net_ip; net_mask_address.s_addr=net_mask; if((net_ip_string=inet_ntoa(net_ip_address))==NULL)
err_sys("ip ntoa error"); if((net_mask_string=inet_ntoa(net_mask_address))==NULL)
err_sys("mask ntoa error"); printf("Network interface is %s\n",net_interface_string); printf("Network ip is %s\n",net_ip_string); printf("Network mask is %s\n",net_mask_string); return ;
}

在一个生存周期内,inet_ntoa返回一个char *,而这个char *的空间是在inet_ntoa里面静态分配的,所以inet_ntoa后面的调用会覆盖上一次的调用。

第一句printf的结果只能说明在printf里面的可变参数的求值是从右到左的,仅此而已。

连续多次调用inet_ntoa()结果重复的更多相关文章

  1. 连续调用inet_ntoa打印出错的问题

    近日写程序,在打印信息的时候调用了inet_ntoa函数,出现了打印一直出错的情况.google了一下,是因为inet_ntoa这类函数没有保证线程安全,其实现原理是在静态内容中申请一块内存,每次调用 ...

  2. Ionic2 rc2 Events 跨界面调用的使用方法及问题解决

    Events:事件注册  在任意一界面注册事件之后可在任意界面根据事件名称进行调用. 首先看一下官方文档的调用方式 import { Events } from 'ionic-angular'; co ...

  3. 页面多次调用查询文章(have_posts())

    通常来说一个页面只调用查询一次文章.have_posts()   如果页面,比如首页需要按照不同的查询参数调用多次文章 需要做如下处理:   //loop前 $temp_query = $wp_que ...

  4. 在一个排序的链表中,存在重复的结点,请删除该链表中重复的结点,重复的结点不保留,返回链表头指针。 例如,链表1->2->3->3->4->4->5 处理后为 1->2->5

    // test20.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include<iostream> #include< ...

  5. 一个简洁通用的调用DLL函数的帮助类

    本次介绍一种调用dll函数的通用简洁的方法,消除了原来调用方式的重复与繁琐,使得我们调用dll函数的方式更加方便简洁.用过dll的人会发现c++中调用dll中的函数有点繁琐,调用过程是这样的:在加载d ...

  6. Ajax beforeSend和complete 方法与防止重复提交

    $.ajax({ beforeSend: function(){ // Handle the beforeSend event }, complete: function(){ // Handle t ...

  7. ArrayList去除重复元素(包括字符串和自定义对象)

    1.去除重复字符串 package com.online.msym; import java.util.ArrayList; import java.util.Iterator; @SuppressW ...

  8. inet_pton和inet_ntop inet_ntoa

    Linux下地址转换函数 inet_pton ==> Ox inet_ntop ==> xxx.xxx.xxx #include <sys/types.h> #include ...

  9. (原创)一个简洁通用的调用DLL函数的帮助类

    本次介绍一种调用dll函数的通用简洁的方法,消除了原来调用方式的重复与繁琐,使得我们调用dll函数的方式更加方便简洁.用过dll的人会发现c++中调用dll中的函数有点繁琐,调用过程是这样的:在加载d ...

随机推荐

  1. ES6/ES7/ES8常用特性和新特性

    转自:https://www.jianshu.com/p/9da4aa1c9970

  2. AJAX的简单解释

    什么是AJAX AJAX = 异步 JavaScript 和 XML. AJAX 是一种用于创建快速动态网页的技术. 通过在后台与服务器进行少量数据交换,AJAX 可以使网页实现异步更新.这意味着可以 ...

  3. springboot秒杀课程学习整理1-1

    1)新建一个maven工程quickStart,然后在pom文件里添加依赖 <parent> <groupId>org.springframework.boot</gro ...

  4. UVa LA 4636 Cubist Artwork 难度: 0

    题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...

  5. 修改create-react-app支持多入口

    使用Facebook官方脚手架create-react-app创建React应用,默认只能生成一个SPA,入口是index.html.虽然,SPA的页面切换可以使用前台路由框架方便(比如React-R ...

  6. 搭建SSH框架心得

    <Struts2+Spring4+hibernate3> 工程结构 导入相关jar包:自行网上百度即可,根据环境需要 写dao类 以及实现 package com.icommon.dao; ...

  7. JavaScript js 引入CDN 不生效 注意事项

    [博客园cnblogs笔者m-yb原创,转载请加本文博客链接,笔者github: https://github.com/mayangbo666,公众号aandb7,QQ群927113708]https ...

  8. 从0到1用eclipse用maven搭建web项目

    1,默认已经搭建了JDK1.5以上,以及eclipseEE版本,和maven. 2,修改maven的本地仓库和镜像,修改本地仓库是为了方便我们管理,maven的默认仓库是在C盘的USER文件夹下,我一 ...

  9. Mad Libs 游戏

    name1=input('请输入一个名字:') name2=input('再输入一个名字:') print('丑不拉几的{}被美丽的{}给迷得神魂颠倒'.format(name1,name2)) in ...

  10. java 两行代码解析json文件

    public void JsonRead() throws IOException{ String str = FileUtils.readFileToString(new File("D: ...