我试图使简单的服务器代码工作:
/*
NAME: udpServer0
SYNOPSIS: udpServer0
DESCRIPTION: The program creates a datagram socket in the inet
domain, binds it to port 12345 and receives any message
arrived to the socket and prints it out
*/
#include <stdio.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
int main(void)
{
int sd;
struct sockaddr_in server;
char buf[512];
int rc;
server.sin_family = AF_INET;
server.sin_addr.s_addr = htonl(INADDR_ANY);
server.sin_port = htons(12345);
sd = socket (AF_INET,SOCK_DGRAM,0);
bind( sd, (SA *) &server, sizeof(server));
for(;;){
rc=recv (sd, buf, sizeof(buf), 0);
buf[rc]= (char) NULL;
printf("Received: %s\n", buf);
}
}
我收到这些错误:
clang udp_server.c
udp_server.c:27:16: error: use of undeclared identifier 'SA'
bind( sd, (SA *) &server, sizeof(server));
^
udp_server.c:27:20: error: expected expression
bind( sd, (SA *) &server, sizeof(server));
^
2 errors generated.
我需要一些标题来避免这个问题吗?