UNIX上编译C语言写的SOCKET程序时出错
bwpic 2007-10-05 11:02:56 我在HP UNIX上编译C写的SOCKET程序时老是在opi_addr.sin_addr = *((struct in_addr*)he->h_addr);这一行提示变量类型不匹配.但我是按教程上来写的,不知道错在哪里。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <time.h>
#include <math.h>
#include <errno.h>
#include <stdarg.h>
#include <malloc.h>
#include <netinet/in.h>
#include <netdb.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/wait.h>
#define FAIL -1
#define SUCCEED 1
#define MYPORT 4950
#define h_addr ip_addr[20+1]
int main(int argc, char *argv[])
{
int* JUDGE_FLAG;
char* lot_id;
char IP_ADDRESS[10+1][20+1];
char ip_addr[20+1];
int sockfd;
struct sockaddr_in opi_addr;
sockfd = socket(AF_INET, SOCK_DGRAM, 0);
struct hostent *he
strcpy( ip_addr, IP_ADDRESS[a]);
opi_addr.sin_family = AF_INET;
opi_addr.sin_port = htons(MYPORT);
opi_addr.sin_addr = *((struct in_addr*)he->h_addr);
sendto(sockfd, lot_id, strlen(lot_id), 0, (struct sockaddr *)&opi_addr, sizeof(struct sockaddr));
sendto(sockfd, JUDGE_FLAG, 1, 0, (struct sockaddr *)&opi_addr, sizeof(struct sockaddr));
close(sockfd);
return SUCCEED;
}