50 #define PROG_DESC "REXX function package for tcp/ip sockets"
51 #define PROG_COPY "(c) Copyright International Business Machines Corporation 1993, 2004"
52 #define PROG_COPY1 "(c) Copyright Rexx Language Association 2005-2014"
53 #define PROG_ALRRa "All Rights Reserved."
54 #define PROG_ALRRb "This program and the accompanying materials"
55 #define PROG_ALRRc "are made available under the terms of the Common Public License v1.0"
59 #define SO_USELOOPBACK 0x0040
87 #include <sys/types.h>
92 #include <netinet/in.h>
93 #include <sys/socket.h>
94 #include <arpa/inet.h>
110 for (; tolower(*op1) == tolower(*op2); op1++,op2++)
118 return(tolower(*op1) - tolower(*op2));
129 sLen = strlen(
string);
134 while (sLen && (
' ' ==
string[sLen-1]))
142 leading = strspn(
string,
" ");
145 memmove(
string,
string+leading,sLen+1);
166 return strdup(context->ObjectToStringValue(obj));
195 if (!context->WholeNumber(countObj, &temp))
203 arr = (
int *)malloc(
sizeof(
int) * temp);
214 for (
int i = 0; i < count; i++)
218 if (!context->ObjectToWholeNumber(countObj, &temp))
245 stem.
setValue((
size_t)0, context->WholeNumber(count));
250 for (
int i = 0; i < count; i++)
252 stem.
setValue(i + 1, context->WholeNumber(arr[i]));
263 char *pszFamily = NULL;
264 char *pszPort = NULL;
265 char *pszAddr = NULL;
270 memset(pSockAddr, 0,
sizeof(*pSockAddr));
283 if (pszFamily == NULL || pszPort == NULL || pszAddr == NULL)
297 pSockAddr->sin_family = AF_INET;
301 pSockAddr->sin_family = (short) strtol(pszFamily,NULL,10);
307 pSockAddr->sin_port = (
unsigned short) strtoul(pszPort, NULL, 10);
308 pSockAddr->sin_port = htons(pSockAddr->sin_port);
315 pSockAddr->sin_addr.s_addr = INADDR_ANY;
319 pSockAddr->sin_addr.s_addr = inet_addr(pszAddr);
326 if (pszFamily == NULL)
348 stem.
setValue(
"FAMILY", context->WholeNumber(pSockAddr->sin_family));
353 stem.
setValue(
"PORT", context->UnsignedInt32(htons(pSockAddr->sin_port)));
358 stem.
setValue(
"ADDR", context->String(inet_ntoa(pSockAddr->sin_addr)));
373 stem.
setValue(
"NAME", context->String(pHostEnt->h_name));
378 for (count=0; pHostEnt->h_aliases[count]; count++)
380 snprintf(szBuffer,
sizeof szBuffer,
"ALIAS.%d",count+1);
381 stem.
setValue(szBuffer, context->String(pHostEnt->h_aliases[count]));
384 stem.
setValue(
"ALIAS.0", context->WholeNumber(count));
389 stem.
setValue(
"ADDRTYPE", context->String(
"AF_INET"));
394 addr.s_addr = (*(
uint32_t *)pHostEnt->h_addr);
395 stem.
setValue(
"ADDR", context->String(inet_ntoa(addr)));
407 for (count=0; pHostEnt->h_addr_list[count]; count++)
409 snprintf(szBuffer,
sizeof szBuffer,
"ADDR.%d", count+1);
410 addr.s_addr = (*(
uint32_t *)pHostEnt->h_addr_list[count]);
412 stem.
setValue(szBuffer, context->String(inet_ntoa(addr)));
415 stem.
setValue(
"ADDR.0", context->WholeNumber(count));
424 if (!pszOptName)
return 0;
427 else if (!
caselessCompare(
"SO_REUSEADDR" ,pszOptName))
return SO_REUSEADDR;
428 else if (!
caselessCompare(
"SO_KEEPALIVE" ,pszOptName))
return SO_KEEPALIVE;
429 else if (!
caselessCompare(
"SO_DONTROUTE" ,pszOptName))
return SO_DONTROUTE;
430 else if (!
caselessCompare(
"SO_BROADCAST" ,pszOptName))
return SO_BROADCAST;
431 else if (!
caselessCompare(
"SO_USELOOPBACK" ,pszOptName))
return SO_USELOOPBACK;
433 else if (!
caselessCompare(
"SO_OOBINLINE" ,pszOptName))
return SO_OOBINLINE;
436 else if (!
caselessCompare(
"SO_SNDLOWAT" ,pszOptName))
return SO_SNDLOWAT;
437 else if (!
caselessCompare(
"SO_RCVLOWAT" ,pszOptName))
return SO_RCVLOWAT;
438 else if (!
caselessCompare(
"SO_SNDTIMEO" ,pszOptName))
return SO_SNDTIMEO;
439 else if (!
caselessCompare(
"SO_RCVTIMEO" ,pszOptName))
return SO_RCVTIMEO;
456 const char *pszErrno = szBuff;
461 context->SetContextVariable(
"h_errno", zero);
466 context->SetContextVariable(
"errno", zero);
471 theErrno = WSAGetLastError();
479 case WSAEINTR : pszErrno =
"EINTR";
break;
480 case WSAEBADF : pszErrno =
"EBADF";
break;
481 case WSAEACCES : pszErrno =
"EACCES";
break;
482 case WSAEFAULT : pszErrno =
"EFAULT";
break;
483 case WSAEINVAL : pszErrno =
"EINVAL";
break;
484 case WSAEMFILE : pszErrno =
"EMFILE";
break;
485 case WSAEWOULDBLOCK : pszErrno =
"EWOULDBLOCK";
break;
486 case WSAEINPROGRESS : pszErrno =
"EINPROGRESS";
break;
487 case WSAEALREADY : pszErrno =
"EALREADY";
break;
488 case WSAENOTSOCK : pszErrno =
"ENOTSOCK";
break;
489 case WSAEDESTADDRREQ : pszErrno =
"EDESTADDRREQ";
break;
490 case WSAEMSGSIZE : pszErrno =
"EMSGSIZE";
break;
491 case WSAEPROTOTYPE : pszErrno =
"EPROTOTYPE";
break;
492 case WSAENOPROTOOPT : pszErrno =
"ENOPROTOOPT";
break;
493 case WSAEPROTONOSUPPORT : pszErrno =
"EPROTONOSUPPORT";
break;
494 case WSAESOCKTNOSUPPORT : pszErrno =
"ESOCKTNOSUPPORT";
break;
495 case WSAEOPNOTSUPP : pszErrno =
"EOPNOTSUPP";
break;
496 case WSAEPFNOSUPPORT : pszErrno =
"EPFNOSUPPORT";
break;
497 case WSAEAFNOSUPPORT : pszErrno =
"EAFNOSUPPORT";
break;
498 case WSAEADDRINUSE : pszErrno =
"EADDRINUSE";
break;
499 case WSAEADDRNOTAVAIL : pszErrno =
"EADDRNOTAVAIL";
break;
500 case WSAENETDOWN : pszErrno =
"ENETDOWN";
break;
501 case WSAENETUNREACH : pszErrno =
"ENETUNREACH";
break;
502 case WSAENETRESET : pszErrno =
"ENETRESET";
break;
503 case WSAECONNABORTED : pszErrno =
"ECONNABORTED";
break;
504 case WSAECONNRESET : pszErrno =
"ECONNRESET";
break;
505 case WSAENOBUFS : pszErrno =
"ENOBUFS";
break;
506 case WSAEISCONN : pszErrno =
"EISCONN";
break;
507 case WSAENOTCONN : pszErrno =
"ENOTCONN";
break;
508 case WSAESHUTDOWN : pszErrno =
"ESHUTDOWN";
break;
509 case WSAETOOMANYREFS : pszErrno =
"ETOOMANYREFS";
break;
510 case WSAETIMEDOUT : pszErrno =
"ETIMEDOUT";
break;
511 case WSAECONNREFUSED : pszErrno =
"ECONNREFUSED";
break;
512 case WSAELOOP : pszErrno =
"ELOOP";
break;
513 case WSAENAMETOOLONG : pszErrno =
"ENAMETOOLONG";
break;
514 case WSAEHOSTDOWN : pszErrno =
"EHOSTDOWN";
break;
515 case WSAEHOSTUNREACH : pszErrno =
"EHOSTUNREACH";
break;
516 case WSASYSNOTREADY : pszErrno =
"WSASYSNOTREADY";
break;
517 case WSAVERNOTSUPPORTED : pszErrno =
"WSASAVERNOTSUPPORTED";
break;
518 case WSANOTINITIALISED : pszErrno =
"WSANOTINITIALISED";
break;
519 case WSAHOST_NOT_FOUND : pszErrno =
"HOST_NOT_FOUND";
break;
520 case WSATRY_AGAIN : pszErrno =
"TRY_AGAIN";
break;
521 case WSANO_RECOVERY : pszErrno =
"NO_RECOVERY";
break;
522 case WSANO_DATA : pszErrno =
"NO_DATA";
break;
525 case EWOULDBLOCK : pszErrno =
"EWOULDBLOCK";
break;
526 case EINPROGRESS : pszErrno =
"EINPROGRESS";
break;
527 case EALREADY : pszErrno =
"EALREADY";
break;
528 case ENOTSOCK : pszErrno =
"ENOTSOCK";
break;
529 case EDESTADDRREQ : pszErrno =
"EDESTADDRREQ";
break;
530 case EMSGSIZE : pszErrno =
"EMSGSIZE";
break;
531 case EPROTOTYPE : pszErrno =
"EPROTOTYPE";
break;
532 case ENOPROTOOPT : pszErrno =
"ENOPROTOOPT";
break;
533 case EPROTONOSUPPORT : pszErrno =
"EPROTONOSUPPORT";
break;
534 case ESOCKTNOSUPPORT : pszErrno =
"ESOCKTNOSUPPORT";
break;
535 case EOPNOTSUPP : pszErrno =
"EOPNOTSUPP";
break;
536 case EPFNOSUPPORT : pszErrno =
"EPFNOSUPPORT";
break;
537 case EAFNOSUPPORT : pszErrno =
"EAFNOSUPPORT";
break;
538 case EADDRINUSE : pszErrno =
"EADDRINUSE";
break;
539 case EADDRNOTAVAIL : pszErrno =
"EADDRNOTAVAIL";
break;
540 case ENETDOWN : pszErrno =
"ENETDOWN";
break;
541 case ENETUNREACH : pszErrno =
"ENETUNREACH";
break;
542 case ENETRESET : pszErrno =
"ENETRESET";
break;
543 case ECONNABORTED : pszErrno =
"ECONNABORTED";
break;
544 case ECONNRESET : pszErrno =
"ECONNRESET";
break;
545 case ENOBUFS : pszErrno =
"ENOBUFS";
break;
546 case EISCONN : pszErrno =
"EISCONN";
break;
547 case ENOTCONN : pszErrno =
"ENOTCONN";
break;
548 case ESHUTDOWN : pszErrno =
"ESHUTDOWN";
break;
549 case ETOOMANYREFS : pszErrno =
"ETOOMANYREFS";
break;
550 case ETIMEDOUT : pszErrno =
"ETIMEDOUT";
break;
551 case ECONNREFUSED : pszErrno =
"ECONNREFUSED";
break;
552 case ELOOP : pszErrno =
"ELOOP";
break;
553 case ENAMETOOLONG : pszErrno =
"ENAMETOOLONG";
break;
554 case EHOSTDOWN : pszErrno =
"EHOSTDOWN";
break;
555 case EHOSTUNREACH : pszErrno =
"EHOSTUNREACH";
break;
556 case ENOTEMPTY : pszErrno =
"ENOTEMPTY";
break;
559 snprintf(szBuff,
sizeof szBuff,
"%d",theErrno);
562 context->SetContextVariable(
"errno", context->String(pszErrno));
579 snprintf(buffer,
sizeof buffer,
"%d.%d.%d", ORX_VER, ORX_REL, ORX_MOD);
580 return context->String(buffer);
601 return context->NullString();
627 WORD wVersionRequested;
629 wVersionRequested = MAKEWORD( 1, 1 );
630 int rc = WSAStartup( wVersionRequested, &wsaData );
RexxObjectPtr getValue(const char *name)
bool resolveStem(RexxObjectPtr source)
void setValue(const char *name, RexxObjectPtr value)
#define REXX_INTERPRETER_4_0_0
#define REXX_LAST_ROUTINE()
#define REXX_TYPED_ROUTINE(n, e)
#define STANDARD_PACKAGE_HEADER
struct _RexxStringObject * RexxStringObject
struct _RexxObjectPtr * RexxObjectPtr
void setErrno(RexxCallContext *context, bool noError)
char * getStemElement(RexxCallContext *context, StemManager &stem, const char *name)
int stringToSockOpt(const char *pszOptName)
void stemToSockAddr(RexxCallContext *context, StemManager &stem, sockaddr_in *pSockAddr)
void hostEntToStem(RexxCallContext *context, struct hostent *pHostEnt, StemManager &stem)
REXX_TYPED_ROUTINE_PROTOTYPE(SockDropFuncs)
RexxRoutine1(CSTRING, SockLoadFuncs, OPTIONAL_CSTRING, version)
RexxPackageEntry rxsock_package_entry
void sockAddrToStem(RexxCallContext *context, sockaddr_in *pSockAddr, StemManager &stem)
int caselessCompare(const char *op1, const char *op2)
void intArrayToStem(RexxCallContext *context, RexxObjectPtr stemSource, int count, int *arr)
RexxRoutineEntry rxsock_functions[]
void stripBlanks(char *string)
void RexxEntry loader(RexxThreadContext *context)
void stemToIntArray(RexxCallContext *context, RexxObjectPtr stemSource, int &count, int *&arr)
RexxRoutine0(RexxStringObject, SockVersion)
OOREXX_GET_PACKAGE(rxsock)
struct sockaddr_in sockaddr_in