home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tolkit45.zip / os2tk45 / samples / tcpiptk / sendfile / sendfile.c < prev    next >
C/C++ Source or Header  |  1999-05-11  |  4KB  |  99 lines

  1. /********************************************************copyrite.xic********/
  2. /*                                                                          */
  3. /*   Licensed Materials - Property of IBM                                   */
  4. /*   IBM TCP/IP for OS/2                                                    */
  5. /*   (C) Copyright IBM Corporation. 1990,1996.                              */
  6. /*                                                                          */
  7. /*   All rights reserved.                                                   */
  8. /*                                                                          */
  9. /*   US Government Users Restricted Rights -                                */
  10. /*   Use, duplication or disclosure restricted by GSA ADP Schedule          */
  11. /*   Contract with IBM Corp.                                                */
  12. /*                                                                          */
  13. /*--------------------------------------------------------------------------*/
  14. /*  DISCLAIMER OF WARRANTIES.  The following [enclosed] code is             */
  15. /*  sample code created by IBM Corporation. This sample code is not         */
  16. /*  part of any standard or IBM product and is provided to you solely       */
  17. /*  for  the purpose of assisting you in the development of your            */
  18. /*  applications.  The code is provided "AS IS", without                    */
  19. /*  warranty of any kind.  IBM shall not be liable for any damages          */
  20. /*  arising out of your use of the sample code, even if they have been      */
  21. /*  advised of the possibility of such damages.                             */
  22. /*--------------------------------------------------------------------------*/
  23. /************************* TCP CLIENT****************************************/
  24.  
  25. #define MSG_CLOSE 0x800
  26. #define O_RDONLY  0x4
  27.  
  28. #include <string.h>
  29. #include <stdio.h>
  30. #include <types.h>
  31. #include <sys\socket.h>
  32. #include <netinet\in.h>
  33. #include <netinet\tcp.h>
  34. #include <arpa\inet.h>
  35. #include <io.h>
  36.  
  37. char  serveraddress[128],filename[256];
  38. int   serverport ;
  39. int   fd,rc,s;
  40.  
  41. struct sf_parms sfp;
  42.  
  43. int putfile (void);
  44.  
  45. int main (int argc, char *argv[])
  46. {
  47.  if(argc<4)
  48.    {
  49.      printf(" usage %s: <ip_addr> <port> <filename> \n",argv[0]);
  50.      exit(0);
  51.    }
  52.  strcpy (serveraddress, argv[1]);   /* argv[1] is server address to which file is to be sent */
  53.  serverport = atoi(argv[2]);        /* argv[2] is server port */
  54.  strcpy (filename, argv[3]);        /* argv[3] is name of the file to be sent */
  55.  
  56.  printf ("Sending File to server\n");
  57.    if ((rc = putfile()) != 0)
  58.         {
  59.           printf ("Putfile() failed rc = %d sock_errno = %d \n", rc, sock_errno());
  60.             return(rc);
  61.         }
  62. }
  63.  
  64. int putfile()
  65. {
  66.     struct sockaddr_in servername;
  67.  
  68.     if( (s = socket (PF_INET, SOCK_STREAM, 0)) != -1 )
  69.     {
  70.       servername.sin_len         = sizeof(servername);
  71.       servername.sin_family      = AF_INET;
  72.       servername.sin_addr.s_addr = inet_addr(serveraddress);
  73.       servername.sin_port        = serverport;
  74.  
  75.     if((rc = connect(s,(struct sockaddr *)&servername,sizeof(servername))) != -1)
  76.        {
  77.             fd =open(filename,O_RDONLY,0);
  78.             sfp.header_data   = 0;
  79.             sfp.header_length = 0;
  80.             sfp.file_handle   = fd;
  81.             sfp.file_size     = -1;
  82.             sfp.file_offset   = 0;
  83.             sfp.file_bytes    = -1;
  84.             sfp.trailer_data  = 0;
  85.             sfp.trailer_length= 0;
  86.             sfp.bytes_sent    = 0;
  87.  
  88.           if(( rc = send_file(&s,&sfp,MSG_CLOSE)) != 0)
  89.                 printf( " ******  FILE NOT SENT  ****** ");
  90.             close(fd);
  91.        }
  92.       else
  93.         printf ("send_file :connect() failed sock_errno = %d \n",sock_errno());
  94.     }
  95.     else
  96.       printf ("send_file :socket() failed rc = %d\n", sock_errno());
  97.    return(rc);
  98. }
  99.