The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Special Forums > IP Networking
Google UNIX.COM


IP Networking Questions involving TCP/IP, Routers, Hubs, Network protocols, etc go here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Invalid Argument and glassfish Andrew2008 SUN Solaris 1 04-30-2008 12:25 PM
msgrcv : Invalid argument answers UNIX for Dummies Questions & Answers 1 02-08-2008 06:31 AM
error "Invalid argument" returned after call sched_setscheduler robin.zhu High Level Programming 1 07-26-2007 12:51 AM
ps: 65535 is an invalid non-numeric argument for -p option gogogo SUN Solaris 5 11-19-2006 02:20 PM
stty: : Invalid argument tony3101 Shell Programming and Scripting 2 03-16-2006 02:33 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-16-2008
Registered User
 

Join Date: Apr 2008
Posts: 30
sendto invalid argument

Hi

I lost a lot of time in understanding the message "sendto Invalid argument" when I execute the following code.
This code is a simple UDP sender improved with some reliability feature.
My goal is to send a file. I've reported only the code which may be useful.
Can anyone help me?
Thank you in advance.



Code:
typedef struct{
  char* filename;
  unsigned long encoded_file_size;
}first_message;


typedef struct {
     char data[DATALENGTH];
     int nseq;
}packet; 






ssize_t send_first(int sd, void* buf,size_t len,char* err,const struct sockaddr* to);


int main (int argc, char** argv){

  FILE* fin;
  first_message fm;
  int sd; 
  struct sockaddr_in dest;
  
  unsigned long length, file_size,chunk_size;
  time_t end,start;
  double internal; 
  packet pck;

  if (argc != 3) {
    fprintf(stderr,"Usage: IPdestination path \n");
   exit(EXEC_FAILED);
}

  memset((char *)&dest, 0, sizeof(dest));
  dest.sin_family = AF_INET;
  dest.sin_port = htons(PORT);
  dest.sin_addr.s_addr = inet_addr(argv[1]); /*destination's address*/
 
  if ((sd = socket(AF_INET,SOCK_DGRAM,0))<0) {
  perror("socket creation failed");
  exit(EXEC_FAILED);
  }
  fin = fopen(argv[2],"rb");
  if (fin != NULL){
      
      fm.filename = find_fileName(argv[2]);
      fm.encoded_file_size = htonl(get_file_size(fin));
       printf("sizeof(fm) %ld",sizeof(fm));    

/*HERE THE ERROR*/

      while (send_first(sd,&fm,sizeof(fm),"unable to send first message",(struct sockaddr*)&dest)<0){
      send_first(sd,&fm,2*sizeof(fm),"unable to send first message",(struct sockaddr*)&dest);}
  
.....
}  /*end of main*/

ssize_t send_first(int sd, void* buf,size_t len,char* err, const struct sockaddr* to){
 
 unsigned long byte_sent;
 if(byte_sent = sendto(sd, buf, len, 0, to, sizeof(to))<0){
      perror(err); }
 sleep(TIMEOUT);
 if(fcntl(sd,F_SETFL,O_NONBLOCK)==-1){
    perror("Impossible to set NONBLOCK mode for the socket");
 }     
 return recvfrom(sd, buf,len,0,NULL,NULL);
}
Reply With Quote
Google The UNIX and Linux Forums
Forum Sponsor
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 03:41 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0