problem with recvfrom

From: Omega (Omega_at_NO_SPAM.pl)
Date: 11/21/05

  • Next message: Andrew Falanga: "Re: A curious problem with make"
    Date: Mon, 21 Nov 2005 21:17:50 +0000 (UTC)
    
    

    I have a problem with recvfrom(). I get a message and no error occurs,
    but the struct sockaddr* from is not filled with sender's data.

    The client's source code:

    #include "reversi.h"
    -------------------------------------------------------------------
    int main() {
    int socket_id = socket(PF_INET,SOCK_DGRAM,0);
    struct sockaddr_in adres;
    adres.sin_family = PF_INET;
    adres.sin_port = htons(PORT_NR);
    adres.sin_addr.s_addr = inet_addr("127.0.0.1");
    cli_msg msg;
    msg.type = CMT_LOGIN;
    sendto(socket_id,&msg,sizeof(cli_msg),0,(struct sockaddr*)&adres,sizeof
    (struct sockaddr));
    printf("wyslalem na 127.0.0.1\n");
    ser_main_msg ser_msg;
    unsigned int rozmiar;
    recvfrom(socket_id,&ser_msg,sizeof(ser_main_msg),0,(struct sockaddr*)
    &adres,&rozmiar);
    printf("otrzymalem cos a adresu %s",inet_ntoa(adres.sin_addr));
    printf("type = %d\n",ser_msg.type);
    return 1;
    }
    -------------------------------------------------------------------
    All needed header files are included in reversi.h

    Server is rather long, but the inportant part is, the socket is datagram
    socket:
    -------------------------------------------------------------------
    bzero(&klient1, sizeof(struct sockaddr_in));
    int ret = recvfrom(sockid,&msg_kli1,sizeof(cli_msg),0,(struct sockaddr*)
    &klient1,&rozmiar1);
            printf("received %s, %d, %d\n",inet_ntoa(klient1.sin_addr), ret,
    errno);
          if (msg_kli1.type == CMT_LOGIN) {
            msg.type = SMMT_WAIT;
            sendto(sockid,&msg,sizeof(ser_main_msg),0,(struct sockaddr*)
    &klient1,rozmiar1);
            printf("send SMMT_WAIT to address %s\n",inet_ntoa
    (klient1.sin_addr));
            kli_nr++;
    -------------------------------------------------------------------
    serwer should print:
    received 127.0.0.1, 16, 0
    send SMMT_WAIT to addrress 127.0.0.1

    but it prints:
    reveived 0.0.0.0., 16, 0
    send SMMT_WAIT to address 0.0.0.0

    It happens only when I run the program on my computer, when I tried on
    friends computer problem doesn't occur. Any ideas?

    Omega


  • Next message: Andrew Falanga: "Re: A curious problem with make"

    Relevant Pages

    • problem with recvfrom
      ... but the struct sockaddr* from is not filled with sender's data. ... int main{ ... friends computer problem doesn't occur. ...
      (comp.os.linux.networking)
    • problem with recvfrom
      ... but the struct sockaddr* from is not filled with sender's data. ... int main{ ... friends computer problem doesn't occur. ...
      (comp.os.linux.development.apps)
    • Re: [PATCH] sctp: prevent reading out-of-bounds memory
      ... addr_buf = kaddrs; ... we already validate that we have the proper amount of space for a given sockaddr. ... as sockaddr structs, without checking if the dereferenced struct ... int addrcnt = 0; ...
      (Linux-Kernel)
    • Re: [PATCH] sctp: prevent reading out-of-bounds memory
      ... as sockaddr structs, without checking if the dereferenced struct ... members fall beyond the end of the allocated chunk. ... int addrcnt = 0; ...
      (Linux-Kernel)
    • Re: Linux 2.6.27.8
      ... struct pt_regs *regs); ... static int printbinary ... void show_regs ...
      (Linux-Kernel)