home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / viscobv6.zip / vac22os2 / ibmcobol / samples / toolkit / tcpiptk / socket / msgc.c < prev    next >
Text File  |  1996-11-19  |  4KB  |  107 lines

  1. /********************************************************copyrite.xic********/
  2. /*                                                                          */
  3. /*   Licensed Materials - Property of IBM                                   */
  4. /*   IBM TCP/IP for OS/2                                                    */
  5. /*   (C) Copyright IBM Corporation. 1990,1991.                              */
  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. /*                                                                          */
  15. /*  DISCLAIMER OF WARRANTIES.  The following [enclosed] code is             */
  16. /*  sample code created by IBM Corporation. This sample code is not         */
  17. /*  part of any standard or IBM product and is provided to you solely       */
  18. /*  for  the purpose of assisting you in the development of your            */
  19. /*  applications.  The code is provided "AS IS", without                    */
  20. /*  warranty of any kind.  IBM shall not be liable for any damages          */
  21. /*  arising out of your use of the sample code, even if they have been      */
  22. /*  advised of the possibility of such damages.                             */
  23. /*--------------------------------------------------------------------------*/
  24. #include <stdio.h>
  25. #include <stdlib.h>
  26. #include <string.h>
  27. #include <types.h>
  28. #include <netinet/in.h>
  29. #include <sys/socket.h>
  30.  
  31. main(int argc, char *argv[])
  32. {
  33.  
  34.  
  35.    int s,bytesend;
  36.    unsigned short port;
  37.    struct sockaddr_in server;
  38.    struct msghdr msg;
  39.    struct iovec iov[5];
  40.    char buf[64],buf1[64],buf2[64],buf3[64],buf4[64];
  41.  
  42.    /* argv[1] is internet address of server argv[2] is port of server.
  43.     * Convert the port from ascii to integer and then from host byte
  44.     * order to network byte order.
  45.     */
  46.    if(argc != 3)
  47.    {
  48.       printf("Usage: %s <host address> <port> \n",argv[0]);
  49.       exit(1);
  50.    }
  51.    port = htons(atoi(argv[2]));
  52.  
  53.    /* Initialize with sockets */
  54.    sock_init();
  55.  
  56.    /* Create a datagram socket in the internet domain and use the
  57.     * default protocol (UDP).
  58.     */
  59.    if ((s = socket(PF_INET, SOCK_DGRAM, 0)) < 0)
  60.    {
  61.        psock_errno("socket()");
  62.        exit(1);
  63.    }
  64.  
  65.    /* Set up the server name */
  66.    server.sin_family      = AF_INET;            /* Internet Domain    */
  67.    server.sin_port        = port;               /* Server Port        */
  68.    server.sin_addr.s_addr = inet_addr(argv[1]); /* Server's Address   */
  69.  
  70.    strcpy(buf, "Hello, I am Gaurang Shah");
  71.    strcpy(buf1, "Hello *1*, I am William R. SNOW");
  72.    strcpy(buf2, "Hello *2*, I am James Willam");
  73.    strcpy(buf3, "Hello *3*, I am GLENN STUMP");
  74.    strcpy(buf4, "Hello *4*, I am paul seifert");
  75.  
  76.    iov[0].iov_base = &buf[0];
  77.    iov[0].iov_len = sizeof(buf);
  78.    iov[1].iov_base = &buf1[0];
  79.    iov[1].iov_len = sizeof(buf1);
  80.    iov[2].iov_base = &buf2[0];
  81.    iov[2].iov_len = sizeof(buf2);
  82.    iov[3].iov_base = &buf3[0];
  83.    iov[3].iov_len = sizeof(buf3);
  84.    iov[4].iov_base = &buf4[0];
  85.    iov[4].iov_len = sizeof(buf4);
  86.  
  87.    msg.msg_name = (caddr_t) &server;
  88.    msg.msg_namelen = sizeof(server);
  89.  
  90.    msg.msg_iov = &iov[0];
  91.    msg.msg_iovlen = 5;
  92.  
  93.    msg.msg_accrights = 0;
  94.    msg.msg_accrightslen= 0;
  95.  
  96.    /* Send the message in buf to the server */
  97.  
  98.    if ((bytesend=sendmsg(s, &msg, 0)) < 0)
  99.     {
  100.         psock_errno("sendmsg()");
  101.         exit(2);
  102.     }
  103.  
  104.    /* Deallocate the socket */
  105.    soclose(s);
  106. }
  107.