资源简介
ICS lab10 WebProxy
包含 proxy.c
代码片段和文件信息
/*
* proxy.c - CS:APP Web proxy
*
* TEAM MEMBERS:
* Andrew Carnegie ac00@cs.cmu.edu
* Harry Q. Bovik bovik@cs.cmu.edu
*
* A simple web proxy implement.
* No cache. No thread pool. No post method.
*
*/
#include “csapp.h“
#include
#define _DEBUG
#define DEFPORT 8888
typedef struct client_info
{
int connfd;
struct sockaddr_in sockaddr;
} client_info_t;
/*
* Gloval vars
*/
sem_t sem_log;
sem_t sem_dns;
FILE *log_file;
/*
* Function prototypes
*/
int parse_uri(char *uri char *target_addr char *path int *port);
void format_log_entry(char *logstring struct sockaddr_in *sockaddr char *uri int size);
void *work_init(void *arg);
void do_work(int connfd struct sockaddr_in *sockaddr);
void my_clienterror(int fd int errnum char *errmsg char *longmsg);
int open_clientfd_ts(char *hostname int port);
int Open_clientfd_ts(char *hostname int port) ;
void dbg_printf(char *format ...);
/*
* dbg_printf - only print msg in debug mode
*/
void dbg_printf(char *format ...)
{
#ifdef _DEBUG
va_list va;
va_start(va format);
vprintf(format va);
va_end(va);
#endif
}
/*
* wrapper of three rio functions
*/
ssize_t Rio_readnb_w(rio_t *rp void *usrbuf size_t n)
{
ssize_t rc;
if ((rc = rio_readnb(rp usrbuf n)) < 0)
{
fprintf(stderr “Rio_readnb error: %s\n“ strerror(errno));
return 0;
}
return rc;
}
ssize_t Rio_readlineb_w(rio_t *rp void *usrbuf size_t maxlen)
{
ssize_t rc;
if ((rc = rio_readlineb(rp usrbuf maxlen)) < 0)
{
fprintf(stderr “Rio_readlineb error: %s\n“ strerror(errno));
return 0;
}
return rc;
}
void Rio_writen_w(int fd void *usrbuf size_t n)
{
if (rio_writen(fd usrbuf n) != n)
fprintf(stderr “Rio_writen error: %s\n“ strerror(errno));
}
/*
* Open_clientfd_ts - wrapper of open_clientfd_s
*/
int Open_clientfd_ts(char *hostname int port)
{
int rc = open_clientfd_ts(hostname port);
if (rc == -1)
unix_error(“Open_clientfd_s Unix error“);
else if(rc == -2)
dns_error(“Open_clientfd_s DNS error“);
return rc;
}
/*
* open_clientfd_s - thread-safe version for open_clientfd
*/
int open_clientfd_ts(char *hostname int port)
{
int clientfd;
struct hostent *hp;
struct sockaddr_in serveraddr;
if ((clientfd = socket(AF_INET SOCK_STREAM 0)) < 0)
return -1; /* check errno for cause of error */
/* Fill in the server‘s IP address and port */
P(&sem_dns);
if ((hp = gethostbyname(hostname)) == NULL)
{
V(&sem_dns);
return -2; /* check h_errno for cause of error */
}
bzero((char *) &serveraddr sizeof(serveraddr));
serveraddr.sin_family = AF_INET;
bcopy((char *)hp->h_addr_list[0]
(char *)&serveraddr.sin_addr.s_addr hp->h_length);
V(&sem_dns);
serveraddr.sin_port = htons(port);
/* Establish a connection with the server */
if (connect(clientfd (SA *) &serveraddr sizeof(ser
- 上一篇:CATIA 直(斜)齿轮生成器V5R21下绝对好用
- 下一篇:网络RTK连接测试
相关资源
- OpenHaptics_API_Reference 完整API翻译
- zw_wangjunfeibj-4044319-wyLogistics.zip
- zw_STMicroelectronicsSTM32F4.zip
- radiomics图像特征计算程序46
- 稳定的有领航者的多移动agent群集运动
- elasticsearch漏洞监测工具
- Elasticsearch 7.0 7.x版本安装head+ik+配置
- qt 绘制流程图程序——Diagram
- Graphics.h教程
- 1994Nonlinear Dynamics and Chaos - Strogatz
- QGraphicsView Draw
- 在QGraphicsScene上画矩形
- ICSharpCode.SharpZipLib改过后的dll 不乱码
- 英特尔集成显卡及核心显卡Intel(R)
- Qt使用QGraphicsView实现滑动窗体效果
- WidgetTimeline.zip
- 深入理解计算机系统真题
- simics 4.6 最新版
- MyGraphics.rar
- Kinetics-400数据集.zip
- Qt QGraphics View架构
- Computer Graphics and Geometric Modeling: Impl
- elk Elasticsearch全套学习视频,基础篇,
- springboot+ElasticSearch搜索引擎
- IBM SPSS Statistics V21.0激活码
- NordicSemiconductor.nRF_DeviceFamilyPack.8.15.
- elasticsearch3台服务器集群
- LMCOMSOL_Multiphysics_SSQ.7z
-
《xm
l》实验任务书 xm l Basics & DT - ICSS变点检测方法.rar
评论
共有 条评论