| int main(int argc, char **argv) { |
| struct sockaddr_in saddr; |
| const struct linger nolinger = { .l_onoff = 1, .l_linger = 0 }; |
| "usage : %s <addr> <port> <string>\n" |
| " This will connect to TCP port <addr>:<port> and send string <string>\n" |
| " then immediately reset.\n", |
| sock = socket(AF_INET, SOCK_STREAM, 0); |
| bzero(&saddr, sizeof(saddr)); |
| saddr.sin_addr.s_addr = inet_addr(addr); |
| saddr.sin_port = htons(port); |
| saddr.sin_family = AF_INET; |
| if (connect(sock, (struct sockaddr *)&saddr, sizeof(saddr)) < 0) { |
| send(sock, argv[3], strlen(argv[3]), MSG_DONTWAIT | MSG_NOSIGNAL); |
| setsockopt(sock, SOL_SOCKET, SO_LINGER, (struct linger *) &nolinger, sizeof(struct linger)); |