unable to recieve UDP packet

This is a discussion on unable to recieve UDP packet within the Networking/Device Communication forums, part of the General Programming Boards category; i have a basic udp program i'm unable to print out the payload. I'm not sure exactly why and was ...

  1. #1
    Registered User caroundw5h's Avatar
    Join Date
    Oct 2003
    Posts
    751

    unable to recieve UDP packet

    i have a basic udp program i'm unable to print out the payload. I'm not sure exactly why and was wondering if a new perspective would be able to help out. When the program runs the client sends and the server says its receiving but i can't print out the payload. any help would be appreciated as i'm sure it something suttle.
    forgive the barrage of code, but truthfully nothing complicated in it, thanks.
    Code:
    Client code:
    /*xrtp.c basic xrtp functions*/
    #include <xrtp\xrtp.h>
    #include <winsock.h>
    #include <stdlib.h>
    #include <stdio.h>
    
    int xrtp_init(xrtp_packet_t* packet,char *ipaddy,int port){
    /*clean out junk from the packet*/  
    memset(&packet,'\0', sizeof packet);
    
    /*initialize WinSock libraie(s) v2.2*/
    WSADATA start;
    if (WSAStartup(MAKEWORD(2,2),&start) !=0){
    printf("WinSock API not initalized");
    fflush(stdout); getchar();
    return -1;
     }
    
    /*create sockets for sending data to destination*/
    if ((xrtp_sendSocket=socket(PF_INET,SOCK_DGRAM,IPPROTO_UDP))==INVALID_SOCKET){
           printf("unable to create sending socket");fflush(stdout);
           getchar(); return -1; }
    
    if ((xrtp_recvSocket=socket(PF_INET,SOCK_DGRAM,IPPROTO_UDP))==INVALID_SOCKET){
           printf("unable to create sending socket");fflush(stdout);
           getchar(); return -1; }
       
    /* you can xrtp_init(0,0) and it'll default to local host: 4050 for testing*/;    
    if ( ipaddy == '\0') ipaddy = "127.0.0.1";
    if ( port == 0) port = 4950;
    
    /*capture the destination ip address to send to*/   
    xrtp_destStruct.sin_family = AF_INET;
    xrtp_destStruct.sin_port = htons(port);
    xrtp_destStruct.sin_addr.s_addr = inet_addr(ipaddy);
    memset(xrtp_destStruct.sin_zero,'\0',sizeof(xrtp_destStruct.sin_zero));
    
    /*let them know we here*/
    printf("XRTP client initialized on win32\n");
    return 0;
    }/*end of xrtp_init()*/
    
    /*assign rtp header info for the session*/
    size_t xrtp_header_init(xrtp_packet_t *rtp_packet){
    rtp_packet->Header.v=htons(2);/*version 2*/
    rtp_packet->Header.p=htons(0);/*no additional padding @ end of payload*/
    rtp_packet->Header.x=htons(0);/*payload type not followed by header extension*/
    rtp_packet->Header.cc=htons(0);/*no contributing sources for now*/
    rtp_packet->Header.m=htons(1);/* = 1 to indicate 1 frame of speex payload*/
    rtp_packet->Header.pt=htons(97);/*payload type is dynamic given by SDP*/
    rtp_packet->Header.sn=htons(345);/*sequence number has to increment in callback*/
    rtp_packet->Header.ts=htons(1230);/*time stamp to be incremented in callback = speex sample rate */
    rtp_packet->Header.ssrc=htons(0);/*no syncronization sources*/
    rtp_packet->Header.csrc=htons(0);/*no contirbuting sources*/
    return sizeof(rtp_packet->Header); 
    }
    
    size_t xrtp_marshall(xrtp_packet_t *packet,char *msg,size_t msg_len){
    /*serialiizes data from msg buffer xrtp_payload just to be sure or strncpy*/
    size_t msg_ndx,bytes_copied=0;
    
    for(msg_ndx=0;msg_ndx<msg_len;msg_ndx++){
     packet->payload[msg_ndx]= msg[msg_ndx];
      bytes_copied+=1;
      }
    /*if we count how many bytes may not need to delimit*/
    packet->payload[msg_ndx]='\0';
    return bytes_copied;
    }
       
    size_t send_xrtp_packet(xrtp_packet_t xrtppacket,size_t packet_len){
    /*pack the packet and send to its destination*/
    size_t bytes_sent = sendto(xrtp_sendSocket,(void*)&xrtppacket,packet_len,0,
    (struct sockaddr*)&xrtp_destStruct, sizeof (xrtp_destStruct) );
    /*comment out in production code: need acurate way to measure payload size*/
    printf("sending %d bytes to %s to port %d\n", bytes_sent,
    inet_ntoa(xrtp_destStruct.sin_addr),ntohs(xrtp_destStruct.sin_port));
    return bytes_sent;
    }
    
    size_t recv_xrtp_packet(xrtp_packet_t xrtpbuf,size_t b_len){
    /*recv needs a pointer to the size of the reciving struct*/
    size_t sender_s = sizeof (xrtp_recvStruct);
    /*get the packet put it to the xrtp buffer we have for it*/
    size_t bytes_recv=recvfrom(xrtp_recvSocket,(void*)&xrtpbuf,b_len,
    0,(struct sockaddr*)&xrtp_recvStruct, &sender_s);
    /*print statement saying how many bytes recv and from where*/
    return bytes_recv;
    }
    
    int xrtp_destroy(){
    /*are these still in the same namespace? should be we'll see log to file*/
    closesocket(xrtp_sendSocket); 
    closesocket(xrtp_recvSocket);
    WSACleanup(); getchar();
    return 0;
    }
    server code:
    Code:
    /* basic functions for the xrtp server_t that receives packetts*/
    #include <xrtp\xrtp_server.h>/*which also calls xrtp.h*/
    #include <stdio.h>
    #include <stdlib.h>
    #include <winsock.h>
    
    int xrtp_server_init(xrtp_packet_t* buffer,int port_num){
    /*clean out garbege in buffer*/
    memset(&buffer,'\0',sizeof buffer);
    
    /*initialize socket api and check to make sure version correct*/ 
    /*all these returns should be enumerated to mean something and logged*/   
    WSADATA info; 
    if (WSAStartup(MAKEWORD(2,2), &info) != 0){
    perror("Socket Startup:"); getchar();return -1; 
    }
        
    /*get host ip so can use for server ip for now*/
    memset(&xrtp_ServerhostInfo,0,sizeof (xrtp_ServerhostInfo) );
    char host[BUFSIZ];
    gethostname(host,BUFSIZ);//GET COMP NAME
    xrtp_ServerhostInfo = gethostbyname(host);//ERROR CHECK IN PROD CODE-GET IP
         
    /*zero out address structure if anything was still left there*/
    memset(&xrtp_serverRecvStruct,0,sizeof(xrtp_serverRecvStruct) );
    xrtp_serverRecvStruct.sin_family = AF_INET;
    xrtp_serverRecvStruct.sin_port = htons(port_num);
    memcpy(&xrtp_serverRecvStruct.sin_addr,xrtp_ServerhostInfo->h_addr,
    xrtp_ServerhostInfo->h_length);
    memset(xrtp_serverRecvStruct.sin_zero, '\0', sizeof(xrtp_serverRecvStruct.sin_zero));
        
     /*create a socket for binding and sending back to xrtp client*/
    if ((xrtp_serverSocket = socket(PF_INET, SOCK_DGRAM,IPPROTO_UDP))==INVALID_SOCKET){
    perror("socket"); return INVALID_SOCKET; }
    	
    /*bind the socket to the local address so now a server*/
    if (bind(xrtp_serverSocket, (struct sockaddr *)&xrtp_serverRecvStruct, 
    sizeof (xrtp_serverRecvStruct) ) == SOCKET_ERROR){
    perror("bind"); return SOCKET_ERROR; }
    	
    /*broadcast server ip*/
    printf("xrtp_server @ %s on port %d\n",inet_ntoa(xrtp_serverRecvStruct.sin_addr),
    ntohs(xrtp_serverRecvStruct.sin_port));
    return 0;
    }/*end of initializing the server*/
    
    /*recive the data from the client-how to know how much to recieve*/
    size_t xrtp_server_recv_to(xrtp_packet_t recvBuffer,size_t b_len){
    /*recv needs a pointer to the size of the reciving struct or internet struct*/
    size_t sendersIpstruct_s = sizeof (xrtp_sendersIpstruct);
    /*get the packet put it to the xrtp buffer we have for it and store senders IP*/
    size_t sender_bytes_recv=recvfrom(xrtp_serverSocket,(void*)&recvBuffer,b_len,
    /*now store senders unique ip in the recv struct we have for him*/
    0,(struct sockaddr*)&xrtp_sendersIpstruct, &sendersIpstruct_s);
    /*comment out later in production code*/
    printf("recieving: %d bytes from %s\n",
    sender_bytes_recv,inet_ntoa(xrtp_sendersIpstruct.sin_addr));
    return sender_bytes_recv;
    }
    /*converts packet header to hostbyte order*/
    size_t xrtp_header_convert(xrtp_packet_t *rtp_packet){
    /*(*rtp_packet).Header.v=ntohs(2))*/
    rtp_packet->Header.v=ntohs(2);/*version 2*/
    rtp_packet->Header.p=ntohs(0);/*no additional padding @ end of payload*/
    rtp_packet->Header.x=ntohs(0);/*payload type not followed by header extension*/
    rtp_packet->Header.cc=ntohs(0);/*no contributing sources for now*/
    rtp_packet->Header.m=ntohs(1);/* = 1 to indicate 1 frame of speex payload*/
    rtp_packet->Header.pt=ntohs(97);/*payload type is dynamic given by SDP*/
    rtp_packet->Header.sn=ntohs(125);/*sequence number has to increment in callback*/
    rtp_packet->Header.ts=ntohs(1230);/*time stamp to be incremented in callback = speex sample rate */
    rtp_packet->Header.ssrc=ntohs(0);/*no syncronization sources*/
    rtp_packet->Header.csrc=ntohs(0);/*no contirbuting sources*/ 
    }
    
    /*just clean up the servers mess not the client obvioulsy*/
    void xrtp_server_destroy(){
    closesocket(xrtp_serverSocket);
    WSACleanup();
    /*comment out in produxtion code*/
    printf("ENTER TO EXIT"); getchar();
    return;
    }
    how the server is called:
    Code:
    /*simple datagram server*/
    #include <xrtp/xrtp.h>
    #define MYPORT 4950
    
    int main(void){
    /*i'm thinking not recieving has something to do with the same xrtp_packet_t?*/
        xrtp_packet_t buff;
        xrtp_server_init(&buff,MYPORT);
    
        for(;;){
        xrtp_server_recv_to(buff,32 );
        xrtp_header_convert(&buff);
    /*prints out only garbege: we cleaned out the buffer in initialiazton so...
    and converted the header so we should be able to just print them out...*/
        printf("%d\t%s\n",buff.Header.sn,buff.payload);
        }
        /*never reached*/
        xrtp_server_destroy();
    }

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,499
    I was kinda expecting something with much better indentation....
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User caroundw5h's Avatar
    Join Date
    Oct 2003
    Posts
    751
    Quote Originally Posted by Salem View Post
    I was kinda expecting something with much better indentation....
    you mean for the server code? i think i have my compiler set to auto indent i'll try and take it off. otherwise the rest of the code looks alright to me. do you need any more information to maybe show me where i'm going wrong?

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,499
    Does your code posted here look the same as it does in your IDE ?

    Because code which is all indented at column 1 is simply too horrid to even look at, so I haven't even bothered to look at it.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Registered User caroundw5h's Avatar
    Join Date
    Oct 2003
    Posts
    751
    Quote Originally Posted by Salem View Post
    Does your code posted here look the same as it does in your IDE ?

    Because code which is all indented at column 1 is simply too horrid to even look at, so I haven't even bothered to look at it.
    the code looks the same in my ide. exactly the same. don't worry about looking over the code. someone else will or they won't.

  6. #6
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,499
    Well it's a good way to cut down on the number of people who might be able to help, but hey, it's your problem, not mine.
    Waste of time posting it IMO if you're going to make it so awful that nobody will touch it.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  7. #7
    Registered User caroundw5h's Avatar
    Join Date
    Oct 2003
    Posts
    751
    Quote Originally Posted by Salem View Post
    Well it's a good way to cut down on the number of people who might be able to help, but hey, it's your problem, not mine.
    Waste of time posting it IMO if you're going to make it so awful that nobody will touch it.
    and if more than one person complains then i'll be glad to do what i can for them. thanks for being the first.

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,650
    Your code needs to be properly indented.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  9. #9
    Registered User caroundw5h's Avatar
    Join Date
    Oct 2003
    Posts
    751
    Quote Originally Posted by laserlight View Post
    Your code needs to be properly indented.
    hmm..guess it must be pretty bad then. i've attached the indented server code. it simply waits and recieves a UDP packet. the server code says it is receiving the same amount of bytes the client says its sending however while i'm able to print out the payload member of the client i'm unable to do so with the server.
    Code:
    /* basic functions for the xrtp server_t that receives packets*/
    #include <xrtp\xrtp_server.h>/*which also calls xrtp.h*/
    #include <stdio.h>
    #include <stdlib.h>
    #include <winsock.h>
    
    int xrtp_server_init(xrtp_packet_t* buffer,int port_num){
    /*clean out garbege in buffer*/
      memset(&buffer,'\0',sizeof buffer);
    
    /*initialize socket api and check to make sure version correct*/ 
    /*all these returns should be enumerated to mean something and logged*/   
      WSADATA info; 
      if (WSAStartup(MAKEWORD(2,2), &info) != 0){
        perror("Socket Startup:"); getchar();
       return -1; 
      }
        
    /*get host ip so can use for server ip for now*/
    memset(&xrtp_ServerhostInfo,0,sizeof (xrtp_ServerhostInfo) );
    char host[BUFSIZ];
    gethostname(host,BUFSIZ);//GET COMP NAME
    xrtp_ServerhostInfo = gethostbyname(host);//ERROR CHECK IN PROD CODE-GET IP
         
    /*zero out address structure if anything was still left there*/
    memset(&xrtp_serverRecvStruct,0,sizeof(xrtp_serverRecvStruct) );
    xrtp_serverRecvStruct.sin_family = AF_INET;
    xrtp_serverRecvStruct.sin_port = htons(port_num);
    memcpy(&xrtp_serverRecvStruct.sin_addr,xrtp_ServerhostInfo->h_addr,
    xrtp_ServerhostInfo->h_length);
    memset(xrtp_serverRecvStruct.sin_zero, '\0', sizeof(xrtp_serverRecvStruct.sin_zero));
        
     /*create a socket for binding and sending back to xrtp client*/
    if ((xrtp_serverSocket = socket(PF_INET, SOCK_DGRAM,IPPROTO_UDP))==INVALID_SOCKET){
      perror("socket"); return INVALID_SOCKET; }
    	
    /*bind the socket to the local address so now a server*/
    if (bind(xrtp_serverSocket, (struct sockaddr *)&xrtp_serverRecvStruct, 
      sizeof (xrtp_serverRecvStruct) ) == SOCKET_ERROR){
      perror("bind"); 
      return SOCKET_ERROR; 
    }
    	
    /*broadcast server ip*/
    printf("xrtp_server @ %s on port %d\n",inet_ntoa(xrtp_serverRecvStruct.sin_addr),
      ntohs(xrtp_serverRecvStruct.sin_port));
      return 0;
    }/*end of initializing the server*/
    
    /*recive the data from the client-how to know how much to recieve*/
    size_t xrtp_server_recv_to(xrtp_packet_t recvBuffer,size_t b_len){
    /*recv needs a pointer to the size of the reciving struct or internet struct*/
      size_t sendersIpstruct_s = sizeof (xrtp_sendersIpstruct);
    /*get the packet put it to the xrtp buffer we have for it and store senders IP*/
      size_t sender_bytes_recv=recvfrom(xrtp_serverSocket,(void*)&recvBuffer,b_len,
    /*now store senders unique ip in the recv struct we have for him*/
       0,(struct sockaddr*)&xrtp_sendersIpstruct, &sendersIpstruct_s);
    /*comment out later in production code*/
      printf("recieving: %d bytes from %s\n",
       sender_bytes_recv,inet_ntoa(xrtp_sendersIpstruct.sin_addr));
    return sender_bytes_recv;
    }
    /*converts packet header to hostbyte order*/
    size_t xrtp_header_convert(xrtp_packet_t *rtp_packet){
    /*(*rtp_packet).Header.v=ntohs(2))*/
      rtp_packet->Header.v=ntohs(2);/*version 2*/
      rtp_packet->Header.p=ntohs(0);/*no additional padding @ end of payload*/
      rtp_packet->Header.x=ntohs(0);/*payload type not followed by header extension*/
      rtp_packet->Header.cc=ntohs(0);/*no contributing sources for now*/
      rtp_packet->Header.m=ntohs(1);/* = 1 to indicate 1 frame of speex payload*/
      rtp_packet->Header.pt=ntohs(97);/*payload type is dynamic given by SDP*/
      rtp_packet->Header.sn=ntohs(125);/*sequence number has to increment in callback*/
      rtp_packet->Header.ts=ntohs(1230);/*time stamp to be incremented in callback = speex sample rate */
      rtp_packet->Header.ssrc=ntohs(0);/*no syncronization sources*/
      rtp_packet->Header.csrc=ntohs(0);/*no contirbuting sources*/ 
    }
    
    /*just clean up the servers mess not the client obvioulsy*/
    void xrtp_server_destroy(){
      closesocket(xrtp_serverSocket);
      WSACleanup();
    /*comment out in produxtion code*/
      printf("ENTER TO EXIT"); 
      getchar();
      return;
    }

  10. #10
    Registered User caroundw5h's Avatar
    Join Date
    Oct 2003
    Posts
    751
    This is the receive function for the server. if anyone has any ideas. thanks.
    Code:
    size_t xrtp_server_recv_to(xrtp_packet_t recvBuffer,size_t b_len){
    
        size_t sendersIpstruct_s = sizeof (xrtp_sendersIpstruct);
    
        size_t sender_bytes_recv=recvfrom(xrtp_serverSocket,(void*)&recvBuffer,b_len,
           0,(struct sockaddr*)&xrtp_sendersIpstruct, &sendersIpstruct_s);
    
        printf("recieving: %d bytes from %s\n",
           sender_bytes_recv,inet_ntoa(xrtp_sendersIpstruct.sin_addr));
    
    return sender_bytes_recv;
    }

  11. #11
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,682
    The function itself looks alright to me. But need to make sure that you have read any data. Check the return value of the recvfrom function. And make sure it is more than 0. i mean the received buffer size.

    ssharish
    Last edited by ssharish2005; 09-17-2007 at 06:11 PM.

  12. #12
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,703
    // size_t xrtp_server_recv_to(xrtp_packet_t recvBuffer,size_t b_len)

    could it be that you're passing recvBuffer by value? and in case you haven't already done so, you should specify an alignment for xrtp_packet_t so that no matter what compiler is used, the structure has all of it's members in the same place. ie:

    Code:
    #pragma pack(push, 1)
    struct xrtp_packet_t{...};
    #pragma pack(pop)
    Code:
    bool flip(bool value)
    {
        return std::pow(std::exp(1), std::complex<float>(0, 1) 
        * std::complex<float>(std::atan(1)*(1 << (value + 2))))
        .real() < 0;
    }

  13. #13
    Registered User caroundw5h's Avatar
    Join Date
    Oct 2003
    Posts
    751
    Thank you both for responding, this issue has been plaguing me now for awhile.

    The function itself looks alright to me. But need to make sure that you have read any data. Check the return value of the recvfrom function. And make sure it is more than 0. i mean the received buffer size.
    the client sends 33bytes and the server says it is receiving the same amount of bytes. however i checked the received buffer size and it tells me it is 1616 bytes. that is the regualar size of the xrtp_packet_t. The 16 bytes is the constant header size for the packet, but the 1600 bytes is the max payload length for the payload. i would have expected after receiving the recvfrom buffer would now be the size of the exact bytes from the send function. the header is defined as follows.
    Code:
    /*packet size == 65,535B so rtp header size plus payload size*/
    #define buffer_len 1600/*speex wb_mode encodes max how much?*/
    
    typedef struct{
    #ifndef __WIN32 /*if big endian format: not really true but for now*/
      unsigned short v: 2;/*rtp version*/
      unsigned short p: 1; /*rtp padding*/
      unsigned short x: 1;/*extension bit*/
      unsigned short cc: 4;/*csrc count*/
      unsigned short m: 1;/*marker bit*/
      unsigned short pt: 7;/*payload type*/
    
    #else /*else little endian - compiler puts bits different why?*/
      unsigned short cc: 4;/*csrc count*/
      unsigned short x: 1;/*extension bit*/
      unsigned short p: 1; /*rtp padding*/
      unsigned short v: 2;/*rtp version*/
      unsigned short pt: 7;/*payload type*/
      unsigned short m: 1;/*marker bit*/
    #endif 
    
    /*all endians get the remaining bit format*/
      unsigned short sn: 16;/*sequence number-xxx*/
      unsigned int ts: 32;/*time stamp-xxxx*/
      unsigned int ssrc: 32;/*synchronization source-xxxx*/
      unsigned int csrc: 32;/*contributing sources max 15-xxxx*/
    }rtp_hdr;
    
    /*multiplex xrtp packet type can easily extend later*/
    typedef struct{
      rtp_hdr Header;
      char payload[buffer_len];
    }xrtp_packet_t;

    could it be that you're passing recvBuffer by value?
    recvBuffer is passed to the function however in the recvfrom function it takes the address of the buffer to manipulate. i could be wrong but i believe it is able to change the buffer thus inside of the function.

    Code:
    size_t recv_xrtp_packet(xrtp_packet_t xrtpbuf,size_t b_len){
      size_t sender_s = sizeof (xrtp_recvStruct);
      size_t bytes_recv=recvfrom(xrtp_recvSocket,(void*)&xrtpbuf,b_len,
         0,(struct sockaddr*)&xrtp_recvStruct, &sender_s);
    return bytes_recv;
    }
    and in case you haven't already done so, you should specify an alignment for xrtp_packet_t so that no matter what compiler is used, the structure has all of it's members in the same place. ie:
    now thats the interesting part, because the the header part member of the packet contains a bit field this is what i was wondering was happening. I will
    check out the pragma directive, however, in declaring the xrtp_packet_t i took into consideration the compiler would want to make sure everything was aligned and how windows byte order was - being little endian. thus the original packet is supposed to be defined thus
    Code:
    typedef struct{
      unsigned short v: 2;/*rtp version*/
      unsigned short p: 1; /*rtp padding*/
      unsigned short x: 1;/*extension bit*/
      unsigned short cc: 4;/*csrc count*/
      unsigned short m: 1;/*marker bit*/
      unsigned short pt: 7;/*payload type*/
      unsigned short sn: 16;/*sequence number-xxx*/
      unsigned int ts: 32;/*time stamp-xxxx*/
      unsigned int ssrc: 32;/*synchronization source-xxxx*/
      unsigned int csrc: 32;/*contributing sources max 15-xxxx*/
    }rtp_hdr;
    are you telling me that if i use the pragma directive
    Code:
    #pragma pack(push, 1)
    struct xrtp_packet_t{...};
    #pragma pack(pop)
    and define the struct as above, it will be sent that exact same way across the network?

  14. #14
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,703
    >> recvBuffer is passed to the function however in the recvfrom function it takes the address of the buffer to manipulate. i could be wrong but i believe it is able to change the buffer thus inside of the function.

    that's incorrect. the variable passed to recv_xrtp_packet is a copy of the packet you passed to it, and so the changes will be made to the copy, not the original packet.

    >> and define the struct as above, it will be sent that exact same way across the network?

    it won't have an effect on byte ordering (it looks like xrtp_header_convert takes care of that though), but it will ensure that across compilers, the internal padding of the structure is the same.
    Code:
    bool flip(bool value)
    {
        return std::pow(std::exp(1), std::complex<float>(0, 1) 
        * std::complex<float>(std::atan(1)*(1 << (value + 2))))
        .real() < 0;
    }

  15. #15
    Registered User caroundw5h's Avatar
    Join Date
    Oct 2003
    Posts
    751
    that's incorrect. the variable passed to recv_xrtp_packet is a copy of the packet you passed to it, and so the changes will be made to the copy, not the original packet.
    that would have seemed to be the trouble but changing the function to accept a (xrtp_packet_t *) still seems to have the buffer only receive
    gibberish.
    Code:
    /*receive and store data from the client of b_len*/
    size_t xrtp_server_recv_to(xrtp_packet_t *recvBuffer,size_t b_len){
    
      size_t sendersIpstruct_s = sizeof (xrtp_sendersIpstruct);
    
      size_t sender_bytes_recv=recvfrom(xrtp_serverSocket,(void*)&recvBuffer,b_len,
       0,(struct sockaddr*)&xrtp_sendersIpstruct, &sendersIpstruct_s);
    
      printf("recieving: &#37;d bytes from %s\n",sender_bytes_recv,
        inet_ntoa(xrtp_sendersIpstruct.sin_addr));
    
    return sender_bytes_recv;
    }
    i may be having trouble understanding my send function?
    Last edited by caroundw5h; 09-19-2007 at 08:59 AM. Reason: still not working.
    Warning: Opinions subject to change without notice

    The C Library Reference Guide
    Understand the fundamentals
    Then have some more fun

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 05-05-2009, 05:35 AM
  2. Global Variables
    By Taka in forum C Programming
    Replies: 34
    Last Post: 11-02-2007, 03:25 AM
  3. Raw Packet (sorry tripple weird Post)
    By Coder87C in forum Networking/Device Communication
    Replies: 6
    Last Post: 03-04-2006, 10:34 AM
  4. Traceroute using UDP and ICMP
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 08-09-2002, 07:09 PM
  5. Traceroute using UDP + ICMP
    By Unregistered in forum Windows Programming
    Replies: 0
    Last Post: 08-05-2002, 10:50 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21