?? dgechoaddr.c
字號(hào):
#include "unp.h"#undef MAXLINE#define MAXLINE 20 /* to see datagram truncation */voiddg_echo(int sockfd, SA *pcliaddr, socklen_t clilen){ int flags; const int on = 1; socklen_t len; ssize_t n; char mesg[MAXLINE], str[INET6_ADDRSTRLEN]; struct in_addr dstaddr;#ifdef IP_RECVDSTADDR Setsockopt(sockfd, IPPROTO_IP, IP_RECVDSTADDR, &on, sizeof(on));#endif for ( ; ; ) { len = clilen; flags = 0; n = Recvfrom_flags(sockfd, mesg, MAXLINE, &flags, pcliaddr, &len, &dstaddr); printf("%d-byte datagram from %s", n, Sock_ntop(pcliaddr, len)); if ((flags & MSG_CTRUNC) == 0) printf(", to %s", Inet_ntop(AF_INET, &dstaddr, str, sizeof(str)));#ifdef MSG_TRUNC if (flags & MSG_TRUNC) printf(" (datagram truncated)");#endif#ifdef MSG_BCAST if (flags & MSG_BCAST) printf(" (broadcast)");#endif#ifdef MSG_MCAST if (flags & MSG_MCAST) printf(" (multicast)");#endif printf("\n"); Sendto(sockfd, mesg, n, 0, pcliaddr, clilen); }}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -