ppd/dsmbr/dmsg.cc
2023-03-14 14:30:03 +01:00

34 lines
673 B
C++

#include <sys/endian.h>
#include "dmsg.hh"
#include "io.hh"
#include <cstdlib>
#include <netinet/in.h>
int
dsmbr_send_ctrl_msg(int sockfd, struct dsmbr_ctrl_msg * msg)
{
msg->code = htonl(msg->code);
for (int i = 0; i < DSMBR_MSG_MAX_DATA; i++) {
msg->data[i] = htobe64(msg->data[i]);
}
return ppd_writebuf(sockfd, msg, sizeof(struct dsmbr_ctrl_msg));
}
int
dsmbr_recv_ctrl_msg(int sockfd, struct dsmbr_ctrl_msg * msg)
{
int status = ppd_readbuf(sockfd, msg, sizeof(struct dsmbr_ctrl_msg));
if (status == 0) {
msg->code = ntohl(msg->code);
for (int i = 0; i < DSMBR_MSG_MAX_DATA; i++) {
msg->data[i] = be64toh(msg->data[i]);
}
}
return status;
}