91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 10KB
    文件類型: .c
    金幣: 1
    下載: 0 次
    發布日期: 2021-06-15
  • 語言: 其他
  • 標簽: SSL??https??C??

資源簡介

訪問Https通信協議做的網站的時候,建立的socket套接字需要SSL協議認證 ,加密之后,才可以和網站建立資源

資源截圖

代碼片段和文件信息

/*?
?
?*?OpenSSL?SSL/TLS?Https?Client?example?
?
?*?Only?for?Unix/Linux:?
?
?*????cc?-c?https.c?
?
?*????cc?-o?https?https.c?-lssl?
?
?*?OpenSSL?library?needed.?
?
?*?
?
?*?同時支持普通的socket連接以及基于普通socket基礎之上的ssl?
?
?*?連接。這對于已有的socket程序修改來說會比較方便,不至于?
?
?*?和原來的結構發生太大的沖突.?
?
?*?要注意的一點,似乎當使用socket套接字來創建ssl連接的時候?
?
?*?如果套接字是采用非阻塞方式建立的話,會導致ssl會話失敗,不?
?
?*?知道為什么。所以這里對于提供給https的套接字采用了普通的?
?
?*?connect方法創建。?
?
?*?
?
?*/??
??
??
#include???
??
#include???
??
#include???
??
#include???
??
#include???
??
#include???
??
#include???
??
#include???
??
#include???
??
#include???
??
#include???
??
#include???
??
??
#include???
??
#include???
??
#include???
??
#include???
??
??
#define?BUF_LEN?1024??
??
#define?MAX_STRING_LEN??2048??
??
??
//xnet_select?x?defines??
??
#define?READ_STATUS?????0??
??
#define?WRITE_STATUS????1??
??
#define?EXCPT_STATUS????2??
??
??
/*?flag?to?set?request?with?ssl?or?not.?*/??
??
static?int?bIsHttps?=?1;??
??
??
static?int?timeout_sec?=?10;??
??
static?int?timeout_microsec?=?0;??
??
??
void?err_doit(int?errnoflag?const?char?*fmt?va_list?ap);??
??
void?err_quit(const?char?*fmt?...);??
??
int?create_tcpsocket(const?char?*host?const?unsigned?short?port);??
??
int?xnet_select(int?s?int?sec?int?usec?short?x);??
??
??
int?main(int?argc?char*?argv[])
{??
??
????char*?host?=?“127.0.0.1“;??
??
????unsigned?short?port?=?80;??
??
??
????int?fd;??
??
??????
??
????SSL?*ssl;??
??
????SSL_CTX?*ctx;??
??
??
????int?nret;??
??
??
????char?buf[BUF_LEN];??
??
????char*?requestpath?=?“/“;??
??
??
????if(?argc?==?5?)
????{??
??
????????host?=?argv[1];??
??
????????port?=?atoi(argv[2]);??
??
????????requestpath?=?argv[3];??
??
????????bIsHttps?=?atoi(argv[4]);??
??
????}?
????else
printf(“Argc?Err?!!!“);?
????printf(“host:%s??port:%d??requestpath:%s\n“hostportrequestpath);?
????/*?make?connection?to?the?cache?server?*/??
??
????fd?=?create_tcpsocket(host?port);??
????printf(“建立套接字\n“);
??
????/*?http?request.?*/??
??
????sprintf(buf?“GET?%s?HTTP/1.0\r\nHost:?%s\r\n\r\n“requestpath?host);??
??
????if(bIsHttps?!=?1)
????{??
??
????????if(xnet_select(fd?timeout_sec?timeout_microsec?WRITE_STATUS)>0)
{??
??
????????????/*?send?off?the?message?*/??
?
???printf(“發送數據內容:%s\n“buf);
?
????????????write(fd?buf?strlen(buf));??
??
????????}??
??
????????else
{??
??
????????????err_quit(“Socket?I/O?Write?Timeout?%s:%d\n“?host?port);??
??
????????}??
??
????????printf(“Server?response:\n“);??
??
????????while?(xnet_select(fd?timeout_sec?timeout_microsec?READ_STATUS)>0)
{??
??
????????????if?((n?=?read(fd?buf?BUF_LEN-1))?>?0)?
????{??
??
????????????????buf[n]?=?‘\0‘;??
??
????????????????printf(“%s“?buf);??
??
????????????}??
??
????????????else
????{??
??
????????????????break;??
??
????????????}??
??
????????}??
??
????????//?close?the?plain?s

評論

共有 條評論