home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
viscobv6.zip
/
vac22os2
/
ibmcobol
/
samples
/
toolkit
/
tcpiptk
/
socket
/
udpc.c
< prev
next >
Wrap
Text File
|
1996-11-19
|
3KB
|
82 lines
/********************************************************copyrite.xic********/
/* */
/* Licensed Materials - Property of IBM */
/* IBM TCP/IP for OS/2 */
/* (C) Copyright IBM Corporation. 1990,1991. */
/* */
/* All rights reserved. */
/* */
/* US Government Users Restricted Rights - */
/* Use, duplication or disclosure restricted by GSA ADP Schedule */
/* Contract with IBM Corp. */
/* */
/*--------------------------------------------------------------------------*/
/* */
/* DISCLAIMER OF WARRANTIES. The following [enclosed] code is */
/* sample code created by IBM Corporation. This sample code is not */
/* part of any standard or IBM product and is provided to you solely */
/* for the purpose of assisting you in the development of your */
/* applications. The code is provided "AS IS", without */
/* warranty of any kind. IBM shall not be liable for any damages */
/* arising out of your use of the sample code, even if they have been */
/* advised of the possibility of such damages. */
/*--------------------------------------------------------------------------*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <types.h>
#include <netinet/in.h>
#include <sys/socket.h>
main(int argc, char *argv[])
{
int s;
unsigned short port;
struct sockaddr_in server;
char buf[32];
/* argv[1] is internet address of server argv[2] is port of server.
* Convert the port from ascii to integer and then from host byte
* order to network byte order.
*/
if(argc != 3)
{
printf("Usage: %s <host address> <port> \n",argv[0]);
exit(1);
}
port = htons(atoi(argv[2]));
/* Initialize with sockets */
sock_init();
/* Create a datagram socket in the internet domain and use the
* default protocol (UDP).
*/
if ((s = socket(PF_INET, SOCK_DGRAM, 0)) < 0)
{
psock_errno("socket()");
exit(1);
}
/* Set up the server name */
server.sin_family = AF_INET; /* Internet Domain */
server.sin_port = port; /* Server Port */
server.sin_addr.s_addr = inet_addr(argv[1]); /* Server's Address */
strcpy(buf, "Hello");
/* Send the message in buf to the server */
if (sendto(s, buf, (strlen(buf)+1), 0, (struct sockaddr *)&server, sizeof(server)) < 0)
{
psock_errno("sendto()");
exit(2);
}
/* Deallocate the socket */
soclose(s);
}