|
TCPIP
TCPIP
[ol]#define _GNU_SOURCE#include #include #include #include #include const char* redir = "HTTP/1.1 301 Moved Permanently\r\n" "Location: http://www.baidu.com\r\n\r\n";int main(){ struct sockaddr_in sa; memset(&sa,0,sizeof(sa)); sa.sin_family = AF_INET; sa.sin_port = htons(8888); int fd = socket(AF_INET,SOCK_STREAM,0); bind(fd,(struct sockaddr*)&sa,sizeof(sa)); listen(fd,16); int xfd; while(1) { xfd = accept4(fd, NULL, NULL, SOCK_NONBLOCK); write(xfd, redir, strlen(redir)); close(xfd); } close(fd); return 0;}[/ol]复制代码
差不多得了
|
|