【发布时间】:2024-01-21 21:22:02
【问题描述】:
我使用以下函数从文件描述符中读取...
int cread(int fd, char *buf, int n){
int nread;
if((nread=read(fd, buf, n))<0){
perror("Reading data");
exit(1);
}
return nread;
}
以下是使用上述函数的函数
if(FD_ISSET(tap_fd, &rd_set)){
/* data from tun/tap: just read it and write it to the network */
nread = cread(tap_fd, buffer, BUFSIZE);
tap2net++;
do_debug("TAP2NET %lu: Read %d bytes from the tap interface\n", tap2net, nread);
/* write length + packet */
plength = htons(nread);
nwrite = cwrite(net_fd, (char *)&plength, sizeof(plength));
nwrite = cwrite(net_fd, buffer, nread);
do_debug("TAP2NET %lu: Written %d bytes to the network\n", tap2net, nwrite);
}
它们都适用于 TCP siocket,但不适用于 udp 套接字。任何帮助将不胜感激
【问题讨论】:
-
tap_fd是否在为 UDP 案例设置的文件描述符中?
标签: networking udp tcp