libcurl with telnet
#include <stdio.h>
#include <string.h>
#include <curl/curl.h>
#include <curl/easy.h>
#include <errno.h>
#include <dirent.h>
#include <unistd.h>
size_t write_data(void *buffer, size_t size, size_t nmemb, void *userp);
static CURL *curl;
size_t write_data(void *buffer, size_t size, size_t nmemb, void *userp) {
DIR * dp;
struct dirent *dirp;
int fd, bytes, cnt;
char dirs[128], dircmp[NAME_MAX], lbuf[2];
static long socketdno;
static char buflast;
static int madewrite = 0;
static int sockfdokay = 0;
if (size * nmemb == 0)
return (0);
printf("%c", *(char *) buffer);
if (*(char *) buffer == ' ' && buflast == ':') {
if (!madewrite) {
madewrite = 1;
sprintf(dirs, "/proc/%d/fd", getpid());
dp = opendir(dirs);
dp = opendir(dirs);
if (dp) {
dirp = (struct dirent *) 1;
for (cnt = 0; dirp;) {
dirp = readdir(dp);
if (dirp) {
cnt++;
printf("dir is: %s cnt: %d\n", dirp->d_name, cnt);
sprintf(dirs, "/proc/%d/fd/%s", getpid(), dirp->d_name);
memset(dircmp, 0, NAME_MAX);
if (readlink(dirs, dircmp, NAME_MAX) != -1) {
printf("link points to: %s\n", dircmp);
if (!strncmp(dircmp, "socket:", strlen("socket:")) && cnt == 6) {
printf("found socket at expected position: %d link: %s\n",
cnt, dirp->d_name);
sockfdokay = 1;
}
}
}
}
printf("fd dir count %d\n", cnt);
closedir(dp);
}
if (cnt == 8 && sockfdokay == 1) { //
bytes = write(3, "CogcoG\r\r", strlen("CogcoG\r\r"));
printf("wrote: %d bytes sock: %d\n", bytes, 3);
bytes = 1;
bytes = write(3, "who\r", strlen("who\r"));
printf("wrote: %d bytes sock: %d\n", bytes, 3);
#if 0
while (bytes >0 ) {
bytes = read(3,lbuf,1);
printf("lub:: %c ::\n",lbuf);
}
#endif
bytes = write(3, "quit\r", strlen("quit\r"));
printf("wrote: %d bytes sock: %d\n", bytes, 3);
bytes = write(3, "exit\r", strlen("exit\r"));
printf("wrote: %d bytes sock: %d\n", bytes, 3);
}
}
}
buflast = *(char *) buffer;
/* printf("bytes in: %d\n",size*nmemb); */
return (size * nmemb);
}
//int main(int argc, char **argv)
int main() {
FILE *hd_src;
int res;
curl = curl_easy_init();
/* Get curl 7.7 from sunet.se's FTP site: */
curl_easy_setopt(curl, CURLOPT_URL, "telnet://192.168.1.1");
curl_easy_setopt(curl, CURLOPT_USERPWD, "user:password");
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
res = curl_easy_perform(curl);
printf("res is: %d\n", res);
/* always cleanup */
curl_easy_cleanup(curl);
/* fclose(ftpfile); close the local file */
return 0;
}
libcurl with telnet的更多相关文章
- 【转】如何在Windows+VS2005使用最新静态libcurl 7.35.0获取网页数据,支持HTTPS
地址: http://blog.csdn.net/hujkay作者:Jekkay Hu(34538980@qq.com)关键词:Windows,curl,ssl, visual c++ 2005, ...
- C++ 用libcurl库进行http通讯网络编程
使用libcurl完成http通讯,很方便而且是线程安全,转载一篇比较好的入门文章 转载自 http://www.cnblogs.com/moodlxs/archive/2012/10/15/2724 ...
- C++ 用libcurl库进行http通讯网络编程(转)
转载:http://www.cnblogs.com/moodlxs/archive/2012/10/15/2724318.html 目录索引: 一.LibCurl基本编程框架 二.一些基本的函数 三. ...
- curl Protocol 'http not supported or disabled in libcurl
C:\Documents and Settings\ganiks.liu\Desktop\curl-7.37.0-win32\bin>curl -V curl 7.37.0 (i386-pc-w ...
- [工作积累] android 中添加libssl和libcurl
1. libssl https://github.com/guardianproject/openssl-android 然后执行ndk-build 2.libcurl 源代码组织结构, 下面的mak ...
- libcurl
一.LibCurl基本编程框架 二.一些基本的函数 三.curl_easy_setopt函数部分选项介绍 四.curl_easy_perform 函数说明(error 状态码) 五.libcurl使用 ...
- libcurl编程学习
一.curl简介 curl是一个利用URL语法在命令行方式下工作的文件传输工具.它支持的协议有:FTP, FTPS, HTTP, HTTPS, GOPHER, TELNET, DICT, FILE 以 ...
- libCURL动态分配buffer——节约内存
libCURL是一个免费的.开源的强大客户端url传输库.支持的平台.协议甚广.平台上有Windows.Linux.FreeBSD:协议上有FTP.HTTP(S).Telnet.DICT.File等. ...
- C++ 用libcurl库进行http通讯网络编程[转]
http://www.cnblogs.com/moodlxs/archive/2012/10/15/2724318.html 目录索引: 一.LibCurl基本编程框架 二.一些基本的函数 三.cur ...
随机推荐
- Windows server 2008系统基本优化
前几天用上了Windows server 2008刚开始还真不习惯,毕竟是做服务器用的系统和娱乐操作系统有很大区别.先总结几点,以后慢慢更新 安装Win2008驱动: 大部分支持vista系统的驱动都 ...
- Saltstack-进阶篇
查看minion端的文件内容 [root@linux-node2 ~]# cat /etc/resolv.conf # Generated by NetworkManager nameserver 1 ...
- NSURLSession学习笔记
NSURLSession学习笔记(一)简介 一.URL Session的基本概念 1.三种工作模式: 默认会话模式(default):工作模式类似于原来的NSURLConnection,使用的是基于磁 ...
- 005医疗项目-模块一:用户的查找:1.用户表查询的sql语句
这是医疗项目的第一个模块:做一个用户的查询,可以根据用户的账号,用户的名称,单位的名称,用户的类型去查询.要求效果如下:
- 查询Sqlserver数据库死锁的一个存储过程(转)
链接 :http://www.cnblogs.com/mzhanker/archive/2011/06/04/2072739.html 使用sqlserver作为数据库的应用系统,都避免不了有时候会产 ...
- [服务]ftp主动模式和被动模式
经常忘记这个东西.于是总结下这东西感受下这个协议. FTP连接方式 控制连接:标准端口为21,用于发送FTP命令信息 数据连接:标准端口为20,用于上传.下载数据 数据连接的建立类型: 主动模式:服务 ...
- Linux 发送信号
使用kill命令 --在命令行执行kill命令.向指定进程发送信号. 使用kill函数 int kill(pid_t pid,int sig); --参数pid指定一个要杀死的进程,而sig是要发送的 ...
- Linux非root用户安装jdk和tomcat
转载自:http://blog.csdn.net/wuyigong111/article/details/17410661,进行部分修改 创建一个用户 sgmm,并在其用户目录里面安装 jdk和tom ...
- python爬虫中文网页cmd打印出错问题解决
问题描述 用python写爬虫,很多时候我们会先在cmd下先进行尝试. 运行爬虫之后,肯定的,我们想看看爬取的结果. 于是,我们print... 运气好的话,一切顺利.但这样的次数不多,更多地,我们会 ...
- [CareerCup] 9.11 Parenthesize the Expression 表达式加括号
9.11 Given a boolean expression consisting of the symbols 0,1, &, |, and ^, and a desired boolea ...