/* acopbind.c */ /* Test of port bind capability */ #include #include #include #include #include #include #include char buf[16 * 1024]; struct sockaddr_in name; struct sockaddr_in sname; int namelen; char hnamebuf[80]; #include "copuser.h" main( int argc, char** argv) { int i, me, you; unsigned char c; int sock; int netaddr; int status; unsigned dummy; int msgcount; /* Create datagram socket */ sock = socket(AF_INET, SOCK_COP, IPPROTO_COP); if (sock < 0) { printf("Socket create failed \n"); exit(1); } /* Fill in protocol family and port # from command line then */ /* bind the socket to the specified address. */ name.sin_family = AF_INET; if (argc > 1) name.sin_port = htons(atoi(argv[1])); else name.sin_port = htons(33456); status = bind(sock, (struct sockaddr *)&name, sizeof(name)); printf("Bind status = %d\n", status); if (status < 0) { perror("bind error"); exit(1); } status = listen(sock, 1); printf("Listen status = %d\n", status); if (status < 0) { perror("listen error"); exit(1); } sleep(10); printf("closing \n"); }