Chinaunix首页 | 论坛 | 博客
  • 博客访问: 234434
  • 博文数量: 30
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 300
  • 用 户 组: 普通用户
  • 注册时间: 2014-01-26 17:22
个人简介

linux初学者~

文章分类

全部博文(30)

文章存档

2017年(9)

2016年(6)

2015年(6)

2014年(9)

我的朋友

分类: LINUX

2014-07-28 09:23:53

在修改dnsmasq代码时,发现receive_query中使用recvmsg收到的DNS query总是没有源IP,调试代码如下:
printf("source=%s, to=%s", inet_ntoa(source_addr.in.sin_addr), inet_ntoa(dst_addr_4));
打印结果:
source=192.168.1.1, to=192.168.1.1

在高人指点下,终于发现是inet_ntoa接口特性所致,inet_ntoa的man手册描述如下:
The inet_ntoa() function converts the Internet host address in, given in network byte order, to a string in IPv4 dotted-decimal notation.
The string is returned in a statically allocated buffer, which subse-quent calls will overwrite.

修改成分2个printf分别打印source和to就OK了。

总结:
1、不熟悉的接口一定要仔细阅读man手册;
2、不熟悉的接口先上网搜索,前人遇到过这个问题,并且总结了相应的文章。
阅读(1793) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~