Sponsored Content
Full Discussion: sendto invalid argument
Special Forums IP Networking sendto invalid argument Post 302205682 by Puntino on Monday 16th of June 2008 05:06:08 AM
Old 06-16-2008
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);
}

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

stty: : Invalid argument

Hello Everyone; I have a script that is throwing the following message: stty: : Invalid argument The line that gives the message is the following, sailormoon$ scp home/voice.xml newwave@silvermoon:/newwave/config/radius stty: : Invalid argument voice.xml | ... (2 Replies)
Discussion started by: tony3101
2 Replies

2. Solaris

ps: 65535 is an invalid non-numeric argument for -p option

I want to figure out what is the reason of error message I have in Solaris 10. Why Solaris 10 dosn't recognize 65535? ps: 65535 is an invalid non-numeric argument for -p option usage: ps 'format' is one or more of: Thank you (5 Replies)
Discussion started by: gogogo
5 Replies

3. Programming

error "Invalid argument" returned after call sched_setscheduler

the code is below and the was run on Solaris 9. ----------------------------- struct sched_param param; param.sched_priority = 99; if(sched_setscheduler(0, SCHED_RR, &param) == -1) { perror("setting priority"); exit(1); } ------------------------------- after the... (1 Reply)
Discussion started by: robin.zhu
1 Replies

4. UNIX for Dummies Questions & Answers

msgrcv : Invalid argument

Hi All, Please guide me how to get rid : msgrcv : Invalid argument. I am using message queues: msgsnd and msgrcv, I am able to send through msgsnd and receive through msgrcv, but at times i get the belo error. msgrcv : Invalid argument. (1 Reply)
Discussion started by: answers
1 Replies

5. Solaris

Invalid Argument and glassfish

I tried to install glassfish on Solaris 10 and it worked fine on other instances. I got the below message bash-3.00# ./sjsas-9_1_01-solaris-sparc.bin -console bash: ./sjsas-9_1_01-solaris-sparc.bin: Invalid argument I logged on as root and the file has execute permission. So strange. Do... (1 Reply)
Discussion started by: Andrew2008
1 Replies

6. UNIX for Dummies Questions & Answers

Need FIX for: RTNETLINK answers: Invalid argument

OK...I'm using the latest version of Fedora 10. My network connection was working fine, and I had several network LAN shares on my desktop. Then I rebooted the system without dismounting those shares first. ooops. <:( ...When the system came back up, my network connection was gone. All... (2 Replies)
Discussion started by: Pudnik
2 Replies

7. UNIX for Advanced & Expert Users

invalid argument in semctl()

When I am using the function semctl() it is giving me error as the INVALID ARGUMENT. Can any body give me the possible reasons??? (2 Replies)
Discussion started by: asimibm
2 Replies

8. Programming

SIOCSARP: Invalid Argument.

Hello everybody, I've been programming an alternative to linux's standard 'arp' program. I can delete arp entries (SIOCDARP), get arp entries (SIOCGARP), but i'm having troubles setting entries with ioctl. I can't set any PERM, USETRAILERS, or COM address. It only adds PUB entries and i don't... (2 Replies)
Discussion started by: semash!
2 Replies

9. UNIX for Advanced & Expert Users

NFS : Invalid argument (Remote share mounting issue)

Hi Guru's, I am unable to mount NFS share on unix system (DG/UX) which is nfs client. Error: mount: /nfsshare: Invalid argument mount: giving up on: /mountpoint i tried following command mount -t nfs remotehost:/nfsshare /mountpoint Error: (5 Replies)
Discussion started by: Justin John
5 Replies

10. UNIX for Beginners Questions & Answers

Mount error in Linux: invalid argument

hi i have an android phone which i think is bricked, so wanted to see what the actual issue is, I flashed it with TWRP recovery image and launched terminal i, was able understand that mount is not happening, it says invalid argument and no such file or directory. Below is what i get while... (32 Replies)
Discussion started by: nanz143
32 Replies
STRCAT(3)						     Linux Programmer's Manual							 STRCAT(3)

NAME
strcat, strncat - concatenate two strings SYNOPSIS
#include <string.h> char *strcat(char *dest, const char *src); char *strncat(char *dest, const char *src, size_t n); DESCRIPTION
The strcat() function appends the src string to the dest string, overwriting the terminating null byte ('') at the end of dest, and then adds a terminating null byte. The strings may not overlap, and the dest string must have enough space for the result. If dest is not large enough, program behavior is unpredictable; buffer overruns are a favorite avenue for attacking secure programs. The strncat() function is similar, except that * it will use at most n bytes from src; and * src does not need to be null-terminated if it contains n or more bytes. As with strcat(), the resulting string in dest is always null-terminated. If src contains n or more bytes, strncat() writes n+1 bytes to dest (n from src plus the terminating null byte). Therefore, the size of dest must be at least strlen(dest)+n+1. A simple implementation of strncat() might be: char * strncat(char *dest, const char *src, size_t n) { size_t dest_len = strlen(dest); size_t i; for (i = 0 ; i < n && src[i] != '' ; i++) dest[dest_len + i] = src[i]; dest[dest_len + i] = ''; return dest; } RETURN VALUE
The strcat() and strncat() functions return a pointer to the resulting string dest. ATTRIBUTES
For an explanation of the terms used in this section, see attributes(7). +--------------------+---------------+---------+ |Interface | Attribute | Value | +--------------------+---------------+---------+ |strcat(), strncat() | Thread safety | MT-Safe | +--------------------+---------------+---------+ CONFORMING TO
POSIX.1-2001, POSIX.1-2008, C89, C99, SVr4, 4.3BSD. NOTES
Some systems (the BSDs, Solaris, and others) provide the following function: size_t strlcat(char *dest, const char *src, size_t size); This function appends the null-terminated string src to the string dest, copying at most size-strlen(dest)-1 from src, and adds a terminat- ing null byte to the result, unless size is less than strlen(dest). This function fixes the buffer overrun problem of strcat(), but the caller must still handle the possibility of data loss if size is too small. The function returns the length of the string strlcat() tried to create; if the return value is greater than or equal to size, data loss occurred. If data loss matters, the caller must either check the arguments before the call, or test the function return value. strlcat() is not present in glibc and is not standardized by POSIX, but is available on Linux via the libbsd library. EXAMPLE
Because strcat() and strncat() must find the null byte that terminates the string dest using a search that starts at the beginning of the string, the execution time of these functions scales according to the length of the string dest. This can be demonstrated by running the program below. (If the goal is to concatenate many strings to one target, then manually copying the bytes from each source string while maintaining a pointer to the end of the target string will provide better performance.) Program source #include <string.h> #include <time.h> #include <stdio.h> int main(int argc, char *argv[]) { #define LIM 4000000 int j; char p[LIM]; time_t base; base = time(NULL); p[0] = ''; for (j = 0; j < LIM; j++) { if ((j % 10000) == 0) printf("%d %ld ", j, (long) (time(NULL) - base)); strcat(p, "a"); } } SEE ALSO
bcopy(3), memccpy(3), memcpy(3), strcpy(3), string(3), strncpy(3), wcscat(3), wcsncat(3) COLOPHON
This page is part of release 4.15 of the Linux man-pages project. A description of the project, information about reporting bugs, and the latest version of this page, can be found at https://www.kernel.org/doc/man-pages/. GNU
2017-09-15 STRCAT(3)
All times are GMT -4. The time now is 07:07 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy