G?khan Alkan: > I try to develop poc code for postfix content filtering. All i need is read > the 10025/tcp and send all data which i can read to 10026/tcp. Below is my > poc code. But i try to send email it doesn't work and postfix show me "451 > 4.3.0 Error: queue file write error".
I recommend that you use netcat. Wietse > fcntl(server_sock, F_SETFL, O_NONBLOCK); What if fcntl() reports an error? > fcntl(client_sock, F_SETFL, O_NONBLOCK); client_sock is still zero here. What if fcntl() reports an error? > client_sock = accept(server_sock, (struct sockaddr > *)&client_addr, &addr_len); What if accept() reports an error? It will always return -1 because server_sock is non-blocking. Thus, client_sock will always be -1. > sock_fd = socket(AF_INET, SOCK_STREAM, 0); What if socket() reports an error? > while(1) { > result = recv(client_sock, buff, sizeof(buff),0 ); What if recv() reports an error? At this point, client_sock is -1 because accept() reported an error. See above. > inet_pton(AF_INET, REMOTE_IP, &remote_addr.sin_addr); > connect(sock_fd, (struct sockaddr *)&remote_addr, > sizeof(remote_addr)); What if connect() reports an error? > send(sock_fd, buff, (sizeof(buff)-1), 0); What if send() reports an error? > } The above program loops forever in while(1). > shutdown(client_sock, SHUT_RDWR); What if shutdown() reports an error? At this point client_sock is -1 because accept() reported an error. See above. > close(server_sock); > close(client_sock); > close(sock_fd); Wietse