/* attpsend.c */ /* Send a datagram without using a connected socket */ #include #include #include #include #include #include #include #include #include #include #include "copuser.h" #define REPS 125 char buf[1024*16]; struct sockaddr_in name; struct hostent *hp; char hnamebuf[80]; main( int argc, char **argv) { int i, me, you; unsigned char c; int sock; int status; long msglen; int msgcount; unsigned dummy; int one = 1; int rc = 0; sock = socket(AF_INET, SOCK_COP, IPPROTO_COP); if (sock < 0) { printf("Socket create failed \n"); exit(1); } hp = gethostbyname(argv[1]); if (hp == 0) { printf("Host %s not found\n", argv[1]); exit(1); } bcopy((char *)hp->h_addr, (char *)&name.sin_addr, hp->h_length); printf("Addr = "); for (i = 0; i < sizeof(dummy); i++) { c = *((char *)&name.sin_addr + i); printf(" %2x", c); } printf("\n"); setsockopt(sock, IPPROTO_COP, COP_FCD, &one, 4); name.sin_family = AF_INET; name.sin_port = htons(33456); if (argc > 2) name.sin_port = htons(atoi(argv[2])); else name.sin_port = htons(33456); rc = connect(sock, &name, sizeof(name)); if (rc < 0) { perror("connect error"); exit(1); } printf("connect returnd 0 \n"); while (msglen = read(0, buf, 100)) { status = sendto(sock, buf, msglen, 0, 0, 0); if (status != msglen) perror("send"); } }