我是 C++ 的初学者,我正在将 C 代码(TWAMP RFC5357)移植到一个新项目(IPSLA RFC 6812)中,我遇到了这个问题:
当我尝试使用函数send时,我看到错误“error C2664: 'send' : cannot convert parameter 2 from 'ServerGreeting' to 'const char *'” “No user-defined-conversion operator available that can perform this conversion ,否则无法调用运算符”。
所以,我搜索了这个,我发现了一些我不明白的答案。
这是一些代码:
typedef struct server_greeting
{
UINT8 未使用[12];
UINT32 模式;
UINT8 挑战[16];
UINT8 盐[16];
UINT32 计数;
UINT8 MBZ[12];
} 服务器问候;
struct active_session {
int socket;
// RequestSession req;
};
struct client_info {
int socket;
sockaddr_in addr;
int sess_no;
struct active_session sessions[MAX_SESSIONS_PER_CLIENT];
timeval shutdown_time;
};
static void cleanup_client (struct client_info *client)
{
fprintf (stderr,"Cleanup client %s\n", inet_ntoa(client->addr.sin_addr));
FD_CLR(client->socket,&read_fds);
closesocket(client->socket);
used_sockets--;
int i;
for (i = 0; i < client->sess_no; i++)
/* If socket is -1 the session has already been closed */
if (client->sessions[i].socket > 0) {
FD_CLR(client->sessions[i].socket, &read_fds);
closesocket(client->sessions[i].socket);
client->sessions[i].socket = -1;
used_sockets--;
}
memset(client, 0, sizeof(struct client_info));
//client->status = kOffline;
}
static int send_greeting(UINT8 mode_mask, struct client_info *client)
{
int socket = client->socket;
int i;
ServerGreeting greet;
memset(&greet, 0, sizeof(greet));
greet.Modes = 1 & mode_mask;
for (i = 0; i < 16; i++)
greet.Challenge[i] = rand() % 16;
for (i = 0; i < 16; i++)
greet.Salt[i] = rand() % 16;
greet.Count = (1 << 12);
int rv = send (socket, greet, sizeof(greet), 0);
if (rv < 0) {
fprintf(stderr, "[%s] ", inet_ntoa(client->addr.sin_addr));
perror("Failed to send ServerGreeting message");
cleanup_client(client);
} else {
printf("Sent ServerGreeting message to %s. Result %d\n",
inet_ntoa(client->addr.sin_addr), rv);
}
return rv;
}
你能帮我解决这个问题吗?谢谢