Re: ¿Problem in linux 2.4.3?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



For starters, you need to initialize your "peer" variable properly.

On Tue, 17 Apr 2001, Rafael MatíasHernández wrote:

> Hello. I have a problem running this code under linux 2.4.3: the
> "recv" function does not block, but instead returns "0". The same code
> under linux 2.2.19 will block until a datagram is received. I think
> the problem is in the shutdown code (although the socket is not
> connected). Any idea?
>
>
> #include <unistd.h>
> #include <stdio.h>
> #include <netinet/in.h>
> #include <sys/types.h>
> #include <sys/socket.h>
>
> int main(void)
> {
>     int so, so2, res;
>     struct sockaddr_in peer;
>     unsigned char buffer[1024];
>
>     so = socket(AF_INET, SOCK_DGRAM, 0);
>     memset(&peer, 0, sizeof(peer));
>     bind(so, &peer, sizeof(peer));
>
>     so2 = dup(so);
>     /* receive disallowed. Returns -1 = ENOTCONN */
>     /* Does shutdown refer both to so and so2? */
>     shutdown(so, 0);
>
>     /* Under linux 2.4.3 this will not block, and it will return 0
>        (success!).
>        Under 2.2.19, this will block */
>     res = recv(so2, buffer, sizeof(buffer), 0);
>     printf("Result = %d\n", res);
>     return 0;
> }
>
> /************** Under 2.4.3 */
> // socket(PF_INET, SOCK_DGRAM, IPPROTO_IP) = 3
> // bind(3, {sin_family=AF_UNSPEC, {sa_family=0, sa_data="\0\0\0\0\0\0\0\0\0\0\0\0\0\0"}, 16) = 0
> // dup(3)                                  = 4
> // shutdown(3, 0 /* receive */)            = -1 ENOTCONN (Transport endpoint is not connected)
> // recv(4, "", 1024, 0)                    = 0
>
> --
> Salu2
> -
> : send the line "unsubscribe linux-net" in
> the body of a message to majordomo@vger.kernel.org
>

-- 
Tuan Hoang
The MITRE Corporation
tuan@optimus.mitre.org


-
: send the line "unsubscribe linux-net" in
the body of a message to majordomo@vger.kernel.org


[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux 802.1Q VLAN]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Git]     [Bugtraq]     [Yosemite News and Information]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux PCI]     [Linux Admin]     [Samba]

  Powered by Linux