登录
注册
开源
企业版
高校版
搜索
帮助中心
使用条款
关于我们
开源
企业版
高校版
私有云
Gitee AI
NEW
我知道了
查看详情
登录
注册
代码拉取完成,页面将自动刷新
捐赠
捐赠前请先登录
取消
前往登录
扫描微信二维码支付
取消
支付完成
支付提示
将跳转至支付宝完成支付
确定
取消
Watch
不关注
关注所有动态
仅关注版本发行动态
关注但不提醒动态
1
Star
0
Fork
0
20191205
/
zx代码
代码
Issues
19
Pull Requests
0
Wiki
统计
流水线
服务
Gitee Pages
JavaDoc
PHPDoc
质量分析
Jenkins for Gitee
腾讯云托管
腾讯云 Serverless
悬镜安全
阿里云 SAE
Codeblitz
我知道了,不再自动展开
更新失败,请稍后重试!
Issues
/
详情
移除标识
内容风险标识
本任务被
标识为内容中包含有代码安全 Bug 、隐私泄露等敏感信息,仓库外成员不可访问
timeserv.c
待办的
#I4ITJ3
20191205
拥有者
创建于
2021-11-18 16:24
/* timeserv.c - a socket-based time of day server */ #include <stdio.h> #include <unistd.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <netdb.h> #include <time.h> #include <strings.h> #define PORTNUM 13000 /* our time service phone number */ #define HOSTLEN 256 #define oops(msg) { perror(msg) ; exit(1) ; } int main(int ac, char *av[]) { struct sockaddr_in saddr; /* build our address here */ struct hostent *hp; /* this is part of our */ char hostname[HOSTLEN]; /* address */ int sock_id,sock_fd; /* line id, file desc */ FILE *sock_fp; /* use socket as stream */ char *ctime(); /* convert secs to string */ time_t thetime; /* the time we report */ /* * Step 1: ask kernel for a socket */ sock_id = socket( PF_INET, SOCK_STREAM, 0 ); /* get a socket */ if ( sock_id == -1 ) oops( "socket" ); /* * Step 2: bind address to socket. Address is host,port */ bzero( (void *)&saddr, sizeof(saddr) ); /* clear out struct */ gethostname( hostname, HOSTLEN ); /* where am I ? */ hp = gethostbyname( hostname ); /* get info about host */ /* fill in host part */ bcopy( (void *)hp->h_addr, (void *)&saddr.sin_addr, hp->h_length); saddr.sin_port = htons(PORTNUM); /* fill in socket port */ saddr.sin_family = AF_INET ; /* fill in addr family */ if ( bind(sock_id, (struct sockaddr *)&saddr, sizeof(saddr)) != 0 ) oops( "bind" ); /* * Step 3: allow incoming calls with Qsize=1 on socket */ if ( listen(sock_id, 1) != 0 ) oops( "listen" ); /* * main loop: accept(), write(), close() */ int times = 0; while ( 1 ){ sock_fd = accept(sock_id, NULL, NULL); /* wait for call */ times++; printf("Wow! got %d calls!\n", times); if ( sock_fd == -1 ) oops( "accept" ); /* error getting calls */ sock_fp = fdopen(sock_fd,"w"); /* we'll write to the */ if ( sock_fp == NULL ) /* socket as a stream */ oops( "fdopen" ); /* unless we can't */ thetime = time(NULL); /* get time */ /* and convert to strng */ fprintf( sock_fp, "The time here is .." ); fprintf( sock_fp, "%s", ctime(&thetime) ); fclose( sock_fp ); /* release connection */ } }
/* timeserv.c - a socket-based time of day server */ #include <stdio.h> #include <unistd.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <netdb.h> #include <time.h> #include <strings.h> #define PORTNUM 13000 /* our time service phone number */ #define HOSTLEN 256 #define oops(msg) { perror(msg) ; exit(1) ; } int main(int ac, char *av[]) { struct sockaddr_in saddr; /* build our address here */ struct hostent *hp; /* this is part of our */ char hostname[HOSTLEN]; /* address */ int sock_id,sock_fd; /* line id, file desc */ FILE *sock_fp; /* use socket as stream */ char *ctime(); /* convert secs to string */ time_t thetime; /* the time we report */ /* * Step 1: ask kernel for a socket */ sock_id = socket( PF_INET, SOCK_STREAM, 0 ); /* get a socket */ if ( sock_id == -1 ) oops( "socket" ); /* * Step 2: bind address to socket. Address is host,port */ bzero( (void *)&saddr, sizeof(saddr) ); /* clear out struct */ gethostname( hostname, HOSTLEN ); /* where am I ? */ hp = gethostbyname( hostname ); /* get info about host */ /* fill in host part */ bcopy( (void *)hp->h_addr, (void *)&saddr.sin_addr, hp->h_length); saddr.sin_port = htons(PORTNUM); /* fill in socket port */ saddr.sin_family = AF_INET ; /* fill in addr family */ if ( bind(sock_id, (struct sockaddr *)&saddr, sizeof(saddr)) != 0 ) oops( "bind" ); /* * Step 3: allow incoming calls with Qsize=1 on socket */ if ( listen(sock_id, 1) != 0 ) oops( "listen" ); /* * main loop: accept(), write(), close() */ int times = 0; while ( 1 ){ sock_fd = accept(sock_id, NULL, NULL); /* wait for call */ times++; printf("Wow! got %d calls!\n", times); if ( sock_fd == -1 ) oops( "accept" ); /* error getting calls */ sock_fp = fdopen(sock_fd,"w"); /* we'll write to the */ if ( sock_fp == NULL ) /* socket as a stream */ oops( "fdopen" ); /* unless we can't */ thetime = time(NULL); /* get time */ /* and convert to strng */ fprintf( sock_fp, "The time here is .." ); fprintf( sock_fp, "%s", ctime(&thetime) ); fclose( sock_fp ); /* release connection */ } }
评论 (
0
)
20191205
创建了
任务
登录
后才可以发表评论
状态
待办的
待办的
进行中
已完成
已关闭
负责人
未设置
标签
未设置
标签管理
里程碑
未关联里程碑
未关联里程碑
Pull Requests
未关联
未关联
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
未关联
未关联
master
公文代码
开始日期   -   截止日期
-
置顶选项
不置顶
置顶等级:高
置顶等级:中
置顶等级:低
优先级
不指定
严重
主要
次要
不重要
参与者(1)
1
https://gitee.com/two_thousand_and_thirteen/zx-code.git
git@gitee.com:two_thousand_and_thirteen/zx-code.git
two_thousand_and_thirteen
zx-code
zx代码
点此查找更多帮助
搜索帮助
Git 命令在线学习
如何在 Gitee 导入 GitHub 仓库
Git 仓库基础操作
企业版和社区版功能对比
SSH 公钥设置
如何处理代码冲突
仓库体积过大,如何减小?
如何找回被删除的仓库数据
Gitee 产品配额说明
GitHub仓库快速导入Gitee及同步更新
什么是 Release(发行版)
将 PHP 项目自动发布到 packagist.org
评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册