连续多次调用inet_ntoa()结果重复
#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后面的调用会覆盖上一次的调用。
连续多次调用inet_ntoa()结果重复的更多相关文章
- 连续调用inet_ntoa打印出错的问题
近日写程序,在打印信息的时候调用了inet_ntoa函数,出现了打印一直出错的情况.google了一下,是因为inet_ntoa这类函数没有保证线程安全,其实现原理是在静态内容中申请一块内存,每次调用 ...
- Ionic2 rc2 Events 跨界面调用的使用方法及问题解决
Events:事件注册 在任意一界面注册事件之后可在任意界面根据事件名称进行调用. 首先看一下官方文档的调用方式 import { Events } from 'ionic-angular'; co ...
- 页面多次调用查询文章(have_posts())
通常来说一个页面只调用查询一次文章.have_posts() 如果页面,比如首页需要按照不同的查询参数调用多次文章 需要做如下处理: //loop前 $temp_query = $wp_que ...
- 在一个排序的链表中,存在重复的结点,请删除该链表中重复的结点,重复的结点不保留,返回链表头指针。 例如,链表1->2->3->3->4->4->5 处理后为 1->2->5
// test20.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include<iostream> #include< ...
- 一个简洁通用的调用DLL函数的帮助类
本次介绍一种调用dll函数的通用简洁的方法,消除了原来调用方式的重复与繁琐,使得我们调用dll函数的方式更加方便简洁.用过dll的人会发现c++中调用dll中的函数有点繁琐,调用过程是这样的:在加载d ...
- Ajax beforeSend和complete 方法与防止重复提交
$.ajax({ beforeSend: function(){ // Handle the beforeSend event }, complete: function(){ // Handle t ...
- ArrayList去除重复元素(包括字符串和自定义对象)
1.去除重复字符串 package com.online.msym; import java.util.ArrayList; import java.util.Iterator; @SuppressW ...
- inet_pton和inet_ntop inet_ntoa
Linux下地址转换函数 inet_pton ==> Ox inet_ntop ==> xxx.xxx.xxx #include <sys/types.h> #include ...
- (原创)一个简洁通用的调用DLL函数的帮助类
本次介绍一种调用dll函数的通用简洁的方法,消除了原来调用方式的重复与繁琐,使得我们调用dll函数的方式更加方便简洁.用过dll的人会发现c++中调用dll中的函数有点繁琐,调用过程是这样的:在加载d ...
随机推荐
- EF - Code First 开发方式
概述: 本节介绍通过 Code First 开发建立新数据库. 借助 Code First 可以选择使用类的特性和属性执行配置,或者使用 XML 配置文件来配置,当然也可以使用 Fluent API ...
- 【Python】Scrapy基础
一.Scrapy 架构 Engine(引擎):负责 Spider(爬虫).Item Pipeline(管道).Downloader(下载器).Scheduler(调度器)中的通讯和数据传递. Sche ...
- String字符串的常用方法
1.substr():可在字符串中抽取从 start 下标开始的指定数目的字符. stringObject.substr(start,length) start:必需.要抽取的子串的起始下标.必须是数 ...
- 一位资深Java架构师的晋级心得
架构师是什么? 是一个既需要掌控整体又需要洞悉局部瓶颈并依据具体的业务场景给出解决方案的团队领导型人物.一个架构师得需要足够的想像力,能把各种目标需求进行不同维度的扩展,为目标客户提供更为全面的需求清 ...
- echarts 自适应方法 x和y x2和y2
grid:{ x:65, y:20, x2:30, y2:30},
- js的回调函数
介绍首先从英文介绍开始 A callback is a function that is passed as an argument to another function and is execut ...
- test--3
<script type="text/javascript">// <![CDATA[$(function () { if (isLogined &&am ...
- 《用Python写爬虫》学习笔记(二)编写第一个网络爬虫
1.首先,下载网页使用Python的urllib2模块,或者Python HTTP模块request来实现 urllib2会出现问题,解决方法1.重试下载(设置下载次数) 2.设置用户代理 2.其次, ...
- python学习博客地址集合。。。
python学习博客地址集合... 老师讲课博客目录 http://www.bootcdn.cn/bootstrap/ bootstrap cdn在线地址 http://www.cnblogs. ...
- Linux常用shell命令
1.>>>>>刚安装好的ubuntu需要为root创建密码[解决]passwd root 2.>>>>>安装完ubuntu后需要更新[解决] ...