I'm working on a client/server ftp program for a class using UNIX sockets in C. I have to send my data to this process my professor is having us use to simulate network traffic (called "troll"). It requires a special header. So I was going to try to make a struct with the header and then tack my data on to it... but my compiler keeps giving me this error...
"cannot convert to a pointer type" (referring to the last line of code)
I can not figure out what I am doing wrong...
/* make troll header */
struct sockaddr_in dest, troll;
struct {
struct sockaddr_in header;
char body[MAXDATASIZE];
} message;
message.header.sin_family = htons(AF_INET);
message.header.sin_port = htons(SERVER_PORT);
bcopy((char *)&server_name.sin_addr, (char *)&message.header.sin_addr, sizeof(server_name.sin_addr));
troll.sin_family = AF_INET;
troll.sin_port = htons(TROLL_PORT);
bcopy((char *)&name.sin_addr, (char *)&troll.sin_addr, sizeof(name.sin_addr));
/* send mini_buffer to troll */
memcpy(message.body, mini_buffer, MAXDATASIZE);
int result = sendto(troll_sock, (char *) &message, sizeof(message), 0, (struct sockaddr *) troll, sizeof(troll));
You need to pass the address of troll - not the the object itself. Try: ...(struct sockaddr *)(&troll)...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.