static int udpParseAmsEndpoint(AmsEndpoint *dp) { char *colon; char hostName[MAXHOSTNAMELEN + 1]; UdpTsep tsep; if (dp == NULL || dp->ept == NULL) { errno = EINVAL; putErrmsg("udpts can't parse AMS endpoint.", NULL); return -1; } colon = strchr(dp->ept, ':'); *colon = '\0'; istrcpy(hostName, dp->ept, sizeof hostName); *colon = ':'; tsep.portNbr = atoi(colon + 1); tsep.ipAddress = getInternetAddress(hostName); dp->tsep = MTAKE(sizeof(UdpTsep)); if (dp->tsep == NULL) { putSysErrmsg("udpts can't record parsed AMS endpoint name.", NULL); return -1; } memcpy((char *) (dp->tsep), (char *) &tsep, sizeof(UdpTsep)); /* Also parse out the QOS of this endpoint. */ dp->diligence = AmsBestEffort; dp->sequence = AmsArrivalOrder; return 0; }
static int udpParseMamsEndpoint(MamsEndpoint *ep) { char *colon; char hostName[MAXHOSTNAMELEN + 1]; UdpTsep tsep; if (ep == NULL || ep->ept == NULL) { errno = EINVAL; putErrmsg("udpts can't parse MAMS endpoint name.", NULL); return -1; } colon = strchr(ep->ept, ':'); *colon = '\0'; istrcpy(hostName, ep->ept, sizeof hostName); *colon = ':'; tsep.portNbr = atoi(colon + 1); tsep.ipAddress = getInternetAddress(hostName); ep->tsep = MTAKE(sizeof(UdpTsep)); if (ep->tsep == NULL) { putSysErrmsg("udpts can't record parsed MAMS endpoint name.", NULL); return -1; } memcpy((char *) (ep->tsep), (char *) &tsep, sizeof(UdpTsep)); //printf("parsed '%s' to port %d address %d.\n", ep->ept, tsep.portNbr, //tsep.ipAddress); return 0; }
static int hashcase(const char *key) { char *lckey; lckey = salloc(strlen(key) + 1); istrcpy(lckey, key); return hash(lckey); }
static int parseDtn2Nss(char *nss, char *nodeName, char *demux) { int nssLength; char *startOfNodeName; char *endOfNodeName; char *startOfDemux; nssLength = strlen(nss); if (nssLength < 3 || strncmp(nss, "//", 2) != 0) { return 0; /* Wrong NSS format. */ } startOfNodeName = nss; endOfNodeName = strchr(startOfNodeName + 2, '/'); if (endOfNodeName == NULL) /* No delimiter, no demux. */ { if (nssLength >= SDRSTRING_BUFSZ) { return 0; /* Too long. */ } istrcpy(nodeName, startOfNodeName, SDRSTRING_BUFSZ); *demux = '\0'; return 1; /* Fully parsed. */ } if ((endOfNodeName - startOfNodeName) >= SDRSTRING_BUFSZ) { return 0; /* Too long. */ } *endOfNodeName = '\0'; /* Temporary. */ istrcpy(nodeName, startOfNodeName, SDRSTRING_BUFSZ); *endOfNodeName = '/'; /* Restore original. */ startOfDemux = endOfNodeName + 1; if (strlen(startOfDemux) >= SDRSTRING_BUFSZ) { return 0; } istrcpy(demux, startOfDemux, SDRSTRING_BUFSZ); return 1; }
static int icsubstr(char *s1, char *s2) { char buf[LINESIZE]; if (s1 && s2) { istrcpy(buf, sizeof (buf), s1); return substr(buf, s2) != -1; } else return 0; }
static ichar * DirName(const ichar *f, ichar *dir) { const ichar *base, *p; for (base = p = f; *p; p++) { if (isDirSep(*p) && p[1] != EOS) base = p; } if (base == f) { if (isDirSep(*f)) istrcpy(dir, DIRSEPSTR); else istrcpy(dir, L"."); } else { istrncpy(dir, f, base - f); dir[base - f] = EOS; } return dir; }
int main() { char *str1 = istring_mk(NULL); char *str2 = istring_mk("Anders"); char *str3 = istring_mk("Alander"); char *str4 = istring_mk(" "); char *str9 = istring_to_string(str2); char *str5 = istrcat(str9,str4); char *str11 = istring_to_string(str5); char *str6 = istrcat(str11, str3); char *str7 = istring_to_string(str6); char *str8 = istring_mk("Erik"); char *str10 = istring_to_string(str5); char *str12 = "Anders Ă…lander"; char *str13 = istrncat(str9, str3,2); printf("An empty istring has length %zu\n", istrlen(str1)); printf("My first name is %s\n",str2); printf("My last name is %s\n",str3); printf("My name concatenated is %s\n", str6); printf("%s concatenated with the first %d chars from %s is %s\n", str2, 2, str3, str13); printf("%s has length %zu\n", str6, istrlen(str6)); printf("%s is my name stored as normal string, it also has length %zu\n", str7, strlen(str7)); printf("An istring's length can be changed without touching the string itself. %s has length %zu\n", str2, istrlen(str2)); str2 = istrslen(str2, 15); printf("but we can change it to %zu\n", istrlen(str2)); printf("Returns a pointer to the first given character in %s, for example a pointer to 's'gives %s\n", str2, istrchr(str2,'s')); printf("Same as above but from the end of %s. Pointer to 's' gives %s\n", str2, istrrchr(str2, 's')); printf("Are the strings %s and %s equal? %s\n", str2, str3, istrcmp(str2,str3)?"no":"yes"); printf("Which one of %s and %s is greatest? %s\n", str2, str3, istrcmp(str2,str3)<0?str2:str3); printf("Compares the first %d characters in %s and %s. The substring of %s is greatest\n", 3, str2, str3, istrncmp(str2, str3, 3) > 0?str3:str2); printf("The result of copying %s into %s is %s\n", str8, str12, istrcpy(str7, str8)); printf("The result of copying %d chars from %s into %s is %s\n", 3, str8, str12, istrncpy(str7,str8,3)); istring_rm(str1); istring_rm(str2); istring_rm(str3); istring_rm(str4); istring_rm(str5); istring_rm(str6); free(str7); istring_rm(str8); free(str9); free(str10); free(str11); istring_rm(str13); return 0; }
static PsmAddress findFileName(PsmPartition trace, TraceHeader *trh, char *sourceFileName) { PsmAddress elt; PsmAddress filenameAddress; char *filename; int buflen; for (elt = sm_list_first(trace, trh->files); elt; elt = sm_list_next(trace, elt)) { filenameAddress = sm_list_data(trace, elt); filename = (char *) psp(trace, filenameAddress); if (strcmp(filename, sourceFileName) == 0) { return filenameAddress; } } /* This is a source file we haven't heard of before. */ buflen = strlen(sourceFileName) + 1; filenameAddress = psm_zalloc(trace, buflen); if (filenameAddress == 0) { discardEvent(trace); return 0; } /* Add this source file to the list for the trace. */ istrcpy((char *) psp(trace, filenameAddress), sourceFileName, buflen); if (sm_list_insert_last(trace, trh->files, filenameAddress) == 0) { discardEvent(trace); return 0; } return filenameAddress; }
static void logEvent(PsmPartition trace, int opType, unsigned long addr, int objectSize, char *msg, char *fileName, int lineNbr, PsmAddress *eltp) { PsmAddress traceHeaderAddress; TraceHeader *trh; PsmAddress itemAddr; TraceItem *item; int buflen; PsmAddress elt; if (eltp) { *eltp = 0; } traceHeaderAddress = psm_get_root(trace); trh = (TraceHeader *) psp(trace, traceHeaderAddress); if (trh == NULL) return; itemAddr = psm_zalloc(trace, sizeof(TraceItem)); if (itemAddr == 0) { discardEvent(trace); return; } item = (TraceItem *) psp(trace, itemAddr); memset((char *) item, 0, sizeof(TraceItem)); if (msg) { buflen = strlen(msg) + 1; item->msg = psm_zalloc(trace, buflen); if (item->msg == 0) { discardEvent(trace); return; } istrcpy((char *) psp(trace, item->msg), msg, buflen); } item->taskId = sm_TaskIdSelf(); item->fileName = findFileName(trace, trh, fileName); if (item->fileName == 0) { return; /* Events are being discarded. */ } item->lineNbr = lineNbr; trh->opCount++; item->opNbr = trh->opCount; item->opType = opType; item->objectAddress = addr; item->objectSize = objectSize; elt = sm_list_insert_last(trace, trh->log, itemAddr); if (elt == 0) { discardEvent(trace); return; } if (eltp) { *eltp = elt; } }
static int udpAmsInit(AmsInterface *tsif, char *epspec) { unsigned short portNbr; unsigned int ipAddress; char hostName[MAXHOSTNAMELEN + 1]; struct sockaddr socketName; struct sockaddr_in *inetName; socklen_t nameLength; int fd; char endpointNameText[32]; int eptLen; long longfd; if (strcmp(epspec, "@") == 0) /* Default. */ { epspec = NULL; /* Force default selection. */ } parseSocketSpec(epspec, &portNbr, &ipAddress); if (ipAddress == 0) { getNameOfHost(hostName, sizeof hostName); ipAddress = getInternetAddress(hostName); } else { if (getInternetHostName(ipAddress, hostName) == NULL) { putErrmsg("Unknown host in endpoint.", epspec); return -1; } } portNbr = htons(portNbr); ipAddress = htonl(ipAddress); memset((char *) &socketName, 0, sizeof socketName); inetName = (struct sockaddr_in *) &socketName; inetName->sin_family = AF_INET; inetName->sin_port = portNbr; memcpy((char *) &(inetName->sin_addr.s_addr), (char *) &ipAddress, 4); fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); if (fd < 0) { putSysErrmsg("udpts can't open AMS SAP", NULL); return -1; } nameLength = sizeof(struct sockaddr); if (reUseAddress(fd) || bind(fd, &socketName, nameLength) < 0 || getsockname(fd, &socketName, &nameLength) < 0) { putSysErrmsg("udpts can't initialize AMS SAP", NULL); return -1; } portNbr = inetName->sin_port; portNbr = ntohs(portNbr); memcpy((char *) &ipAddress, (char *) &(inetName->sin_addr.s_addr), 4); ipAddress = ntohl(ipAddress); tsif->diligence = AmsBestEffort; tsif->sequence = AmsArrivalOrder; isprintf(endpointNameText, sizeof endpointNameText, "%s:%hu", hostName, portNbr); eptLen = strlen(endpointNameText) + 1; tsif->ept = MTAKE(eptLen); if (tsif->ept == NULL) { close(fd); putSysErrmsg(NoMemoryMemo, NULL); return -1; } istrcpy(tsif->ept, endpointNameText, eptLen); longfd = fd; tsif->sap = (void *) longfd; return 0; }
static int checkNodeListParms(IonParms *parms, char *wdName, unsigned long nodeNbr) { char *nodeListDir; char nodeListFileName[265]; int nodeListFile; int lineNbr = 0; int lineLen; char lineBuf[256]; unsigned long lineNodeNbr; int lineWmKey; char lineSdrName[MAX_SDR_NAME + 1]; char lineWdName[256]; int result; nodeListDir = getenv("ION_NODE_LIST_DIR"); if (nodeListDir == NULL) /* Single node on machine. */ { if (parms->wmKey == 0) { parms->wmKey = ION_DEFAULT_SM_KEY; } if (parms->wmKey != ION_DEFAULT_SM_KEY) { putErrmsg("Config parms wmKey != default.", itoa(ION_DEFAULT_SM_KEY)); return -1; } if (parms->sdrName[0] == '\0') { istrcpy(parms->sdrName, ION_DEFAULT_SDR_NAME, sizeof parms->sdrName); } if (strcmp(parms->sdrName, ION_DEFAULT_SDR_NAME) != 0) { putErrmsg("Config parms sdrName != default.", ION_DEFAULT_SDR_NAME); return -1; } return 0; } /* Configured for multi-node operation. */ isprintf(nodeListFileName, sizeof nodeListFileName, "%.255s%cion_nodes", nodeListDir, ION_PATH_DELIMITER); if (nodeNbr == 0) /* Just attaching. */ { nodeListFile = open(nodeListFileName, O_RDONLY, 0); } else /* Initializing the node. */ { nodeListFile = open(nodeListFileName, O_RDWR | O_CREAT, 00666); } if (nodeListFile < 0) { putSysErrmsg("Can't open ion_nodes file", nodeListFileName); writeMemo("[?] Remove ION_NODE_LIST_DIR from env?"); return -1; } while (1) { if (igets(nodeListFile, lineBuf, sizeof lineBuf, &lineLen) == NULL) { if (lineLen < 0) { close(nodeListFile); putErrmsg("Failed reading ion_nodes file.", nodeListFileName); return -1; } break; /* End of file. */ } lineNbr++; if (sscanf(lineBuf, "%lu %d %31s %255s", &lineNodeNbr, &lineWmKey, lineSdrName, lineWdName) < 4) { close(nodeListFile); putErrmsg("Syntax error at line#", itoa(lineNbr)); writeMemoNote("[?] Repair ion_nodes file.", nodeListFileName); return -1; } if (lineNodeNbr == nodeNbr) /* Match. */ { /* lineNodeNbr can't be zero (we never * write such lines to the file), so this * must be matching non-zero node numbers. * So we are re-initializing this node. */ close(nodeListFile); if (strcmp(lineWdName, wdName) != 0) { putErrmsg("CWD conflict at line#", itoa(lineNbr)); writeMemoNote("[?] Repair ion_nodes file.", nodeListFileName); return -1; } if (parms->wmKey == 0) { parms->wmKey = lineWmKey; } if (parms->wmKey != lineWmKey) { putErrmsg("WmKey conflict at line#", itoa(lineNbr)); writeMemoNote("[?] Repair ion_nodes file.", nodeListFileName); return -1; } if (parms->sdrName[0] == '\0') { istrcpy(parms->sdrName, lineSdrName, sizeof parms->sdrName); } if (strcmp(parms->sdrName, lineSdrName) != 0) { putErrmsg("SdrName conflict at line#", itoa(lineNbr)); writeMemoNote("[?] Repair ion_nodes file.", nodeListFileName); return -1; } return 0; } /* lineNodeNbr does not match nodeNbr (which may * be zero). */ if (strcmp(lineWdName, wdName) == 0) /* Match. */ { close(nodeListFile); if (nodeNbr == 0) /* Attaching. */ { parms->wmKey = lineWmKey; istrcpy(parms->sdrName, lineSdrName, MAX_SDR_NAME + 1); return 0; } /* Reinitialization conflict. */ putErrmsg("NodeNbr conflict at line#", itoa(lineNbr)); writeMemoNote("[?] Repair ion_nodes file.", nodeListFileName); return -1; } /* Haven't found matching line yet. Continue. */ } /* No matching lines in file. */ if (nodeNbr == 0) /* Attaching to existing node. */ { close(nodeListFile); putErrmsg("No node has been initialized in this directory.", wdName); return -1; } /* Initializing, so append line to the nodes list file. */ if (parms->wmKey == 0) { parms->wmKey = ION_DEFAULT_SM_KEY; } if (parms->sdrName[0] == '\0') { istrcpy(parms->sdrName, ION_DEFAULT_SDR_NAME, sizeof parms->sdrName); } isprintf(lineBuf, sizeof lineBuf, "%lu %d %.31s %.255s\n", nodeNbr, parms->wmKey, parms->sdrName, wdName); result = iputs(nodeListFile, lineBuf); close(nodeListFile); if (result < 0) { putErrmsg("Failed writing to ion_nodes file.", NULL); return -1; } return 0; }
int readIonParms(char *configFileName, IonParms *parms) { char ownHostName[MAXHOSTNAMELEN + 1]; char *endOfHostName; char configFileNameBuffer[PATHLENMAX + 1 + 9 + 1]; int configFile; char buffer[512]; int lineNbr; char line[256]; int lineLength; int result; char *cursor; int i; char *tokens[2]; int tokenCount; /* Set defaults. */ CHKERR(parms); memset((char *) parms, 0, sizeof(IonParms)); parms->wmSize = 5000000; parms->wmAddress = 0; /* Dyamically allocated. */ parms->configFlags = SDR_IN_DRAM; parms->heapWords = 250000; parms->heapKey = SM_NO_KEY; istrcpy(parms->pathName, "/usr/ion", sizeof parms->pathName); /* Determine name of config file. */ if (configFileName == NULL) { #ifdef ION_NO_DNS ownHostName[0] = '\0'; #else if (getNameOfHost(ownHostName, MAXHOSTNAMELEN) < 0) { writeMemo("[?] Can't get name of local host."); return -1; } #endif /* Find end of high-order part of host name. */ if ((endOfHostName = strchr(ownHostName, '.')) != NULL) { *endOfHostName = 0; } isprintf(configFileNameBuffer, sizeof configFileNameBuffer, "%.256s.ionconfig", ownHostName); configFileName = configFileNameBuffer; } /* Get overrides from config file. */ configFile = open(configFileName, O_RDONLY, 0777); if (configFile < 0) { if (errno == ENOENT) /* No overrides apply. */ { writeMemo("[i] admin pgm using default SDR parms."); printIonParms(parms); return 0; } isprintf(buffer, sizeof buffer, "[?] admin pgm can't open SDR \ config file '%.255s': %.64s", configFileName, system_error_msg()); writeMemo(buffer); return -1; } isprintf(buffer, sizeof buffer, "[i] admin pgm using SDR parm \ overrides from %.255s.", configFileName); writeMemo(buffer); lineNbr = 0; while (1) { if (igets(configFile, line, sizeof line, &lineLength) == NULL) { if (lineLength == 0) { result = 0; printIonParms(parms); } else { result = -1; writeErrMemo("admin pgm SDR config file igets \ failed"); } break; /* Done. */ } lineNbr++; if (lineLength < 1) { continue; /* Empty line. */ } if (line[0] == '#') /* Comment only. */ { continue; } tokenCount = 0; for (cursor = line, i = 0; i < 2; i++) { if (*cursor == '\0') { tokens[i] = NULL; } else { findToken((char **) &cursor, &(tokens[i])); tokenCount++; } } if (tokenCount != 2) { isprintf(buffer, sizeof buffer, "[?] incomplete SDR \ configuration file line (%d).", lineNbr); writeMemo(buffer); result = -1; break; } if (strcmp(tokens[0], "wmKey") == 0) { parms->wmKey = atoi(tokens[1]); continue; } if (strcmp(tokens[0], "wmSize") == 0) { parms->wmSize = atoi(tokens[1]); continue; } if (strcmp(tokens[0], "wmAddress") == 0) { parms->wmAddress = (char *) atol(tokens[1]); continue; } if (strcmp(tokens[0], "sdrName") == 0) { istrcpy(parms->sdrName, tokens[1], sizeof(parms->sdrName)); continue; } if (strcmp(tokens[0], "configFlags") == 0) { parms->configFlags = atoi(tokens[1]); continue; } if (strcmp(tokens[0], "heapWords") == 0) { parms->heapWords = atoi(tokens[1]); continue; } if (strcmp(tokens[0], "heapKey") == 0) { parms->heapKey = atoi(tokens[1]); continue; } if (strcmp(tokens[0], "pathName") == 0) { istrcpy(parms->pathName, tokens[1], sizeof(parms->pathName)); continue; } isprintf(buffer, sizeof buffer, "[?] unknown SDR config \ keyword '%.32s' at line %d.", tokens[0], lineNbr); writeMemo(buffer); result = -1; break; }
int bp_open(char *eidString, BpSAP *bpsapPtr) { Sdr sdr; MetaEid metaEid; VScheme *vscheme; PsmAddress vschemeElt; Sap sap; VEndpoint *vpoint; PsmAddress vpointElt; CHKERR(eidString && *eidString && bpsapPtr); *bpsapPtr = NULL; /* Default, in case of failure. */ sdr = getIonsdr(); sdr_begin_xn(sdr); /* Just to lock memory. */ /* First validate the endpoint ID. */ if (parseEidString(eidString, &metaEid, &vscheme, &vschemeElt) == 0) { sdr_exit_xn(sdr); putErrmsg("Malformed EID.", eidString); return -1; } if (vschemeElt == 0) { sdr_exit_xn(sdr); putErrmsg("Scheme not known.", metaEid.schemeName); restoreEidString(&metaEid); return -1; } findEndpoint(NULL, metaEid.nss, vscheme, &vpoint, &vpointElt); if (vpointElt == 0) { sdr_exit_xn(sdr); putErrmsg("Endpoint not known.", metaEid.nss); restoreEidString(&metaEid); return -1; } /* Endpoint exists; make sure it's not already opened * by some application. */ if (vpoint->appPid > 0) /* Endpoint not closed. */ { if (sm_TaskExists(vpoint->appPid)) { sdr_exit_xn(sdr); if (vpoint->appPid == sm_TaskIdSelf()) { return 0; } restoreEidString(&metaEid); putErrmsg("Endpoint is already open.", itoa(vpoint->appPid)); return -1; } /* Application terminated without closing the * endpoint, so simply close it now. */ vpoint->appPid = -1; } /* Construct the service access point. */ sap.vpoint = vpoint; memcpy(&sap.endpointMetaEid, &metaEid, sizeof(MetaEid)); sap.endpointMetaEid.colon = NULL; sap.endpointMetaEid.schemeName = MTAKE(metaEid.schemeNameLength + 1); if (sap.endpointMetaEid.schemeName == NULL) { sdr_exit_xn(sdr); putErrmsg("Can't create BpSAP.", NULL); restoreEidString(&metaEid); return -1; } sap.endpointMetaEid.nss = MTAKE(metaEid.nssLength + 1); if (sap.endpointMetaEid.nss == NULL) { sdr_exit_xn(sdr); MRELEASE(sap.endpointMetaEid.schemeName); putErrmsg("Can't create BpSAP.", NULL); restoreEidString(&metaEid); return -1; } *bpsapPtr = MTAKE(sizeof(Sap)); if (*bpsapPtr == NULL) { sdr_exit_xn(sdr); MRELEASE(sap.endpointMetaEid.nss); MRELEASE(sap.endpointMetaEid.schemeName); putErrmsg("Can't create BpSAP.", NULL); restoreEidString(&metaEid); return -1; } istrcpy(sap.endpointMetaEid.schemeName, metaEid.schemeName, sizeof sap.endpointMetaEid.schemeName); istrcpy(sap.endpointMetaEid.nss, metaEid.nss, sizeof sap.endpointMetaEid.nss); restoreEidString(&metaEid); sap.recvSemaphore = vpoint->semaphore; memcpy((char *) *bpsapPtr, (char *) &sap, sizeof(Sap)); /* Having created the SAP, give its owner exclusive * access to the endpoint. */ vpoint->appPid = sm_TaskIdSelf(); sdr_exit_xn(sdr); /* Unlock memory. */ return 0; }
int bpecho(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8, int a9, int a10) { char *ownEid = (char *) a1; #else int main(int argc, char **argv) { char *ownEid = (argc > 1 ? argv[1] : NULL); #endif /* Indication marks: "." for BpPayloadPresent (1), "*" for BpReceptionTimedOut (2). "!" for BpReceptionInterrupted (3). */ static char dlvmarks[] = "?.*!"; BpSAP sap; Sdr sdr; int running = 1; char dataToSend[ADU_LEN] = "x"; Object bundleZco; Object newBundle; Object extent; BpDelivery dlv; char sourceEid[1024]; if (ownEid == NULL) { PUTS("Usage: bpecho <own endpoint ID>"); return 0; } if (bp_attach() < 0) { putErrmsg("Can't attach to BP.", NULL); return 0; } if (bp_open(ownEid, &sap) < 0) { putErrmsg("Can't open own endpoint.", NULL); return 0; } oK(_bpsap(&sap)); sdr = bp_get_sdr(); isignal(SIGINT, handleQuit); while (1) { /* Wait for a bundle from the driver. */ while (running) { if (bp_receive(sap, &dlv, BP_BLOCKING) < 0) { bp_close(sap); putErrmsg("bpecho bundle reception failed.", NULL); return 1; } putchar(dlvmarks[dlv.result]); fflush(stdout); if (dlv.result == BpReceptionInterrupted) { running = 0; continue; } if (dlv.result == BpPayloadPresent) { istrcpy(sourceEid, dlv.bundleSourceEid, sizeof sourceEid); bp_release_delivery(&dlv, 1); break; /* Out of reception loop. */ } bp_release_delivery(&dlv, 1); } if (!running) /* Benchmark run terminated. */ { break; /* Out of main loop. */ } /* Now send acknowledgment bundle. */ sdr_begin_xn(sdr); extent = sdr_malloc(sdr, ADU_LEN); if (extent == 0) { sdr_cancel_xn(sdr); putErrmsg("No space for ZCO extent.", NULL); break; /* Out of main loop. */ } sdr_write(sdr, extent, dataToSend, ADU_LEN); bundleZco = zco_create(sdr, ZcoSdrSource, extent, 0, ADU_LEN); if (sdr_end_xn(sdr) < 0 || bundleZco == 0) { putErrmsg("Can't create ZCO.", NULL); break; /* Out of main loop. */ } if (bp_send(sap, BP_BLOCKING, sourceEid, NULL, 300, BP_STD_PRIORITY, NoCustodyRequested, 0, 0, NULL, bundleZco, &newBundle) < 1) { putErrmsg("bpecho can't send echo bundle.", NULL); break; /* Out of main loop. */ } } bp_close(sap); writeErrmsgMemos(); bp_detach(); return 0; }
static void load_one_catalogue(catalog_file * file) { FILE *src = wfopen(file->file, "r"); ichar buffer[2 * FILENAME_MAX]; ichar base[2 * FILENAME_MAX]; ichar *p; int t; catalogue_item_ptr this_item; int override = 0; if ( !src ) { gripe(NULL, ERC_NO_CATALOGUE, file->file); return; } (void) istrcpy(base, file->file); p = base + istrlen(base); while (p != base && !isDirSep(p[-1])) p--; for (;;) { t = scan(src, buffer, sizeof(buffer), 1); switch (t) { case CAT_BASE: if (scan(src, buffer, sizeof(buffer), 0) == EOF) break; (void) istrcpy(base, buffer); p = base + istrlen(base); if (p != base && !isDirSep(p[-1])) *p++ = '/'; continue; case CAT_OVERRIDE: if (scan(src, buffer, sizeof(buffer), 0) == EOF) break; override = towlower(buffer[0]) == 'y' ? CAT_OVERRIDE : 0; continue; case CAT_PUBLIC: case CAT_SYSTEM: case CAT_ENTITY: case CAT_DOCTYPE: this_item = sgml_malloc(sizeof *this_item); if (scan(src, buffer, sizeof buffer, 0) == EOF) break; if (t == CAT_PUBLIC) squish(buffer); this_item->next = 0; this_item->kind = t == CAT_SYSTEM ? t : t + override; this_item->target = istrdup(buffer); if (scan(src, buffer, sizeof buffer, 0) == EOF) break; if (is_absolute_path(buffer) || p == base) { this_item->replacement = istrdup(buffer); } else { (void) istrcpy(p, buffer); this_item->replacement = istrdup(base); } if (file->first_item == 0) { file->first_item = this_item; } else { file->last_item->next = this_item; } file->last_item = this_item; continue; case EOF: break; default: continue; } break; }
int _tcpOutductId(struct sockaddr *socketName, char *protocolName, char *ductName) { static Lyst tcpOutductIds = NULL; LystElt elt; TcpOutductId *id = NULL; int idNotFound = 1; CHKERR(socketName); if (tcpOutductIds == NULL) { tcpOutductIds = lyst_create_using(getIonMemoryMgr()); CHKERR(tcpOutductIds); lyst_delete_set(tcpOutductIds, deleteOutductId, NULL); } for (elt = lyst_first(tcpOutductIds); elt; elt = lyst_next(elt)) { id = (TcpOutductId *) lyst_data(elt); idNotFound = memcmp(&(id->socketName), socketName, sizeof(struct sockaddr)); if (idNotFound < 0) { continue; } /* The result of memcmp is either 0, indicating * matching TcpOutductId was found (that is, * idNotFound is false), or greater than 0 * indicating that no matching TcpOutductId was * found (that is, idNotFound is true). */ break; } if (protocolName == NULL) /* Deleting outduct ID. */ { if (!idNotFound) /* Found it. */ { lyst_delete(elt); } return 0; } if (*protocolName == 0) /* Retrieving outduct ID. */ { if (!idNotFound) /* Found it. */ { istrcpy(protocolName, id->protocolName, MAX_CL_PROTOCOL_NAME_LEN); istrcpy(ductName, id->ductName, MAX_CL_DUCT_NAME_LEN); } return 0; } /* Recording new TCP Outduct ID. */ if (!idNotFound) { putErrmsg("[?] Socket address is already in TcpOutductSocket \ list.", ductName); return -1; }
static void createIonConfigFiles() { uvast nodenbr = ION_NODE_NBR; char filenamebuf[80]; int fd; char *ionconfigLines[] = { "wmSize 300000\n", "configFlags 1\n", "heapWords 75000\n", "pathName /ion\n", }; int ionconfigLineCount = sizeof ionconfigLines / sizeof (char *); char *globalLines[] = { "a contact +0 +7200 19 19 100000\n" }; int globalLineCount = sizeof globalLines / sizeof (char *); char *ionsecrcLines[] = { "1\n", "a bspbabrule ipn:19.* ipn:19.* '' ''\n" }; int ionsecrcLineCount = sizeof ionsecrcLines / sizeof (char *); char *ltprcLines[] = { "1 20 64000\n", "a span 19 4 4000 4 4000 1084 2048 1 'pmqlso /ionpmq.19'\n", "w 1\n", "s 'pmqlsi /ionpmq.19'\n" }; int ltprcLineCount = sizeof ltprcLines / sizeof (char *); char *bprcLines[] = { "1\n", "a scheme ipn 'ipnfw' 'ipnadminep'\n", "a endpoint ipn:19.0 x\n", "a endpoint ipn:19.1 x\n", "a endpoint ipn:19.2 x\n", "a endpoint ipn:19.64 x\n", "a endpoint ipn:19.65 x\n", "a endpoint ipn:19.126 x\n", "a endpoint ipn:19.127 x\n", "a protocol ltp 1400 100\n", "a induct ltp 19 ltpcli\n", "a outduct ltp 19 ltpclo\n", "w 1\n" }; int bprcLineCount = sizeof bprcLines / sizeof (char *); char *ipnrcLines[] = { "a plan 19 ltp/19\n" }; int ipnrcLineCount = sizeof ipnrcLines / sizeof (char *); char linebuf[255]; char **line; int i; /* Keep all ION configuration files in one directory. */ if (mkdir("/ion", 0777) < 0) { perror("Can't create directory for config files"); return; } /* Create ionconfig file. */ isprintf(filenamebuf, sizeof filenamebuf, "/ion/node" UVAST_FIELDSPEC ".ionconfig", nodenbr); fd = iopen(filenamebuf, O_WRONLY | O_CREAT | O_TRUNC, 0777); if (fd < 0) { printf("Can't create .ionconfig file '%s'.\n", filenamebuf); return; } for (i = 0, line = ionconfigLines; i < ionconfigLineCount; line++, i++) { oK(iputs(fd, *line)); } close(fd); /* Create ionrc file. */ isprintf(filenamebuf, sizeof filenamebuf, "/ion/node" UVAST_FIELDSPEC ".ionrc", nodenbr); fd = iopen(filenamebuf, O_WRONLY | O_CREAT | O_TRUNC, 0777); if (fd < 0) { printf("Can't create .ionrc file '%s'.\n", filenamebuf); return; } isprintf(linebuf, sizeof linebuf, "1 " UVAST_FIELDSPEC " /ion/node" UVAST_FIELDSPEC ".ionconfig\ns\n", nodenbr, nodenbr); oK(iputs(fd, linebuf)); close(fd); /* Create global.ionrc file. */ istrcpy(filenamebuf, "/ion/global.ionrc", sizeof filenamebuf); fd = iopen(filenamebuf, O_WRONLY | O_CREAT | O_TRUNC, 0777); if (fd < 0) { printf("Can't create global.ionrc file '%s'.\n", filenamebuf); return; } for (i = 0, line = globalLines; i < globalLineCount; line++, i++) { oK(iputs(fd, *line)); } close(fd); /* Create ionsecrc file. */ isprintf(filenamebuf, sizeof filenamebuf, "/ion/node" UVAST_FIELDSPEC ".ionsecrc", nodenbr); fd = iopen(filenamebuf, O_WRONLY | O_CREAT | O_TRUNC, 0777); if (fd < 0) { printf("Can't create .ionsecrc file '%s'.\n", filenamebuf); return; } for (i = 0, line = ionsecrcLines; i < ionsecrcLineCount; line++, i++) { oK(iputs(fd, *line)); } close(fd); /* Create ltprc file. */ isprintf(filenamebuf, sizeof filenamebuf, "/ion/node" UVAST_FIELDSPEC ".ltprc", nodenbr); fd = iopen(filenamebuf, O_WRONLY | O_CREAT | O_TRUNC, 0777); if (fd < 0) { printf("Can't create .ltprc file '%s'.\n", filenamebuf); return; } for (i = 0, line = ltprcLines; i < ltprcLineCount; line++, i++) { oK(iputs(fd, *line)); } close(fd); /* Create ipnrc file. */ isprintf(filenamebuf, sizeof filenamebuf, "/ion/node" UVAST_FIELDSPEC ".ipnrc", nodenbr); fd = iopen(filenamebuf, O_WRONLY | O_CREAT | O_TRUNC, 0777); if (fd < 0) { printf("Can't create .ipnrc file '%s'.\n", filenamebuf); return; } for (i = 0, line = ipnrcLines; i < ipnrcLineCount; line++, i++) { oK(iputs(fd, *line)); } close(fd); /* Create bprc file. */ isprintf(filenamebuf, sizeof filenamebuf, "/ion/node" UVAST_FIELDSPEC ".bprc", nodenbr); fd = iopen(filenamebuf, O_WRONLY | O_CREAT | O_TRUNC, 0777); if (fd < 0) { printf("Can't create .bprc file '%s'.\n", filenamebuf); return; } for (i = 0, line = bprcLines; i < bprcLineCount; line++, i++) { oK(iputs(fd, *line)); } isprintf(linebuf, sizeof linebuf, "r 'ipnadmin /ion/node" UVAST_FIELDSPEC ".ipnrc'\ns\n", nodenbr); oK(iputs(fd, linebuf)); close(fd); #ifndef NASA_PROTECTED_FLIGHT_CODE /* Create cfdprc file. */ isprintf(filenamebuf, sizeof filenamebuf, "/ion/node" UVAST_FIELDSPEC ".cfdprc", nodenbr); fd = iopen(filenamebuf, O_WRONLY | O_CREAT | O_TRUNC, 0777); if (fd < 0) { printf("Can't create .cfdprc file '%s'.\n", filenamebuf); return; } oK(iputs(fd, "1\ns bputa\n")); close(fd); #endif }
static int udpMamsInit(MamsInterface *tsif) { unsigned short portNbr; unsigned int ipAddress; char hostName[MAXHOSTNAMELEN + 1]; struct sockaddr socketName; struct sockaddr_in *inetName; socklen_t nameLength; int fd; char endpointNameText[32]; int eptLen; long longfd; parseSocketSpec(tsif->endpointSpec, &portNbr, &ipAddress); //printf("parsed endpoint spec to port %d address %d.\n", portNbr, ipAddress); if (ipAddress == 0) { getNameOfHost(hostName, sizeof hostName); ipAddress = getInternetAddress(hostName); } else { if (getInternetHostName(ipAddress, hostName) == NULL) { putErrmsg("Unknown host in endpoint.", tsif->endpointSpec); return -1; } } portNbr = htons(portNbr); ipAddress = htonl(ipAddress); memset((char *) &socketName, 0, sizeof socketName); inetName = (struct sockaddr_in *) &socketName; inetName->sin_family = AF_INET; inetName->sin_port = portNbr; memcpy((char *) &(inetName->sin_addr.s_addr), (char *) &ipAddress, 4); fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); if (fd < 0) { putSysErrmsg("udpts can't open MAMS SAP", NULL); return -1; } nameLength = sizeof(struct sockaddr); if (reUseAddress(fd) || bind(fd, &socketName, nameLength) < 0 || getsockname(fd, &socketName, &nameLength) < 0) { putSysErrmsg("udpts can't initialize AMS SAP", NULL); return -1; } portNbr = inetName->sin_port; portNbr = ntohs(portNbr); memcpy((char *) &ipAddress, (char *) &(inetName->sin_addr.s_addr), 4); ipAddress = ntohl(ipAddress); isprintf(endpointNameText, sizeof endpointNameText, "%s:%hu", hostName, portNbr); //printf("resulting ept is '%s'.\n", endpointNameText); eptLen = strlen(endpointNameText) + 1; tsif->ept = MTAKE(eptLen); if (tsif->ept == NULL) { close(fd); putSysErrmsg(NoMemoryMemo, NULL); return -1; } istrcpy(tsif->ept, endpointNameText, eptLen); longfd = fd; tsif->sap = (void *) longfd; return 0; }
void sptrace_report(PsmPartition trace, int verbose) { PsmAddress traceHeaderAddress; TraceHeader *trh; PsmAddress elt; TraceItem *item; char *fileName; char buffer[384]; int len; char buf2[256]; if (!trace) return; traceHeaderAddress = psm_get_root(trace); trh = (TraceHeader *) psp(trace, traceHeaderAddress); CHKVOID(trh); for (elt = sm_list_first(trace, trh->log); elt; elt = sm_list_next(trace, elt)) { item = (TraceItem *) psp(trace, sm_list_data(trace, elt)); CHKVOID(item); fileName = (char *) psp(trace, item->fileName); isprintf(buffer, sizeof buffer, "(%5d) at line %6d of %32.32s \ (pid %5d): ", item->opNbr, item->lineNbr, fileName, item->taskId); len = strlen(buffer); switch (item->opType) { case OP_ALLOCATE: isprintf(buf2, sizeof buf2, "allocated object %6ld of \ size %6d, ", item->objectAddress, item->objectSize); istrcpy(buffer + len, buf2, sizeof buffer - len); if (item->refOpNbr == 0) { len = strlen(buffer); istrcpy(buffer + len, "never freed", sizeof buffer - len); } else { if (!verbose) { continue; } len = strlen(buffer); fileName = (char *) psp(trace, item->refFileName); isprintf(buf2, sizeof buf2, "freed in (%5d) \ at line %6d of %32.32s (pid %5d)", item->refOpNbr, item->refLineNbr, fileName, item->refTaskId); istrcpy(buffer + len, buf2, sizeof buffer - len); } break; case OP_MEMO: isprintf(buf2, sizeof buf2, "re %6ld, '%.128s'", item->objectAddress, (char *) psp(trace, item->msg)); istrcpy(buffer + len, buf2, sizeof buffer - len); break; case OP_FREE: isprintf(buf2, sizeof buf2, "freed object %6ld, ", item->objectAddress); istrcpy(buffer + len, buf2, sizeof buffer - len); if (item->refOpNbr == 0) { len = strlen(buffer); istrcpy(buffer + len, "not currently allocated", sizeof buffer - len); } else { if (!verbose) { continue; } len = strlen(buffer); fileName = (char *) psp(trace, item->refFileName); CHKVOID(fileName); isprintf(buf2, sizeof buf2, "allocated in \ (%5d) at line %6d of %32.32s (pid %5d)", item->refOpNbr, item->refLineNbr, fileName, item->refTaskId); istrcpy(buffer + len, buf2, sizeof buffer - len); } break; } writeMemo(buffer); } }
PsmPartition sptrace_start(int smkey, int smsize, char *sm, PsmPartition trace, char *name) { int nameLen; int smid; PsmMgtOutcome outcome; TraceHeader *trh; PsmAddress traceHeaderAddress; CHKNULL(trace); CHKNULL(smsize > 0); CHKNULL(name); if ((nameLen = strlen(name)) < 1 || nameLen > 31) { sptracePrint("start: name must be 1-31 characters."); return NULL; } /* Attach to shared memory used for trace operations. */ if (sm_ShmAttach(smkey, smsize, &sm, &smid) < 0) { sptracePrint("start: can't attach shared memory for trace."); return NULL; } /* Manage the shared memory region. "Trace" argument * is normally NULL. */ if (psm_manage(sm, smsize, name, &trace, &outcome) < 0) { sptracePrint("start: shared memory mgt failed."); return NULL; } switch (outcome) { case Refused: sptracePrint("start: can't psm_manage shared memory."); return NULL; case Redundant: trh = (TraceHeader *) psp(trace, psm_get_root(trace)); if (trh == NULL || strcmp(name, trh->name) != 0) { sptracePrint("start: shared memory used otherwise."); return NULL; } return trace; /* Trace already started. */ default: break; } /* Initialize the shared memory region for tracing. */ traceHeaderAddress = psm_zalloc(trace, sizeof(TraceHeader)); if (traceHeaderAddress == 0) { sptracePrint("start: not enough memory for header."); sm_ShmDetach(sm); sm_ShmDestroy(smid); return NULL; } oK(psm_set_root(trace, traceHeaderAddress)); trh = (TraceHeader *) psp(trace, traceHeaderAddress); CHKNULL(trh); trh->traceSmId = smid; memset(trh->name, 0, sizeof trh->name); istrcpy(trh->name, name, sizeof trh->name); trh->opCount = 0; trh->files = sm_list_create(trace); if (trh->files == 0) { sptracePrint("start: not enough memory for files list."); sm_ShmDetach(sm); sm_ShmDestroy(smid); return NULL; } trh->log = sm_list_create(trace); if (trh->log == 0) { sptracePrint("start: not enough memory for log."); sm_ShmDetach(sm); sm_ShmDestroy(smid); return NULL; } return trace; }
int psm_manage(char *start, u_long length, char *name, PsmPartition *psmp, PsmMgtOutcome *outcome) { PsmPartition partition; PartitionMap *map; CHKERR(outcome); *outcome = Refused; CHKERR(start != NULL); if ((((unsigned long) start) % LG_OHD_SIZE) != 0) { putErrmsg("Starting address not double-word-aligned.", utoa((unsigned long) start)); return -1; /* Start address misaligned. */ } /* Acquire handle to space management structure. */ partition = *psmp; /* Dynamically allocate space management structure as * necessary. */ if (partition == NULL) { partition = (PsmPartition) acquireSystemMemory(sizeof(PsmView)); CHKERR(partition != NULL); partition->freeNeeded = 1; } else { partition->freeNeeded = 0; } partition->space = start; partition->trace = NULL; map = (PartitionMap *) (partition->space); if (map->status == MANAGED) { *psmp = partition; sm_SemUnwedge(map->semaphore, 3); *outcome = Redundant; return 0; } /* Need to manage and possibly initialize the partition. */ if (length % LG_OHD_SIZE) { if (partition->freeNeeded) free(partition); putErrmsg("Partition length is not an integral number of \ double words.", utoa(length)); return -1; } if (length < sizeof(PartitionMap)) { if (partition->freeNeeded) free(partition); putErrmsg("Partition length is less than partition map size.", utoa(length)); return -1; /* Partition can't contain map. */ } if (name == NULL) { if (partition->freeNeeded) free(partition); putErrmsg("Partition name is NULL.", NULL); return -1; } if (strlen(name) > 31) { if (partition->freeNeeded) free(partition); putErrmsg("Partition name length exceeds 31.", name); return -1; } switch (map->status) { case INITIALIZED: if (map->partitionSize != length) { if (partition->freeNeeded) free(partition); putErrmsg("Asserted partition length doesn't match \ actual length.", itoa(map->partitionSize)); return -1; /* Size mismatch. */ } if (strcmp(map->name, name) != 0) { if (partition->freeNeeded) free(partition); putErrmsg("Asserted partition name doesn't match \ actual name.", map->name); return -1; /* Name mismatch. */ } break; /* Proceed with managing the partition. */ default: /* Must initialize the partition. */ map->directory = 0; map->desperate = 0; map->partitionSize = length; istrcpy(map->name, name, sizeof map->name); map->startOfSmallPool = sizeof(PartitionMap); map->endOfSmallPool = map->startOfSmallPool; memset((char *) (map->firstSmallFree), 0, sizeof map->firstSmallFree); map->endOfLargePool = length; map->startOfLargePool = map->endOfLargePool; memset((char *) (map->firstLargeFree), 0, sizeof map->firstLargeFree); map->unassignedSpace = map->startOfLargePool - map->endOfSmallPool; map->traceKey = sm_GetUniqueKey(); map->traceSize = 0; } map->semaphore = sm_SemCreate(SM_NO_KEY, SM_SEM_FIFO); if (map->semaphore < 0) { if (partition->freeNeeded) free(partition); putErrmsg("Can't create semaphore for partition map.", NULL); return -1; } map->ownerTask = -1; map->depth = 0; map->status = MANAGED; *psmp = partition; *outcome = Okay; return 0; }