static t_stat net_attach(UNIT *uptr, char *cptr) { uint32 i; char host[CBUFSIZE], port[CBUFSIZE]; t_stat r; r = sim_parse_addr (cptr, host, sizeof(host), "localhost", port, sizeof(port), "3000", NULL); if (r != SCPE_OK) return SCPE_ARG; net_reset(&net_dev); for (i = 0; i <= MAX_CONNECTIONS; i++) serviceDescriptor[i].ioSocket = 0; if (net_unit.flags & UNIT_SERVER) { net_unit.wait = NET_INIT_POLL_SERVER; serviceDescriptor[1].masterSocket = sim_master_sock(cptr, NULL); if (serviceDescriptor[1].masterSocket == INVALID_SOCKET) return SCPE_IOERR; } else { net_unit.wait = NET_INIT_POLL_CLIENT; serviceDescriptor[0].ioSocket = sim_connect_sock(cptr, "localhost", "3000"); if (serviceDescriptor[0].ioSocket == INVALID_SOCKET) return SCPE_IOERR; } net_unit.flags |= UNIT_ATT; net_unit.filename = (char *) calloc(1, strlen(cptr)+1); /* alloc name buf */ if (net_unit.filename == NULL) return SCPE_MEM; strcpy(net_unit.filename, cptr); /* save name */ return SCPE_OK; }
static int udp_parse_remote (int link, char * premote) { // This routine will parse a remote address string in any of these forms - // // llll:w.x.y.z:rrrr // llll:name.domain.com:rrrr // llll::rrrr // w.x.y.z:rrrr // name.domain.com:rrrr // // In all examples, "llll" is the local port number that we use for listening, // and "rrrr" is the remote port number that we use for transmitting. The // local port is optional and may be omitted, in which case it defaults to the // same as the remote port. This works fine if the other IMP is actually on // a different host, but don't try that with localhost - you'll be talking to // yourself!! In both cases, "w.x.y.z" is a dotted IP for the remote machine // and "name.domain.com" is its name (which will be looked up to get the IP). // If the host name/IP is omitted then it defaults to "localhost". char * end; int32_t lportno, rport; char host [64], port [16]; if (* premote == '\0') return -1; memset (udp_links [link] . lport, 0, sizeof (udp_links [link] . lport)); memset (udp_links [link] . rhost, 0, sizeof (udp_links [link] . rhost)); memset (udp_links [link] . rport, 0, sizeof (udp_links [link] . rport)); // Handle the llll::rrrr case first if (2 == sscanf (premote, "%d::%d", & lportno, & rport)) { if ((lportno < 1) || (lportno >65535) || (rport < 1) || (rport >65535)) return -1; sprintf (udp_links [link] . lport, "%d", lportno); udp_links [link] . lportno = lportno; sprintf (udp_links [link] . rhost, "localhost"); sprintf (udp_links [link] . rport, "%d", rport); udp_links [link] . rportno = rport; return 0; } // Look for the local port number and save it away. lportno = strtoul (premote, & end, 10); if ((* end == ':') && (lportno > 0)) { sprintf (udp_links [link] . lport, "%d", lportno); udp_links [link] . lportno = lportno; premote = end + 1; } if (sim_parse_addr (premote, host, sizeof (host), "localhost", port, sizeof (port), NULL, NULL)) return -1; sprintf (udp_links [link] . rhost, "%s", host); sprintf (udp_links [link] . rport, "%s", port); udp_links [link] . rportno = atoi (port); if (udp_links [link] . lport [0] == '\0') { strcpy (udp_links [link] . lport, port); udp_links [link] . lportno = atoi (port); } if ((strcmp (udp_links [link] . lport, port) == 0) && (strcmp ("localhost", host) == 0)) fprintf (stderr, "WARNING - use different transmit and receive ports!\n"); return 0; }