📄 67.htm
字号:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>CTerm非常精华下载</title>
</head>
<body bgcolor="#FFFFFF">
<table border="0" width="100%" cellspacing="0" cellpadding="0" height="577">
<tr><td width="32%" rowspan="3" height="123"><img src="DDl_back.jpg" width="300" height="129" alt="DDl_back.jpg"></td><td width="30%" background="DDl_back2.jpg" height="35"><p align="center"><a href="http://apue.dhs.org"><font face="黑体"><big><big>123</big></big></font></a></td></tr>
<tr>
<td width="68%" background="DDl_back2.jpg" height="44"><big><big><font face="黑体"><p align="center"> ● UNIX网络编程 (BM: clown) </font></big></big></td></tr>
<tr>
<td width="68%" height="44" bgcolor="#000000"><font face="黑体"><big><big><p align="center"></big></big><a href="http://cterm.163.net"><img src="banner.gif" width="400" height="60" alt="banner.gif"border="0"></a></font></td>
</tr>
<tr><td width="100%" colspan="2" height="100" align="center" valign="top"><br><p align="center">[<a href="index.htm">回到开始</a>][<a href="54.htm">上一层</a>][<a href="68.htm">下一篇</a>]
<hr><p align="left"><small>发信人: scz (小四), 信区: UNP <br>
标 题: 直接编译运行这个checkopt.c <br>
发信站: UNIX编程 (2001年08月29日12:04:24 星期三), 站内信件 <br>
<br>
简单改了几行,直接编译就可以了 <br>
<br>
/* include checkopts1 */ <br>
/* *INDENT-OFF* */ <br>
<br>
#include <ctype.h> /* for isalpha() */ <br>
#include <dirent.h> /* for readdir() */ <br>
#include <getopt.h> /* for getopt_long() */ <br>
#include <stdio.h> <br>
#include <stdlib.h> <br>
#include <string.h> <br>
#include <stdarg.h> /* ANSI C header file */ <br>
#include <syslog.h> /* for syslog() */ <br>
#include <errno.h> <br>
#include <fcntl.h> /* for nonblocking */ <br>
#include <netdb.h> <br>
#include <pwd.h> /* for getpass */ <br>
#include <pthread.h> /* for pthread_ */ <br>
#include <signal.h> <br>
#include <unistd.h> <br>
#include <time.h> /* timespec{} for pselect() */ <br>
#include <sys/ioctl.h> <br>
#include <sys/mman.h> /* for mmap */ <br>
#include <sys/poll.h> /* for poll */ <br>
#include <sys/socket.h> /* basic socket definitions */ <br>
#include <sys/stat.h> /* for S_xxx file mode constants */ <br>
#include <sys/time.h> /* timeval{} for select() */ <br>
#include <sys/types.h> /* basic system data types */ <br>
#include <sys/uio.h> /* for iovec{} and readv/writev */ <br>
#include <sys/un.h> /* for Unix domain sockets */ <br>
#include <sys/wait.h> <br>
#include <sys/ipc.h> /* for share memory */ <br>
#include <sys/resource.h> /* for pr_cpu_time */ <br>
#include <sys/shm.h> <br>
#include <sys/user.h> /* for PAGE_SIZE */ <br>
#include <net/if.h> /* for ifreq */ <br>
#include <net/ethernet.h> <br>
#include <netinet/in.h> /* sockaddr_in{} and other Internet defns */ <br>
#include <netinet/ip.h> /* for iphdr */ <br>
#include <netinet/ip_icmp.h> <br>
/* for icmphdr */ <br>
#include <netinet/igmp.h> /* for igmp */ <br>
#include <netinet/tcp.h> /* for tcphdr */ <br>
#include <netinet/udp.h> /* for udphdr */ <br>
#include <net/if_arp.h> /* for arphdr */ <br>
#include <arpa/inet.h> /* inet(3) functions */ <br>
#include <linux/if_ether.h> <br>
/* for ethhdr #define ETH_P_ALL 0x0003 */ <br>
#include <linux/if_packet.h> <br>
<br>
union val { <br>
int i_val; <br>
long l_val; <br>
char c_val[10]; <br>
struct linger linger_val; <br>
struct timeval timeval_val; <br>
} val; <br>
<br>
static char *sock_str_flag(union val *, int); <br>
static char *sock_str_int(union val *, int); <br>
static char *sock_str_linger(union val *, int); <br>
static char *sock_str_timeval(union val *, int); <br>
<br>
<br>
struct sock_opts { <br>
char *opt_str; <br>
int opt_level; <br>
int opt_name; <br>
char *(*opt_val_str)(union val *, int); <br>
} sock_opts[] = { <br>
"SO_BROADCAST", SOL_SOCKET, SO_BROADCAST, sock_str_flag, <br>
"SO_DEBUG", SOL_SOCKET, SO_DEBUG, <br>
sock_str_flag, <br>
"SO_DONTROUTE", SOL_SOCKET, SO_DONTROUTE, sock_str_flag, <br>
"SO_ERROR", SOL_SOCKET, SO_ERROR, <br>
sock_str_int, <br>
"SO_KEEPALIVE", SOL_SOCKET, SO_KEEPALIVE, sock_str_flag, <br>
"SO_LINGER", SOL_SOCKET, SO_LINGER, sock_str <br>
_linger, <br>
"SO_OOBINLINE", SOL_SOCKET, SO_OOBINLINE, sock_str_flag, <br>
"SO_RCVBUF", SOL_SOCKET, SO_RCVBUF, sock_str <br>
_int, <br>
"SO_SNDBUF", SOL_SOCKET, SO_SNDBUF, sock_str <br>
_int, <br>
"SO_RCVLOWAT", SOL_SOCKET, SO_RCVLOWAT, sock_str_int, <br>
"SO_SNDLOWAT", SOL_SOCKET, SO_SNDLOWAT, sock_str_int, <br>
"SO_RCVTIMEO", SOL_SOCKET, SO_RCVTIMEO, sock_str_timeval <br>
, <br>
"SO_SNDTIMEO", SOL_SOCKET, SO_SNDTIMEO, sock_str_timeval <br>
, <br>
"SO_REUSEADDR", SOL_SOCKET, SO_REUSEADDR, sock_str_flag, <br>
#ifdef SO_REUSEPORT <br>
"SO_REUSEPORT", SOL_SOCKET, SO_REUSEPORT, sock_str_flag, <br>
#else <br>
"SO_REUSEPORT", 0, 0, <br>
NULL, <br>
#endif <br>
"SO_TYPE", SOL_SOCKET, SO_TYPE, <br>
sock_str_int, <br>
"IP_TOS", IPPROTO_IP, IP_TOS, <br>
sock_str_int, <br>
"IP_TTL", IPPROTO_IP, IP_TTL, <br>
sock_str_int, <br>
"TCP_MAXSEG", IPPROTO_TCP,TCP_MAXSEG, sock_str_int, <br>
"TCP_NODELAY", IPPROTO_TCP,TCP_NODELAY, sock_str_flag, <br>
NULL, 0, 0, <br>
NULL <br>
}; <br>
}; <br>
/* *INDENT-ON* */ <br>
/* end checkopts1 */ <br>
<br>
/* include checkopts2 */ <br>
int <br>
main(int argc, char **argv) <br>
{ <br>
int fd, len; <br>
struct sock_opts *ptr; <br>
<br>
fd = socket(AF_INET, SOCK_STREAM, 0); <br>
<br>
for (ptr = sock_opts; ptr->opt_str != NULL; ptr++) { <br>
printf("%s: ", ptr->opt_str); <br>
if (ptr->opt_val_str == NULL) <br>
printf("(undefined)\n"); <br>
else { <br>
len = sizeof(val); <br>
if (getsockopt(fd, ptr->opt_level, ptr->opt_name, <br>
&val, &len) == -1) { <br>
perror("getsockopt error"); <br>
exit( -1 ); <br>
} else { <br>
printf("default = %s\n", (*ptr->opt_val_str)(&va <br>
l, len)); <br>
} <br>
} <br>
} <br>
exit(0); <br>
} <br>
/* end checkopts2 */ <br>
<br>
/* include checkopts3 */ <br>
static char strres[128]; <br>
<br>
static char * <br>
sock_str_flag(union val *ptr, int len) <br>
{ <br>
/* *INDENT-OFF* */ <br>
if (len != sizeof(int)) <br>
snprintf(strres, sizeof(strres), "size (%d) not sizeof(int)", le <br>
n); <br>
else <br>
snprintf(strres, sizeof(strres), <br>
"%s", (ptr->i_val == 0) ? "off" : "on"); <br>
return(strres); <br>
/* *INDENT-ON* */ <br>
} <br>
/* end checkopts3 */ <br>
<br>
static char * <br>
sock_str_int(union val *ptr, int len) <br>
{ <br>
if (len != sizeof(int)) <br>
snprintf(strres, sizeof(strres), "size (%d) not sizeof(int)", le <br>
n); <br>
else <br>
snprintf(strres, sizeof(strres), "%d", ptr->i_val); <br>
return(strres); <br>
} <br>
<br>
static char * <br>
sock_str_linger(union val *ptr, int len) <br>
{ <br>
struct linger *lptr = &ptr->linger_val; <br>
<br>
<br>
if (len != sizeof(struct linger)) <br>
snprintf(strres, sizeof(strres), <br>
"size (%d) not sizeof(struct linger)", len); <br>
else <br>
snprintf(strres, sizeof(strres), "l_onoff = %d, l_linger = %d", <br>
lptr->l_onoff, lptr->l_linger); <br>
return(strres); <br>
} <br>
<br>
static char * <br>
sock_str_timeval(union val *ptr, int len) <br>
{ <br>
struct timeval *tvptr = &ptr->timeval_val; <br>
<br>
if (len != sizeof(struct timeval)) <br>
snprintf(strres, sizeof(strres), <br>
"size (%d) not sizeof(struct timeval)", len); <br>
else <br>
snprintf(strres, sizeof(strres), "%d sec, %d usec", <br>
tvptr->tv_sec, tvptr->tv_usec); <br>
return(strres); <br>
} <br>
-- <br>
<br>
也许有一天,他再从海上蓬蓬的雨点中升起, <br>
飞向西来,再形成一道江流,再冲倒两旁的石壁, <br>
再来寻夹岸的桃花。然而,我不敢说来生,也不敢信来生...... <br>
※ 来源:·UNIX编程 www.tiaozhan.com/unixbbs/·[FROM: 211.167.65.123] <br>
</small><hr>
<p align="center">[<a href="index.htm">回到开始</a>][<a href="54.htm">上一层</a>][<a href="68.htm">下一篇</a>]
<p align="center"><a href="http://cterm.163.net">欢迎访问Cterm主页</a></p>
</table>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -