xxxx18一60岁hd中国/日韩女同互慰一区二区/西西人体扒开双腿无遮挡/日韩欧美黄色一级片 - 色护士精品影院www

  • 大小: 10KB
    文件類(lèi)型: .c
    金幣: 1
    下載: 0 次
    發(fā)布日期: 2021-06-15
  • 語(yǔ)言: 其他
  • 標(biāo)簽: SSL??https??C??

資源簡(jiǎn)介

訪問(wèn)Https通信協(xié)議做的網(wǎng)站的時(shí)候,建立的socket套接字需要SSL協(xié)議認(rèn)證 ,加密之后,才可以和網(wǎng)站建立資源

資源截圖

代碼片段和文件信息

/*?
?
?*?OpenSSL?SSL/TLS?Https?Client?example?
?
?*?Only?for?Unix/Linux:?
?
?*????cc?-c?https.c?
?
?*????cc?-o?https?https.c?-lssl?
?
?*?OpenSSL?library?needed.?
?
?*?
?
?*?同時(shí)支持普通的socket連接以及基于普通socket基礎(chǔ)之上的ssl?
?
?*?連接。這對(duì)于已有的socket程序修改來(lái)說(shuō)會(huì)比較方便,不至于?
?
?*?和原來(lái)的結(jié)構(gòu)發(fā)生太大的沖突.?
?
?*?要注意的一點(diǎn),似乎當(dāng)使用socket套接字來(lái)創(chuàng)建ssl連接的時(shí)候?
?
?*?如果套接字是采用非阻塞方式建立的話,會(huì)導(dǎo)致ssl會(huì)話失敗,不?
?
?*?知道為什么。所以這里對(duì)于提供給https的套接字采用了普通的?
?
?*?connect方法創(chuàng)建。?
?
?*?
?
?*/??
??
??
#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(“發(fā)送數(shù)據(jù)內(nèi)容:%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

評(píng)論

共有 條評(píng)論