博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
libcurl with telnet
阅读量:5046 次
发布时间:2019-06-12

本文共 2471 字,大约阅读时间需要 8 分钟。

#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;
}

转载于:https://www.cnblogs.com/bigben0123/p/3184308.html

你可能感兴趣的文章
PopupWindow
查看>>
Bi-shoe and Phi-shoe (欧拉函数)
查看>>
English trip V1 - B 19. Life of Confucius 孔子的生活 Teacher:Patrick Key:
查看>>
js 去掉空格
查看>>
bee api new
查看>>
【HTML5】可以省略标记的元素
查看>>
vue工程化之去除Eslint验证
查看>>
VUE+WebPack实现精美Html5游戏设计:纸牌战争
查看>>
进程(第一部分)
查看>>
1-2微信公众平台测试账号
查看>>
Python列表边遍历边修改问题解决方案:alist[:]
查看>>
Java Threads - The volatile keyword
查看>>
POJ Layout
查看>>
HDU 4497 GCD and LCM
查看>>
带上传头像注册功能的实现
查看>>
[UVALive4329] Ping pong(树状数组,组合)
查看>>
为什么要学习算法和数据结构
查看>>
[Other] 应用下载网站的APK/IPA等常见MIME设置
查看>>
Parcelable和Serializable的区别
查看>>
媒介查询demo
查看>>