#pragma module TCPIP$SCTP_CLIENT "V5.7-00" /* ** BUILD ENVIRONMENT: ** ** If the current version of DECC does not suport SCTP, then you must ** manually configure the environment as follows: ** ** $ define netinet tcpip$examples ** ** BUILD INSTRUCTIONS: ** ** $ cc tcpip$sctp_client ** $ link tcpip$sctp_client ** ** SYNTAX: ** ** sctp_client [port] ** ** EXAMPLE: ** ** Define a foreign symbol to point at the application. ** ** $ sctp_client :== $TCPIP$EXAMPLES:tcpip$sctp_client ** $ sctp_client myserver */ #define _SOCKADDR_LEN #include #include #include #ifndef __VMS #include #else #include #endif typedef unsigned int socklen_t; /* usually defined in socket.h */ #include #include #include #include #include /* SCTP */ #ifndef IPPROTO_SCTP #define IPPROTO_SCTP 132 /* SCTP */ #endif #define DEF_PORT 55555 #define SA(x) ((struct sockaddr *)x) int main(int argc, char *argv[]) { int sd; int count = 0, cc; struct sockaddr_in peer; int peerlen = sizeof(peer); char peername[INET6_ADDRSTRLEN]; char *hostname; int port; in_addr_t in_addr; struct hostent *hent; char line[128]; if(argc == 1) {printf("Usage: client [port]\n"); return 1;} hostname = argv[1]; if(argc == 3) port = atoi(argv[2]); else port = DEF_PORT; /* convert hostname string to in_addr_t */ in_addr = inet_addr(hostname); /* first try dotted decimal notation? */ if(in_addr == (in_addr_t)-1) { hent = gethostbyname(hostname); /* now try DNS */ if(hent == NULL) {printf("No host information for %s\n", hostname); return 1;} in_addr = *(int *)hent->h_addr; } /* setup the local address that we will connect to */ peer.sin_len = sizeof(peer); peer.sin_family = AF_INET; peer.sin_port = htons(port); peer.sin_addr.s_addr = in_addr; /* create an SCTP socket */ sd = socket(AF_INET, SOCK_STREAM, IPPROTO_SCTP); if(sd == -1) {perror("socket"); return 1;} /* connect to server */ if(connect(sd, SA(&peer), peerlen) == -1) {perror("connect"); return 1;} printf("Connected to: %s:%d\n", inet_ntop(AF_INET, &peer.sin_addr.s_addr, &peername[0], sizeof(peername)), ntohs(peer.sin_port)); /* write loop */ do { printf("Enter a line to send:"); if(scanf("%[^\n]%*c", line) == -1) {perror("scanf"); return 1;} cc = write(sd, line, strlen(line)); if(cc == -1) {perror("send"); return(1);} } while(cc != -1 && line[0] != 'Q'); if(close(sd) == -1) {perror("close"); return 1;} return 0; }