tar@ksuvax1.cis.ksu.edu (Tim Ramsey) (02/13/89)
I'm trying to write a function that will connect two sockets together. This piece of code creates a socket, returning its file descriptor: struct in_addr host_addr; /* Initialized to 0's */ makesock() { int sock; struct sockaddr_in name; if ((sock = socket(AF_INET, SOCK_STREAM, 0)) == -1) { perror("socket"); exit(1); } name.sin_addr = host_addr; name.sin_port = 0; if (bind(sock, &name, sizeof (name)) == -1) { perror("bind"); exit(1); } return (sock); } This piece of code is *supposed* to connect the two sockets created by makesock() together: attach(one, two) int one, two; { struct sockaddr_in name; int length; length = sizeof (name); if (getsockname(one, &name, &length) == -1) { perror("getsockname one"); exit(1); } if (connect(two, &name, length) == -1) { perror("connect two"); exit(1); } [ reverse one and two, repeat ] } The connect fails with the error EADDRNOTAVAIL ("Can't assign requested address"). What am I doing wrong? Disclaimer: I'm not using socketpair(2) because this implementation forgot to include it, even though it's listed in the manual. I'm using SysV Rel2.1.2 with WIN/3B TCP/IP 1.1. Thanks for any help or pointers you can provide. Tim -- Timothy Ramsey BITNET: tar@KSUVAX1 Internet: tar@ksuvax1.cis.ksu.edu UUCP: ...!rutgers!ksuvax1!tar