Keyboard Shortcuts
ctrl + shift + ? :
Show all keyboard shortcuts
ctrl + g :
Navigate to a group
ctrl + shift + f :
Find
ctrl + / :
Quick actions
esc to dismiss
Likes
Search
server programming in "C"
OK well here is the sample program from my system in file?$WCC:WATC.SOCK.SAMPLE... (Note: this will not compile because there are character set errors) ... but you can see some things missing from your sample program that seem to be in mine... ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? ? ? /com ** Sample Waterloo C sockets program. ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? /com ** See the comment about DNS servers below. ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? /com ** Tests functions: connect(), send(), recv(), muresolve(), ? ? ? ? ? ? ? /com ** ? musa2e(), muse2a() ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? /inc watc ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? ? ? #include <socket.h> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? ? ? #include <stdio.h> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #include <string.h> ? /* for memset(), etc. */ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #include <stdlib.h> ? /* for exit() */ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #include <errno.h> ? ?/* for access to errno */ ? ? ? ? ? ? ? ? ? ? ? ? ?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? ? ? /* prototype for local function */ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? static void crlf2nl(unsigned char *buf, int len); ? ? ? ? ? ? ? ? ? ? ? ?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? ? ? int main(void) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? ? ? int i,n,rc,wlen; ? ? ? ? ? int sd; ?/* socket descriptor */ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? ? ? unsigned long ipaddr; ?/* 32-bit IP address */ ? ? ? ? ? ? ? ? ? ? ? ? ?? ? ? unsigned char *sitename=""; ?/* site to connect to */ ? ? ? ? unsigned char *ipnum="132.206.120.4"; ?/* numeric IP addr to use ? ? ? ?? ? ? ? ? ? ? ? ? ? ? ? ? if sitename cannot be resolved by DNS */ ? ? ? ? ? ?? ? ? int port=80; ? /* port number to connect to */ ? ? ? ? ? ? ? ? ? ? ? ? ?? ? ? struct sockaddr_in saddr; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? int numreads,totbytes; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? ? ? unsigned char *wrdata= ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? ? ? ? ?"GET /msi/http/music.html HTTP/1.0\r\x25\r\x25"; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? /* HTML request, to send to a web server. ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Note use of \r\x25 for CRLF. WatC Ebcdic: 0x0D 0x25. ? ? ? ? ? ? ? ? ? ? ? ? ?muse2a() and etoa() translate it to Ascii CR LF = 0x0D 0x0A. ? ? ? ? ? ? ? */ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? ? ? unsigned char lastch,buf?400¨; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? printf("\nWatC sockets sample program\n\n"); ? ? ? ? ? ? ? ? ? ? ? ? ? ?? ? ? /* Resolve the site name to an IP address */ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? /* Note: The muresolve functions uses a DNS server to lookup the ? ? ? ? ? ? ? ?IP address for the given site name (domain name).? This requires ? ?? ? ? ? ?that you have 1 or more DNS server IP addresses defined in ? ? ? ? ?? ? ? ? ?your $tcp:tcpip.config file, as NAMESERV records. ? ? ? ? ? ? ? ? ? ? ? ? ? ?Normally the DNS (Domain Name System) server IP addresses are ? ? ? ? ? ? ? ?provided by your ISP (Internet Service Provider). ? ? ? ? ? ? ? ? ? ? ? ? ? ?If you don't have any DNS servers, you can add the following ? ? ? ?? ? ? ? ?record to file $tcp:ip.alias : ? 132.206.120.4 ? ? ?? ? ? ? ?Or, in this source file, set: ?sitename="132.206.120.4" ? ? ? ? ? ? ? ? ? */ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? printf("Resolving site name %s\n",sitename); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? rc=muresolve(sitename,&ipaddr); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? ? ? if(rc<0) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? { printf("** Error: unable to resolve site name %s\n" ? ? ? ? ? ? ? ?? ? ? ? ? ? ? ? ?" ? ? muresolve() gave rc=%d\n",sitename,rc); ? ? ? ? ? ? ? ? ? ? ? ? printf("** Using a specific numeric IP address instead: %s\n", ? ? ? ? ? ? ? ? ? ? ?ipnum); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? ? ? ? ? ipaddr=inet_addr(ipnum); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? ? ? ? } ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? sd=socket(AF_INET,SOCK_STREAM,0); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? printf("sd=%d from socket() create\n",sd); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? ? ? if(sd<0) { printf("** errno=%d\n",errno); exit(1); } ? ? ? ? ? ? ? ? ? ?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? /* Set up the socket address structure for connect() */ ? ? ? ? ? ? ? ? ? ? ? memset(&saddr,0,sizeof(saddr)); ?/* init. it to 0 */ ? ? ? ? ? ? ? ? ? ?? ? ? saddr.sin_family=AF_INET; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? saddr.sin_port=htons((unsigned short)port); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? saddr.sin_addr.s_addr=ipaddr; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? printf("Connecting to %s %s port %d\n",sitename, ? ? ? ? ? ? ? ? ? ? ? ?? ? ? ? ? ? ?inet_ntoa(saddr.sin_addr),port); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? rc=connect(sd,(struct sockaddr *)&saddr,sizeof(saddr)); ? ? ? ? ? ? ? ? ? ? ? printf("rc=%d from connect()\n",rc); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? ? ? if(rc<0) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? { printf("** errno=%d\n",errno); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? if(errno==ECONNREFUSED) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? ? ? ? ? ? ? printf(" ? ?ECONNREFUSED - Connection refused\n"); ? ? ? ? ? ? ? ? ? ? ? if(errno==EHOSTUNREACH) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? ? ? ? ? ? ? printf(" ? ?EHOSTUNREACH - Host unreachable\n"); ? ? ? ? ? ? ? ? ? ? ? ? exit(1); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? ? ? /* Write data to the socket */ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? wlen=strlen(wrdata); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? printf("# of bytes to be written: wlen=%d\ndata=|%s|\n",wlen,wrdata); ?? ? ? muse2a(wrdata,wlen); ?/* convert from Ebcdic to Ascii! */ ? ? ? ? ? ? ?? ? ? n=send(sd,wrdata,wlen,0); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? ? ? if(n<0) printf("** rc=%d from send(). errno=%d\n",n,errno); ? ? ? ? ? ?? ? ? else printf(" %d bytes written to socket\n",n); ? ? ? ? ? ? ? ? ? ? ? ?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? ? ? /* Loop to read from the socket and display the data */ ? ? ? ? ? ? ? ?? ? ? if(rc<0) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? { printf("** errno=%d\n",errno); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? if(errno==ECONNREFUSED) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? ? ? ? ? ? ? printf(" ? ?ECONNREFUSED - Connection refused\n"); ? ? ? ? ? ? ? ? ? ? ? if(errno==EHOSTUNREACH) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? ? ? ? ? ? ? printf(" ? ?EHOSTUNREACH - Host unreachable\n"); ? ? ? ? ? ? ? ? ? ? ? ? exit(1); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? /* Write data to the socket */ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? wlen=strlen(wrdata); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? printf("# of bytes to be written: wlen=%d\ndata=|%s|\n",wlen,wrdata); ?? ? ? muse2a(wrdata,wlen); ?/* convert from Ebcdic to Ascii! */ ? ? ? ? ? ? ?? ? ? n=send(sd,wrdata,wlen,0); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? ? ? if(n<0) printf("** rc=%d from send(). errno=%d\n",n,errno); ? ? ? ? ? ?? ? ? else printf(" %d bytes written to socket\n",n); ? ? ? ? ? ? ? ? ? ? ? ?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? ? ? /* Loop to read from the socket and display the data */ ? ? ? ? ? ? ? ?? ? ? rc=close(sd); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? ? ? printf("rc=%d from close() of socket\n",rc); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? if(rc<0) { printf("** errno=%d\n",errno); exit(1); } ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? ? ? return 0; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? ? ? } ?/* end of main */ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? ? ? /* ---------------------------------------------------------------- */ ?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? static void crlf2nl(unsigned char *buf, int len) ? ? ? ? ? ? ? ? ? ? ? ? ? ? /* Change all Ebcdic CRLF pairs to (blank,\n) */ ? ? ? ? ? ? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? ? ? int i,n1; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? ? ? unsigned char ebc_crlf?2¨={0x0D,0x25}; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? unsigned char blknl?2¨={' ','\n'}; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? ? ? if(len<2) return; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? ? ? n1=len-1; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? ? ? for(i=0;i<n1;i++) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? ? ? ? { if(memcmp(buf+i,ebc_crlf,2)==0) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? ? ? ? ? ? { memcpy(buf+i,blknl,2); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? i++; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? ? ? ? } ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? ? ? } ?/* end of crlf2nl */ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? ? ? /inc $tcp:watc.sockets.obj ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? /inc $tcp:watc.muresolv.obj ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? Joe On Mon, Jun 21, 2021 at 2:50 PM Tom Chandler <tchandler48@...> wrote:
|
/com ** Sample Waterloo C sockets program. /com ** See the comment about DNS servers below. /com ** Tests functions: connect(), send(), recv(), muresolve(), /com ** ? musa2e(), muse2a() /inc watc #include <stdio.h> #include <string.h> ? /* for memset(), etc. */ #include <stdlib.h> ? /* for exit() */ #include <errno.h> ? ?/* for access to errno */ /* prototype for local function */ static void crlf2nl(unsigned char *buf, int len); int main(void) { int i,n,rc,wlen; int sd; ? ?/* socket descriptor */ unsigned long ipaddr; ?/* 32-bit IP address */ unsigned char *sitename=""; ?/* site to connect to */ unsigned char *ipnum="132.206.120.4"; ?/* numeric IP addr to use ? ? ? ? ? ? ? ? ? ? if sitename cannot be resolved by DNS */ int port=80; ? ?/* port number to connect to */ struct sockaddr_in saddr; int numreads,totbytes; unsigned char *wrdata= \ ? ? "GET /msi/http/music.html HTTP/1.0\r\x25\r\x25"; ? ? ? ?/* HTML request, to send to a web server. ? ? ? ? ? Note use of \r\x25 for CRLF. WatC Ebcdic: 0x0D 0x25. ? ? ? ? ? muse2a() and etoa() translate it to Ascii CR LF = 0x0D 0x0A. ? ? ? ?*/ unsigned char lastch,buf[400]; printf("\nWatC sockets sample program\n\n"); /* Resolve the site name to an IP address */ /* Note: The muresolve functions uses a DNS server to lookup the ? ?IP address for the given site name (domain name).? This requires ? ?that you have 1 or more DNS server IP addresses defined in ? ?your $tcp:tcpip.config file, as NAMESERV records. ? ?Normally the DNS (Domain Name System) server IP addresses are ? ?provided by your ISP (Internet Service Provider). ? ?If you don't have any DNS servers, you can add the following ? ?record to file $tcp:ip.alias : ? 132.206.120.4 ? ?Or, in this source file, set: ?sitename="132.206.120.4" */ rc = muresolve(sitename,&ipaddr); if(rc < 0) ? { ? ? ? ? ? printf("** Error: unable to resolve site name %s\n" ? ? ? ? ? ?" ? ? muresolve() gave rc=%d\n",sitename,rc); ? ? ? printf("** Using a specific numeric IP address instead: %s\n", ? ? ? ? ? ?ipnum); ? ? ?ipaddr=inet_addr(ipnum); ? } sd = socket(AF_INET,SOCK_STREAM,0); printf("sd = %d from socket() create\n",sd); if(sd < 0) ? ? ? ?{ ? ? ? ? ? printf("** errno=%d\n",errno); exit(1); ? ? ? ?} /* Set up the socket address structure for connect() */ memset(&saddr,0,sizeof(saddr)); ?/* init. it to 0 */ saddr.sin_family=AF_INET; saddr.sin_port=htons((unsigned short)port); saddr.sin_addr.s_addr=ipaddr; printf("Connecting to %s %s port %d\n",sitename, \ ? ? ? ?inet_ntoa(saddr.sin_addr),port); rc = connect(sd,(struct sockaddr *)&saddr,sizeof(saddr)); printf("rc=%d from connect()\n",rc); if(rc<0) ? { printf("** errno=%d\n",errno); ? ? if(errno==ECONNREFUSED) ? ? ? ? printf(" ? ?ECONNREFUSED - Connection refused\n"); ? ? if(errno==EHOSTUNREACH) ? ? ? ? printf(" ? ?EHOSTUNREACH - Host unreachable\n"); ? ? exit(1); ? } /* Write data to the socket */ wlen=strlen(wrdata); printf("# of bytes to be written: wlen=%d\ndata=|%s|\n",wlen,wrdata); muse2a(wrdata,wlen); ?/* convert from Ebcdic to Ascii! */ n=send(sd,wrdata,wlen,0); if(n<0) printf("** rc=%d from send(). errno=%d\n",n,errno); else printf(" %d bytes written to socket\n",n); /* Loop to read from the socket and display the data */ printf("Reading from socket...\n"); for(numreads=0,totbytes=0,lastch=0;;) ? { numreads++; ? ? n=recv(sd,buf,sizeof(buf),0); ? ? if(n<0) { printf("** rc=%d from recv(). errno=%d\n",n,errno); ? ? ? ? ? ? ? break; } ? ? if(n==0) break; ?/* end of data, server shutdown socket */ ? ? totbytes+=n; ? ? musa2e(buf,n); ?/* convert from Ascii to Ebcdic! */ ? ? crlf2nl(buf,n); ?/* then change all CRLF to (blank,\n) */ ? ? ? ? /* Fix for case of CRLF split between buffers: */ ? ? ? ? if(lastch==0x0D && buf[0]==0x25) buf[0]='\n'; ? ? ? ? lastch=buf[n-1]; ? ? ? ? if(lastch==0x0D) buf[n-1]=' '; ? ? for(i=0;i<n;i++) putc(buf[i],stdout); ? } printf(" numreads=%d totbytes=%d\n",numreads,totbytes); rc=close(sd); printf("rc=%d from close() of socket\n",rc); if(rc<0) { printf("** errno=%d\n",errno); exit(1); } return 0; } ? /* end of main */ /* ---------------------------------------------------------------- */ static void crlf2nl(unsigned char *buf, int len) /* Change all Ebcdic CRLF pairs to (blank,\n) */ { int i,n1; unsigned char ebc_crlf[2]={0x0D,0x25}; unsigned char blknl[2]={' ','\n'}; if(len<2) return; n1=len-1; for(i=0;i<n1;i++) ? { if(memcmp(buf+i,ebc_crlf,2)==0) ? ? ? { memcpy(buf+i,blknl,2); ? ? ? ? i++; ? ? ? } ? } } ?/* end of crlf2nl */ On Mon, Jun 21, 2021 at 12:48 PM Joe Monk <joemonk64@...> wrote:
|
Ok do me a favor ... copy/paste the sample program in a reply to this email. joe On Mon, Jun 21, 2021 at 12:24 PM Tom Chandler <tchandler48@...> wrote:
|
toggle quoted message
Show quoted text
On Mon, Jun 21, 2021 at 12:12 PM Joe Monk <joemonk64@...> wrote:
|
Ok first ... remember the manuals were written for Music 5.1. You are running Music/SP 6.2. Look at the sample program. It should show everything you need. Joe On Mon, Jun 21, 2021 at 11:24 AM Tom Chandler <tchandler48@...> wrote:
|
I will try the change, but I found this, now to figure out how,what,when....Ok. In a FORTRAN program, you might use something like this: /FILE SUBLIB PDS(*OS,*MUS) I don't know if this would work in a C program or if you need something different in that environment. Bear in mind that the available documentation may be appropriate for C/370 or something else that is not WATC. Regards, Peter Coghlan. |
I will try the change, but I found this, now to figure out how,what,when.... ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? This subroutine is intended for C programmers calling TCP/IP socket ? ? ? ? ? routines.? When called before the first socket routine, it guarantees that ? the arguments are passed in the manner C requires. ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? CALLING SEQUENCE: ?CALL CARGCALL(); ? ? ? ?? I think I am not linking to the correct MUSIC/SP library. Got to learn more about compile time libraries. The above was found in? the help menu, system subroutines. Still working on it. Cheers Tom c ? ? ? ? ? ? ? ? ? ? ?? On Mon, Jun 21, 2021 at 11:13 AM Peter Coghlan <groups@...> wrote: > |
In that case, you probably need something more complex than adding an &. Maybe something like this: int family = AF_INET; int type = SOCK_STREAM; int zero = 0; sock = socket (&family, &type, &zero); Regards, Peter Coghlan. |
Sir, The change did not compile, something about a LVALUE needed.? BUT, I think you are on the right track.? See below from ar_pf3 manual: **** If you wish to code socket application in C, you must include a call to CARGENV (no parameters required) in order to cause the socket routines to automatically convert the arguments passed to assembler calling conventions. In this case, use the normal C calling conventions as defined by the SOCKET.HDR header file. **** It appears that cargenv converts arguments from a "C" to something else.? Still digging.? WIll look at the debugger to see what can be done. Thank you very much for your help and interest. Cheers Tom c On Mon, Jun 21, 2021 at 10:40 AM Peter Coghlan <groups@...> wrote: > |
When you say hangs, do you mean hangs waiting for something or hangs stuck in an infinte loop? This is a complete wild guess. Maybe CARGENV causes arguments passed by value to socket routines to be somehow changed into arguments passed by reference? How about trying something like this as a test: sock = socket (&AF_INET, &SOCK_STREAM, &0); and see if it still hangs? Maybe the MUSIC debugger could be used to get more details on what is going wrong? It might even be possible to figure out in what way the arguments being passed to socket() from C are "wrong" which might in turn allow a replacement for CARGENV to be written? Regards, Peter Coghlan. |
Sir, That may true, but in WATC on music/sp, it is not defined in the socket.h file, Cheers Tom c On Mon, Jun 21, 2021 at 9:14 AM Joe Monk <joemonk64@...> wrote:
|
IP_PROTO_TCP is defined in ip.h Joe On Mon, Jun 21, 2021 at 9:01 AM Tom Chandler <tchandler48@...> wrote:
|
Sir, Gave it a try, but it fails in the compile as
IP_PROTO_TCP reports as undefined. Cheers Tom c On Sun, Jun 20, 2021 at 7:22 PM Christian Robert via <christian.robert=[email protected]> wrote: On 2021-06-20 19:00, Tom Chandler wrote: |
Sir, for testing, I run a sim390 and a Hercules version.? The Hercules is SPINHAWK, using the modifications by Peter Coghlan.? It allows MUSIC/SP tcpip access while running under Hercules.? The ftp & http server work great.? Have been using it for over a year now. The reason I usd sim390 and Hercules is to help validate Peter's modification are working as expected. Cheers Tom? c. On Sun, Jun 20, 2021 at 7:29 PM Joe Monk <joemonk64@...> wrote:
|
The reason I ask is this, from the readme.txt in the musdemo_b download: "You can also run the MUSIC/SP Demo system under the Hercules mainframe emulator, but in that case none of the tcp/ip applications in MUSIC/SP can be used, such as FTP, FTPD, HTTPD, socket programming, etc." Joe On Sun, Jun 20, 2021 at 7:27 PM Joe Monk via <joemonk64=[email protected]> wrote:
|
Are you running under hercules or Sim390? Joe On Sun, Jun 20, 2021 at 6:00 PM Tom Chandler <tchandler48@...> wrote:
|
On 2021-06-20 19:00, Tom Chandler wrote:
Thank you for your reply.? I had included the following:I would use sock = socket (AF_INET, SOCK_STREAM, IP_PROTO_TCP); or something like that. I can't help you more because I didn't manage to make TCPIP available yet in my Hercules. Not sure if it's possible. Xtian. <> Virus-free. www.avg.com <> |
Thank you for the reference.? I thought it look familiar as I had a pdf, hardcopy, and text version.? Re-read it to make sure, but with no luck. Cheers Tom c On Sun, Jun 20, 2021 at 4:36 PM Joe Monk <joemonk64@...> wrote:
|
Thank you for your reply.? I had included the following: /inc $tcp:watc.sockets.obj /inc $tcp:watc.muresolv.obj /inc $tcp:watc.mugetsoc.obj with no change.? The program hangs on the: sock = socket (AF_INET, SOCK_STREAM, 0); code. Cheers Tom c. On Sun, Jun 20, 2021 at 5:08 PM Christian Robert via <christian.robert=[email protected]> wrote: I think that if you link your program with $TCP:WATC.SOCKETS.OBJ |
I think that if you link your program with $TCP:WATC.SOCKETS.OBJ
toggle quoted message
Show quoted text
you will not have to call anything special. my 2 cents, Xtian. On 2021-06-20 15:27, Tom Chandler wrote:
I am trying to port over a server program in "C", to MUSIC/SP using WATC?? In the AR guide, part-3 |
to navigate to use esc to dismiss