Skip to content
Commits on Source (2)
......@@ -754,6 +754,38 @@ void intercept_sendpkt(const char *legend,
}
}
int intercept_select(int nfds, fd_set *readfds)
{
char pkt_dump[BUFSIZ];
int nfound;
if (mode == replay)
{
get_operation("select ");
/* FIXME: replay implementation here */
return 0;
} else {
nfound = select(nfds + 1, readfds, NULL, NULL, NULL);
if (mode == capture)
{
int fd;
snprintf(pkt_dump, sizeof(pkt_dump),
"select %d:", nfound);
for (fd = 0; fd <= nfds; fd++)
if (FD_ISSET(fd, readfds))
snprintf(pkt_dump + strlen(pkt_dump),
sizeof(pkt_dump) - strlen(pkt_dump),
" %d", fd);
strlcat(pkt_dump, "\n", sizeof(pkt_dump));
fputs(pkt_dump, stdout);
}
return nfound;
}
}
ssize_t intercept_recvfrom(int sockfd, void *buf, size_t len, int flags,
struct sockaddr *src_addr, socklen_t *addrlen)
{
......@@ -766,20 +798,56 @@ ssize_t intercept_recvfrom(int sockfd, void *buf, size_t len, int flags,
/* FIXME: replay implementation here */
recvlen = 0; /* squish compiler warning */
} else {
char *cp;
snprintf(pkt_dump, sizeof(pkt_dump),
"recvfrom %d %0x %s",
sockfd, flags, socktoa((sockaddr_u *)src_addr));
for (cp = (char *)buf; cp < (char *)buf + len; cp++)
snprintf(pkt_dump + strlen(pkt_dump),
sizeof(pkt_dump) - strlen(pkt_dump),
"%0x", *cp);
strlcat(pkt_dump, "\n", sizeof(pkt_dump));
recvlen = recvfrom(sockfd, buf, len, flags, src_addr, addrlen);
if (mode == capture)
{
char *cp;
snprintf(pkt_dump, sizeof(pkt_dump),
"recvfrom %d %0x %s",
sockfd, flags, socktoa((sockaddr_u *)src_addr));
for (cp = (char *)buf; cp < (char *)buf + recvlen; cp++)
snprintf(pkt_dump + strlen(pkt_dump),
sizeof(pkt_dump) - strlen(pkt_dump),
"%0x", *cp);
strlcat(pkt_dump, "\n", sizeof(pkt_dump));
fputs(pkt_dump, stdout);
}
}
return recvlen;
}
ssize_t intercept_recvmsg(int sockfd, struct msghdr *msg, int flags)
{
char pkt_dump[BUFSIZ];
ssize_t recvlen;
if (mode == replay)
{
get_operation("recvmsg ");
/* FIXME: replay implementation here */
recvlen = 0; /* squish compiler warning */
} else {
recvlen = recvmsg(sockfd, msg, flags);
if (mode == capture) {
char *cp;
snprintf(pkt_dump, sizeof(pkt_dump),
"recvmsg %d %0x %s",
sockfd, msg->msg_flags,
socktoa((sockaddr_u *)(&msg->msg_name)));
for (cp = (char *)msg->msg_iov->iov_base;
cp < (char *)msg->msg_iov->iov_base + recvlen;
cp++)
snprintf(pkt_dump + strlen(pkt_dump),
sizeof(pkt_dump) - strlen(pkt_dump),
"%0x", *cp);
strlcat(pkt_dump, "\n", sizeof(pkt_dump));
fputs(pkt_dump, stdout);
}
}
return recvlen;
......
......@@ -23,8 +23,10 @@ void intercept_get_systime(const char *, l_fp *);
long intercept_ntp_random(const char *);
void intercept_sendpkt(const char *,
sockaddr_u *, struct interface *, int, void *, int);
int intercept_select(int nfds, fd_set *);
ssize_t intercept_recvfrom(int, void *,
size_t, int, struct sockaddr *, socklen_t *);
ssize_t intercept_recvmsg(int sockfd, struct msghdr *msg, int flags);
SOCKET intercept_open_socket(sockaddr_u *, bool, bool, endpt *);
bool intercept_drift_read(const char *, double *);
void intercept_drift_write(char *, double);
......
......@@ -3347,7 +3347,7 @@ read_network_packet(
msghdr.msg_flags = 0;
msghdr.msg_control = (void *)&control;
msghdr.msg_controllen = sizeof(control);
rb->recv_length = recvmsg(fd, &msghdr, 0);
rb->recv_length = intercept_recvmsg(fd, &msghdr, 0);
#endif
buflen = rb->recv_length;
......@@ -3445,8 +3445,7 @@ io_handler(void)
* Mostly harmless, I think.
*/
rdfdes = activefds;
nfound = select(maxactivefd + 1, &rdfdes, NULL,
NULL, NULL);
nfound = intercept_select(maxactivefd, &rdfdes);
if (nfound > 0) {
l_fp ts;
......