#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的更多相关文章

  1. 【转】如何在Windows+VS2005使用最新静态libcurl 7.35.0获取网页数据,支持HTTPS

    地址: http://blog.csdn.net/hujkay作者:Jekkay Hu(34538980@qq.com)关键词:Windows,curl,ssl,  visual c++ 2005, ...

  2. C++ 用libcurl库进行http通讯网络编程

    使用libcurl完成http通讯,很方便而且是线程安全,转载一篇比较好的入门文章 转载自 http://www.cnblogs.com/moodlxs/archive/2012/10/15/2724 ...

  3. C++ 用libcurl库进行http通讯网络编程(转)

    转载:http://www.cnblogs.com/moodlxs/archive/2012/10/15/2724318.html 目录索引: 一.LibCurl基本编程框架 二.一些基本的函数 三. ...

  4. 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 ...

  5. [工作积累] android 中添加libssl和libcurl

    1. libssl https://github.com/guardianproject/openssl-android 然后执行ndk-build 2.libcurl 源代码组织结构, 下面的mak ...

  6. libcurl

    一.LibCurl基本编程框架 二.一些基本的函数 三.curl_easy_setopt函数部分选项介绍 四.curl_easy_perform 函数说明(error 状态码) 五.libcurl使用 ...

  7. libcurl编程学习

    一.curl简介 curl是一个利用URL语法在命令行方式下工作的文件传输工具.它支持的协议有:FTP, FTPS, HTTP, HTTPS, GOPHER, TELNET, DICT, FILE 以 ...

  8. libCURL动态分配buffer——节约内存

    libCURL是一个免费的.开源的强大客户端url传输库.支持的平台.协议甚广.平台上有Windows.Linux.FreeBSD:协议上有FTP.HTTP(S).Telnet.DICT.File等. ...

  9. C++ 用libcurl库进行http通讯网络编程[转]

    http://www.cnblogs.com/moodlxs/archive/2012/10/15/2724318.html 目录索引: 一.LibCurl基本编程框架 二.一些基本的函数 三.cur ...

随机推荐

  1. Yii提供的Htmler助手checkboxList可自定义Checkbox输出格式

    foreach($catetags as $cate){ echo Html::checkboxList('category_id','',$cate,['item'=>'customCheck ...

  2. STL之stack栈

    栈(statck)这种数据结构在计算机中是相当出名的.栈中的数据是先进后出的(First In Last Out, FILO).栈只有一个出口,允许新增元素(只能在栈顶上增加).移出元素(只能移出栈顶 ...

  3. JS 之高级函数

    作用域安全的构造函数 当使用new调用构造函数时,构造函数内部this对象会指向新创建的对象实例.如果不使用new,直接调用的话,则this对象会映射到window对象上.所以需要判断下. eg: f ...

  4. word 2010自定义快捷键提高工作效率

    经常使用word处理文档, 做笔记的时候会把word文档框缩小,以便同时看pdf同时记录笔记,但是缩小的word框不能把所有的菜单项显示出来,我比较常用那个插入边框下面的那个横线来做分割符,但是缩小了 ...

  5. Matlab中的数据类型

    Matlab中有15种基本数据类型,主要是整型.浮点.逻辑.字符.日期和时间.结构数组.单元格数组以及函数句柄等.         1.整型:(int8:uint8:int16:uint16:int3 ...

  6. IOS开发之——意见反馈UITextView的使用+不能输入字符输入

    @interface DMFeedbackViewController ()<UITextViewDelegate,UIAlertViewDelegate>@property (nonat ...

  7. bt协议详解 DHT篇(上)

    bt协议详解 DHT篇(上) 最近开发了一个免费教程的网站,突然产生了仔细了解bt协议的想法,这篇文章是bt协议详解系列的第三篇,后续还会写一些关于搜索和索引的东西,都是在开发这个网站的过程中学习到的 ...

  8. 你的C#代码是怎么跑起来的(一)

    写了那么多C#代码,大家有没有想过自己写的代码编译后的可执行文件内部是什么样子,是怎样在系统上运行的? 编译成exe,然后双击exe文件运行,这中间到底发生了些什么呢,这篇先来剖析下exe内部的样子: ...

  9. unity3d 纹理动画

    不知道大家有没有玩过赛车游戏 赛车游戏的跑道有路标,如下图 玩过赛车游戏的都知道,大多数赛车游戏的路标是会动的,如上图,它会从右往左运动 不会发动态图,大家脑补一下吧 没有玩过赛车游戏的也不要紧,大家 ...

  10. NFine框架的T4模板

    1.前言 前段时间在网上看到一个开源框架很好的.开源:ASP.NET MVC+EF6+Bootstrap开发框架,写代码就是比较比较麻烦,分层比较多,对于我这种偷懒的人就想到了写一个T4模板.不了解框 ...