- 论坛徽章:
- 0
|
#include "local.h"
#include "err.h"
main(int argc, char *argv[]) {
int orig_sock, new_sock, clnt_len;
static struct sockaddr_in clnt_adr, serv_adr;
int len,i;
const int on = 1;
iComLog(__FILE__,__LINE__,"%s\n","begin welcome!" ;
if (orig_sock = socket(AF_INET,SOCK_STREAM,0) < 0){
perror("generate error" ;
return FAIL;
}
bzero ( &serv_adr,0,sizeof(serv_adr) );
serv_adr.sin_family = AF_INET;
serv_adr.sin_addr.s_addr = htonl(INADDR_ANY);
serv_adr.sin_port = htons(8333);
setsockopt(orig_sock,SOL_SOCKET,SO_REUSEADDR,&on,sizeof(on));
if (bind( orig_sock, (struct sockaddr *) &serv_adr,sizeof(serv_adr)) < 0) {
perror("bind error" ;
close(orig_sock);
return FAIL;
}
if (listen(orig_sock,5) < 0) {
perror("listen error" ;
close(orig_sock);
return FAIL;
}
do {
clnt_len = sizeof(clnt_adr);
if ((new_sock = accept( orig_sock,(struct sockaddr *) &clnt_adr,&clnt_len)) < 0) {
perror("accept error" ;
close(orig_sock);
return FAIL;
}
if ( fork() == 0 ) {
while ((len = read(new_sock,buf,BUFSIZ)) >; 0 ){
for (i = 0; i < len; ++i)
buf = toupper(buf);
write(new_sock,buf,len);
if (buf[0] == '.') break;
}
close(new_sock);
exit (0);
}
else{
close(new_sock);
}
}while(1);
}
我在if (bind( orig_sock, (struct sockaddr *) &serv_adr,sizeof(serv_adr)) < 0) {
perror("bind error" ;
close(orig_sock);
return FAIL;
}
这里报错bind error: Socket operation on non-socket
不是socket的描述符,是文件描述符,我用的是HP-UX
怎么回事,请大家帮忙,急 |
|