UDP Socket question 
Author Message
 UDP Socket question

Hi guys,

The program is listening to the UDP socket. After receiving datagram it
it should
determine sender address, but it always is "0.0.0.0". If I sent datagram
using the same sockaddr_in structure, it goes to the localhost.
I use gcc 2.95 on Sparc Ultra5 with Solaris 2.6.

Part of code:
*********************************************
struct sockaddr_in from;
    ......

if ((len = recvfrom(fd, buf, size, 0, (struct sockaddr*) &from,
&addrLen)) < 0)
   {
     return -1;
   }
else
   {
     /* print 32-bit binary address in ascii format */
     printf("addr=%s\n", inet_ntoa(from.sin_addr));
      .....
   }
*********************************************
The same code works perfectly on Intel with RedHat6.1, so
it prints real address of the sender.
Did I make mistake somewhere, or is it Solaris feature?

Any help welcome!
Alex



Mon, 23 Sep 2002 03:00:00 GMT  
 UDP Socket question

Quote:
> if ((len = recvfrom(fd, buf, size, 0, (struct sockaddr*) &from,
> &addrLen)) < 0)
>    {
>      return -1;
>    }
> else
>    {
>      /* print 32-bit binary address in ascii format */
>      printf("addr=%s\n", inet_ntoa(from.sin_addr));
>       .....
>    }
> *********************************************
> The same code works perfectly on Intel with RedHat6.1, so
> it prints real address of the sender.
> Did I make mistake somewhere, or is it Solaris feature?

Did you initialize addrLen properly? It should be sizeof(struct sockaddr_in)

--

B-Lex Information Technologies

PGPKey: 2048/75929DC1     92 F1 6D A4 86 5A AE 50  CF 78 01 5B 18 94 18 40



Mon, 23 Sep 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. UDP Socket question

2. Help: UDP Socket question

3. Close a UDP socket

4. Q: Writing UDP Socket in C...

5. udp socket

6. UDP Datagram sockets

7. TCP/UDP sockets in Visual C++.

8. Broadcast over UDP socket

9. UDP socket and InstallShield???

10. Multihreading UDP Socket Server

11. UDP sockets - How to read data?

12. UDP Socket Win32 Help

 

 
Powered by phpBB® Forum Software