#include #include #include #include #include #include #include #include #include #include #include /* Remote server: socat - tcp4-listen:667 */ int main() { int sockfd = socket(AF_INET, SOCK_STREAM, 0); struct sockaddr_in servaddr; bzero(&servaddr,sizeof(servaddr)); servaddr.sin_family = AF_INET; servaddr.sin_addr.s_addr=inet_addr("192.168.12.254"); servaddr.sin_port=htons(667); int result = connect(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr)); if(result != 0) { perror("failed to connect"); exit(1); } char sendbuf[4096]; memset(sendbuf, 0, sizeof(sendbuf)); strcpy(sendbuf, "NOOP\n"); int max_seg = 0, max_seg_len = sizeof(max_seg), get_res = 0; for (int i = 0; i < 10; ++i) { errno = 0; int send_res = send(sockfd, sendbuf, sizeof(sendbuf), 0); printf("[%d SEND result: %d, strerror: %s]\n", time(NULL), send_res, strerror(errno)); get_res = getsockopt(sockfd, SOL_TCP, TCP_MAXSEG, &max_seg, &max_seg_len); printf("tcp max seg: res: %d, max_seg: %d\n", get_res, max_seg); } printf("All sent.\n"); close(sockfd); exit(0); }