/* I want to write programs for OS/2 in C. I want to use OpenWatcom v2 * as a compiler and I want to compile the code on Linux. * * By default, OpenWatcom v2 links against TCPIP32.DLL, which is not * present in default installations of OS/2 Warp 3 or 4. Those only come * with SO32DLL.DLL and TCP32DLL.DLL, i.e. an older 16 Bit TCP/IP stack. * I do want to use that older stack, though, because I want to stay * close to the "original" Warp 3 and 4 versions and want to avoid * having to install all kinds of additional stuff. * * OpenWatcom does not include the headers nor LIB files for that older * stack. * * As a workaround, I used files from the OS/2 Toolkit 4.5. * * Step 1: Acquire IBM OS/2 DEVELOPER'S TOOLKIT VERSION 4.5.2. * Step 2: Replace backslashes with slashes in include directives, e.g. * replace * #include * with: * #include * This applies to all files in the directory "h/stack16" in the * TK. * * Then compile as follows: * * export INCLUDE=/path/to/os2tk45/h/stack16:/opt/watcom/h:/opt/watcom/h/os2 * owcc -Wall -Wextra -std=c99 -bos2v2 \ * -o test.exe connect-tk45-stack16.c \ * /path/to/os2tk45/lib/so32dll.lib /path/to/os2tk45/lib/tcp32dll.lib * * This places the TK headers before OpenWatcom's own headers and uses * the TK LIB files for linking. * * The resulting EXE file works on Warp 3 and 4, but this whole process * feels quite wonky. */ /* OpenWatcom headers */ #include #include #include #include /* OS/2 TK 4.5 headers */ /* sockaddr, sockaddr_in, socket(), AF_INET, SOCK_STREAM, htons(), * select(), send(), recv() */ #include /* gethostbyname() */ #include int main(int argc, char **argv) { int s, ret; struct sockaddr_in sa = {0}; char buf[4096], *msg; struct hostent *he; if (argc < 3) { fprintf(stderr, "Usage: %s \n", argv[0]); exit(EXIT_FAILURE); } he = gethostbyname(argv[1]); if (he == NULL) { perror("gethostbyname()"); exit(EXIT_FAILURE); } s = socket(AF_INET, SOCK_STREAM, 0); if (s == -1) { perror("socket()"); exit(EXIT_FAILURE); } sa.sin_family = AF_INET; sa.sin_addr.s_addr = *((unsigned long *)he->h_addr); sa.sin_port = htons(atoi(argv[2])); if (connect(s, (struct sockaddr *)&sa, sizeof sa) == -1) { perror("connect()"); exit(EXIT_FAILURE); } msg = "GET / HTTP/1.0\r\n"; send(s, msg, strlen(msg), 0); msg = "Host: "; send(s, msg, strlen(msg), 0); send(s, argv[1], strlen(argv[1]), 0); msg = "\r\n\r\n"; send(s, msg, strlen(msg), 0); while ((ret = recv(s, buf, sizeof buf, 0)) > 0) write(STDOUT_FILENO, buf, ret); soclose(s); exit(EXIT_SUCCESS); }