如何在libcurl中阻止对特定IP的HTTP请求?

时间:2015-05-12 09:23:04

标签: c++ libcurl

我正在使用libcurl(http://curl.haxx.se/libcurl/)来触发HTTP请求。 我想在FQDN解析为IP地址后阻止对特定IP地址的请求。

我如何以及在哪里阻止特定IP地址的请求?

2 个答案:

答案 0 :(得分:0)

使用getaddrinfo()查找FQDN的IP地址。使用该地址来确定是否提交卷曲请求。

答案 1 :(得分:0)

libcurl itself has no block-this-IP-functionality built-in. But it does provide you with the building blocks for you to build your own!

Use CURLOPT_OPENSOCKETFUNCTION and have your callback do the address check, and return failure if the "bad" address is used and otherwise you call the normal socket() function.