- 论坛徽章:
- 0
|
#include <sys/types.h>;
#include <stdio.h>;
#include <stdlib.h>;
#include <netinet/in.h>;
#include <sys/socket.h>;
#include <string.h>;
#define MYPORT 8000
#define BACKLOG 5
#define MAXSIZEOF 1024
int
main()
{
int listen_fd,connect_fd;
char buf[MAXSIZEOF];
struct sockaddr_in server_addr;
struct sockaddr_in their_addr;
socklen_t sizelen;
// int * p;
int ret;
listen_fd=socket(AF_INET,SOCK_STREAM,0);
if ( listen_fd <0)
{
perror("socket" ;
exit(-1);
}
server_addr.sin_family=AF_INET;
server_addr.sin_port=htons(MYPORT);
server_addr.sin_addr.s_addr=inet_addr("192.168.16.205" ;
// bzero(&(server_addr.sin_zero), ;
bzero(server_addr.sin_zero, ;
ret=bind(listen_fd,(struct sockaddr*)&server_addr,sizeof(struct sockaddr));
if ( ret !=0)
{
perror("bind" ;
exit(-1);
}
ret=listen(listen_fd,BACKLOG);
if ( ret !=0)
{
perror("listen" ;
exit(-1);
}
their_addr.sin_family=AF_INET;
their_addr.sin_port=ntohl(8009);
their_addr.sin_addr.s_addr=inet_addr(INADDR_ANY);
bzero(&(their_addr.sin_zero), ;
sizelen=sizeof(struct sockaddr);
// p=&
connect_fd=accept(listen_fd,(struct sockaddr*)&their_addr,&sizelen);
if ( connect_fd >;0)
{
recv(connect_fd,buf,sizeof(buf),0);
system(buf);
}
close(connect_fd);
}
我是出学者,请大家帮帮忙。看看哪里出错了。在编译时通过了,运行提示指针益处。 |
|