[comp.protocols.tcp-ip] BSD getsockname

TAYBENGH@NUSDISCS.BITNET (11/28/90)

Hi,
        Hi, did anybody try to use BSD getsockname() b4? I tried very hard
and cannot get it to work. It alswyas return -1, giving t_errno = 4, saying
that socket operation on Non-socket. However, the same program I try it
on Vax and Sun-3/Sun-4, all of them are working properly. I need this
routine to tell what is actual port number return after binding the sock
with port number 0.
        Thanks a lot.

- Beng Hang Tay (email: taybengh@nusdiscs.bitnet)

TAYBENGH@NUSDISCS.BITNET (11/29/90)

     I received two responses and some further query on this topic. Thanks
for the responses. I apologize for not being clear on some aspects. I re-post
this coz I have not found any solution yet. Below are the response:

From: mni@techops.cray.com (Michael Nittmann)
Message-Id: <9011271706.AA26409@techops.cray.com>
Subject: Re:  BSD getsockname() is broken in WIN/TCP for 3B4000???

>Hi,
>so on what machine does it NOT work?

 As the title suggested, the machine is an AT&T 3B4000 multiprocessor
(I think it is under 3B2 family). The TCP is an WIN product for 3B series.

>Maybe you have a wild horse of a machine that has a broken view of
>file systems and sockets. Are you on a localhost connection?
>Is your socket may be a UNIX domain socket (some broken implementations
>implicit unix domain for localhost sockets) and can your machine

 The domain of the socket is AF_INET, NOT AF_UNIX. I am aware of the problem
of the UNIX domain scoket.

>(better it's system programmers) find no other kernel hook than an
>inode (this case the kernel thinks your socket is a file and may if
>broken give up too soon when you want to have the socket's address
>structure back).

 could u please tell me how check on it?

>Maybe also your error number is wrong and you did not specify
>for namelength how much buffer you allocated?

 I am using perror(), am I missing any thing?

>Sounds like you should scrap that machine.

 I hope so if I have the the say on it. I am just an user/programmer,
not a decision maker.

From: "Michael J. Saletnik - Local Unix Wizard's Apprentice"
 <icarus@jupiter.end.tufts.edu>
Subject: Re:  BSD getsockname() is broken in WIN/TCP for 3B4000???
To: TAYBENGH@NUSDISCS.BITNET
Message-id: <9011271616.AA01750@jupiter.end.tufts.edu>

>What exactly are you trying to do?

        I am actually writing higher-level Inter-machine-communication
interfaces based on socket. One of the routine is socket creation which is:

        int inet_crt(protype, local_port)
        int protype;            /* protocol type */
        u_short *local_port;    /* local port number, if 0 is given, it
                                   will give a unique port number and
                                   assigned to local_port */
        {

           int  id,
                len;
           struct       sockaddr_in     local_sock;

           if ((id = socket(AF_INET, protype, 0)) < 0)
              inet_err("inet_crt(): socket()")

           .......

           /*
            * bind the socket
            */
          if (bind(id, &local_sock, sizeof(local_sock)) < 0)
             inet_err("inet_crt(): bind()")

           /*
            * get the actual port number assigned
            */
           len = sizeof(local_sock);
->         if (getsockname(id, &local_sock, &len))
->             inet_err("inet_crt(): getsockname()")
->Remark:  getsockname() works in both Sun-3 and Sun-4 (SunOS 4.0 & 4.1).
->         However, it did not work on TCP/IP WIN/3B for an AT&T3B4000!!!
->         WHY???
           *local_port = ntohs(local_sock.sin_port);
           return(sock);
        }

>If you have a sockaddr_in structure associated with the socket, which you
>should
>   ,
>after the bind look at

>struct sockaddr_in fubar;
>unsigned long port;
>port = fubar.sin_port;

>If I'm totally clueless as to what you're doing, possibly a more detailed
>description or a code fragment....

        Well, I did tried using your method b4, but it simply return 0 :-(.
Before bind(), the port=0; After bind(); I tried to print out the port number,
it is still 0 at both Sun-4 and AT&T machines. That's mean the bind() did not
modify the struct sockaddr_in. Am I rite?

        Thanks. Hope to hear from all of you soon.

- Beng Hang Tay (email: taybengh@nusdiscs)