Пример #1
0
int
nat_RedirectAddr(struct cmdargs const *arg)
{
  if (!arg->bundle->NatEnabled) {
    prompt_Printf(arg->prompt, "nat not enabled\n");
    return 1;
  } else if (arg->argc == arg->argn+2) {
    int error;
    struct in_addr localaddr, aliasaddr;
    struct alias_link *link;

    error = StrToAddr(arg->argv[arg->argn], &localaddr);
    if (error) {
      prompt_Printf(arg->prompt, "address redirect: invalid local address\n");
      return 1;
    }
    error = StrToAddr(arg->argv[arg->argn+1], &aliasaddr);
    if (error) {
      prompt_Printf(arg->prompt, "address redirect: invalid alias address\n");
      prompt_Printf(arg->prompt, "usage: nat %s %s\n", arg->cmd->name,
                    arg->cmd->syntax);
      return 1;
    }
    link = LibAliasRedirectAddr(la, localaddr, aliasaddr);
    if (link == NULL) {
      prompt_Printf(arg->prompt, "address redirect: packet aliasing"
                    " engine error\n");
      prompt_Printf(arg->prompt, "usage: nat %s %s\n", arg->cmd->name,
                    arg->cmd->syntax);
    }
  } else
    return -1;

  return 0;
}
Пример #2
0
static int
setup_redir_proto(char *buf, int *ac, char ***av)
{
	struct cfg_redir *r;
	struct protoent *protoent;
	size_t space;

	r = (struct cfg_redir *)buf;
	r->mode = REDIR_PROTO;
	/* Skip cfg_redir at beginning of buf. */
	buf = &buf[sizeof(struct cfg_redir)];
	space = sizeof(struct cfg_redir);

	/*
	 * Extract protocol.
	 */
	protoent = getprotobyname(**av);
	if (protoent == NULL)
		errx(EX_DATAERR, "redirect_proto: unknown protocol %s", **av);
	else
		r->proto = protoent->p_proto;

	(*av)++; (*ac)--;

	/*
	 * Extract local address.
	 */
	StrToAddr(**av, &r->laddr);

	(*av)++; (*ac)--;

	/*
	 * Extract optional public address.
	 */
	if (*ac == 0) {
		r->paddr.s_addr = INADDR_ANY;
		r->raddr.s_addr = INADDR_ANY;
	} else {
		/* see above in setup_redir_port() */
		if (isdigit(***av)) {
			StrToAddr(**av, &r->paddr);
			(*av)++; (*ac)--;

			/*
			 * Extract optional remote address.
			 */
			/* see above in setup_redir_port() */
			if (*ac != 0 && isdigit(***av)) {
				StrToAddr(**av, &r->raddr);
				(*av)++; (*ac)--;
			}
		}
	}

	return (space);
}
Пример #3
0
void
SetupProtoRedirect(const char* parms)
{
	char		buf[128];
	char*		ptr;
	struct in_addr	localAddr;
	struct in_addr	publicAddr;
	struct in_addr	remoteAddr;
	int		proto;
	char*		protoName;
	struct protoent *protoent;

	strcpy (buf, parms);
/*
 * Extract protocol.
 */
	protoName = strtok(buf, " \t");
	if (!protoName)
		errx(1, "redirect_proto: missing protocol");

	protoent = getprotobyname(protoName);
	if (protoent == NULL)
		errx(1, "redirect_proto: unknown protocol %s", protoName);
	else
		proto = protoent->p_proto;
/*
 * Extract local address.
 */
	ptr = strtok(NULL, " \t");
	if (!ptr)
		errx(1, "redirect_proto: missing local address");
	else
		StrToAddr(ptr, &localAddr);
/*
 * Extract optional public address.
 */
	ptr = strtok(NULL, " \t");
	if (ptr)
		StrToAddr(ptr, &publicAddr);
	else
		publicAddr.s_addr = INADDR_ANY;
/*
 * Extract optional remote address.
 */
	ptr = strtok(NULL, " \t");
	if (ptr)
		StrToAddr(ptr, &remoteAddr);
	else
		remoteAddr.s_addr = INADDR_ANY;
/*
 * Create aliasing link.
 */
	(void)PacketAliasRedirectProto(localAddr, remoteAddr, publicAddr,
				       proto);
}
Пример #4
0
void
SetupAddressRedirect(const char *parms)
{
	char		buf[128];
	char*		ptr;
	char*		separator;
	struct in_addr	localAddr;
	struct in_addr	publicAddr;
	char*		serverPool;
	struct alias_link *alink;

	strcpy(buf, parms);
/*
 * Extract local address.
 */
	ptr = strtok(buf, " \t");
	if (!ptr)
		errx(1, "redirect_address: missing local address");

	separator = strchr(ptr, ',');
	if (separator) {		/* LSNAT redirection syntax. */
		localAddr.s_addr = INADDR_NONE;
		serverPool = ptr;
	} else {
		StrToAddr(ptr, &localAddr);
		serverPool = NULL;
	}
/*
 * Extract public address.
 */
	ptr = strtok(NULL, " \t");
	if (!ptr)
		errx(1, "redirect_address: missing public address");

	StrToAddr(ptr, &publicAddr);
	alink = PacketAliasRedirectAddr(localAddr, publicAddr);

/*
 * Setup LSNAT server pool.
 */
	if (serverPool != NULL && alink != NULL) {
		ptr = strtok(serverPool, ",");
		while (ptr != NULL) {
			StrToAddr(ptr, &localAddr);
			PacketAliasAddServer(alink, localAddr, htons(~0));
			ptr = strtok(NULL, ",");
		}
	}
}
Пример #5
0
/* open a TCP connection
 */
na_tcp NATCPopen(na_tcpreadp *callback, void *context, char *host, long port, short flags)
{
	int i, err = NATCP_notcpbuf;
	OSErr resolve = noErr;
	tcpinfo *tcp;
	
	if ((tcp = getTCPbuf(callback, context, &i)) == NULL) return (-1);
	if (flags & NATCP_server) tcp->server = 1;
	tcp->port = port;
	tcp->pb.csCode = TCPCreate;
	tcp->pb.csParam.create.rcvBuff = (Ptr) tcp->buf;
	tcp->pb.csParam.create.rcvBuffLen = (*tcpstate)->streamsize;
	tcp->pb.csParam.create.notifyProc = myTCPNotifyProc;
	tcp->pb.csParam.create.userDataPtr = (Ptr) tcp;
	PBControl((ParmBlkPtr)&tcp->pb, false);
	if (tcp->pb.ioResult == 0) {
		tcp->state = TCP_RESOLVE;
		tcp->stream = tcp->pb.tcpStream;
		/* a server isn't required to have a hostname */
		if (!host && tcp->server) return (i);
		tcp->dnrdone = 0;
		resolve = StrToAddr(host, &tcp->host, addrproc, (char *) tcp);
		if (resolve == noErr) tcp->dnrdone = 1;
		if (resolve == cacheFault || resolve == noErr) {
			return (i);
		}
		err = NATCP_nohost;
	}
	DisposPtr((Ptr) tcp);
	(*tcpstate)->tcpbufs[i] = NULL;
	(*callback)(context, -1, err, resolve, NULL);
	
	return (-1);
}
Пример #6
0
static int
setup_redir_addr(char *buf, int *ac, char ***av)
{
	struct cfg_redir *r;
	char *sep;
	size_t space;

	r = (struct cfg_redir *)buf;
	r->mode = REDIR_ADDR;
	/* Skip cfg_redir at beginning of buf. */
	buf = &buf[sizeof(struct cfg_redir)];
	space = sizeof(struct cfg_redir);

	/* Extract local address. */
	if (strchr(**av, ',') != NULL) {
		struct cfg_spool *spool;

		/* Setup LSNAT server pool. */
		r->laddr.s_addr = INADDR_NONE;
		sep = strtok(**av, ",");
		while (sep != NULL) {
			spool = (struct cfg_spool *)buf;
			space += sizeof(struct cfg_spool);
			StrToAddr(sep, &spool->addr);
			spool->port = ~0;
			r->spool_cnt++;
			/* Point to the next possible cfg_spool. */
			buf = &buf[sizeof(struct cfg_spool)];
			sep = strtok(NULL, ",");
		}
	} else
		StrToAddr(**av, &r->laddr);
	(*av)++; (*ac)--;

	/* Extract public address. */
	StrToAddr(**av, &r->paddr);
	(*av)++; (*ac)--;

	return (space);
}
Пример #7
0
int StrToAddrAndPortRange (const char* str, struct in_addr* addr, char* proto, port_range *portRange)
{
	char*	ptr;

	ptr = strchr (str, ':');
	if (!ptr)
		errx (1, "%s is missing port number", str);

	*ptr = '\0';
	++ptr;

	StrToAddr (str, addr);
	return StrToPortRange (ptr, proto, portRange);
}
Пример #8
0
static int
StrToAddrAndPort(const char *str, struct in_addr *addr, u_short *low,
                 u_short *high, const char *proto)
{
  char *colon;
  int res;

  colon = strchr(str, ':');
  if (!colon) {
    log_Printf(LogWARN, "StrToAddrAndPort: %s is missing port number.\n", str);
    return -1;
  }

  *colon = '\0';		/* Cheat the const-ness ! */
  res = StrToAddr(str, addr);
  *colon = ':';			/* Cheat the const-ness ! */
  if (res != 0)
    return -1;

  return StrToPortRange(colon + 1, low, high, proto);
}
Пример #9
0
void SetupPortRedirect (const char* parms)
{
	char		buf[128];
	char*		ptr;
	char*		serverPool;
	struct in_addr	localAddr;
	struct in_addr	publicAddr;
	struct in_addr	remoteAddr;
	port_range      portRange;
	u_short         localPort      = 0;
	u_short         publicPort     = 0;
	u_short         remotePort     = 0;
	u_short         numLocalPorts  = 0;
	u_short         numPublicPorts = 0;
	u_short         numRemotePorts = 0;
	int		proto;
	char*		protoName;
	char*		separator;
	int             i;
	struct alias_link *link = NULL;

	strcpy (buf, parms);
/*
 * Extract protocol.
 */
	protoName = strtok (buf, " \t");
	if (!protoName)
		errx (1, "redirect_port: missing protocol");

	proto = StrToProto (protoName);
/*
 * Extract local address.
 */
	ptr = strtok (NULL, " \t");
	if (!ptr)
		errx (1, "redirect_port: missing local address");

	separator = strchr(ptr, ',');
	if (separator) {		/* LSNAT redirection syntax. */
		localAddr.s_addr = INADDR_NONE;
		localPort = ~0;
		numLocalPorts = 1;
		serverPool = ptr;
	} else {
		if ( StrToAddrAndPortRange (ptr, &localAddr, protoName, &portRange) != 0 )
			errx (1, "redirect_port: invalid local port range");

		localPort     = GETLOPORT(portRange);
		numLocalPorts = GETNUMPORTS(portRange);
		serverPool = NULL;
	}

/*
 * Extract public port and optionally address.
 */
	ptr = strtok (NULL, " \t");
	if (!ptr)
		errx (1, "redirect_port: missing public port");

	separator = strchr (ptr, ':');
	if (separator) {
	        if (StrToAddrAndPortRange (ptr, &publicAddr, protoName, &portRange) != 0 )
		        errx (1, "redirect_port: invalid public port range");
	}
	else {
		publicAddr.s_addr = INADDR_ANY;
		if (StrToPortRange (ptr, protoName, &portRange) != 0)
		        errx (1, "redirect_port: invalid public port range");
	}

	publicPort     = GETLOPORT(portRange);
	numPublicPorts = GETNUMPORTS(portRange);

/*
 * Extract remote address and optionally port.
 */
	ptr = strtok (NULL, " \t");
	if (ptr) {
		separator = strchr (ptr, ':');
		if (separator) {
		        if (StrToAddrAndPortRange (ptr, &remoteAddr, protoName, &portRange) != 0)
			        errx (1, "redirect_port: invalid remote port range");
		} else {
		        SETLOPORT(portRange, 0);
			SETNUMPORTS(portRange, 1);
			StrToAddr (ptr, &remoteAddr);
		}
	}
	else {
	        SETLOPORT(portRange, 0);
		SETNUMPORTS(portRange, 1);
		remoteAddr.s_addr = INADDR_ANY;
	}

	remotePort     = GETLOPORT(portRange);
	numRemotePorts = GETNUMPORTS(portRange);

/*
 * Make sure port ranges match up, then add the redirect ports.
 */
	if (numLocalPorts != numPublicPorts)
	        errx (1, "redirect_port: port ranges must be equal in size");

	/* Remote port range is allowed to be '0' which means all ports. */
	if (numRemotePorts != numLocalPorts && (numRemotePorts != 1 || remotePort != 0))
	        errx (1, "redirect_port: remote port must be 0 or equal to local port range in size");

	for (i = 0 ; i < numPublicPorts ; ++i) {
	        /* If remotePort is all ports, set it to 0. */
	        u_short remotePortCopy = remotePort + i;
	        if (numRemotePorts == 1 && remotePort == 0)
		        remotePortCopy = 0;

		link = PacketAliasRedirectPort (localAddr,
						htons(localPort + i),
						remoteAddr,
						htons(remotePortCopy),
						publicAddr,
						htons(publicPort + i),
						proto);
	}

/*
 * Setup LSNAT server pool.
 */
	if (serverPool != NULL && link != NULL) {
		ptr = strtok(serverPool, ",");
		while (ptr != NULL) {
			if (StrToAddrAndPortRange(ptr, &localAddr, protoName, &portRange) != 0)
				errx(1, "redirect_port: invalid local port range");

			localPort = GETLOPORT(portRange);
			if (GETNUMPORTS(portRange) != 1)
				errx(1, "redirect_port: local port must be single in this context");
			PacketAliasAddServer(link, localAddr, htons(localPort));
			ptr = strtok(NULL, ",");
		}
	}
}
Пример #10
0
static void ParseOption (const char* option, const char* parms)
{
	int			i;
	struct OptionInfo*	info;
	int			yesNoValue;
	int			aliasValue;
	int			numValue;
	u_short			uNumValue;
	const char*		strValue;
	struct in_addr		addrValue;
	int			max;
	char*			end;
	CODE* 			fac_record = NULL;
/*
 * Find option from table.
 */
	max = sizeof (optionTable) / sizeof (struct OptionInfo);
	for (i = 0, info = optionTable; i < max; i++, info++) {

		if (!strcmp (info->name, option))
			break;

		if (info->shortName)
			if (!strcmp (info->shortName, option))
				break;
	}

	if (i >= max) {

		warnx ("unknown option %s", option);
		Usage ();
	}

	uNumValue	= 0;
	yesNoValue	= 0;
	numValue	= 0;
	strValue	= NULL;
/*
 * Check parameters.
 */
	switch (info->parm) {
	case YesNo:
		if (!parms)
			parms = "yes";

		if (!strcmp (parms, "yes"))
			yesNoValue = 1;
		else
			if (!strcmp (parms, "no"))
				yesNoValue = 0;
			else
				errx (1, "%s needs yes/no parameter", option);
		break;

	case Service:
		if (!parms)
			errx (1, "%s needs service name or "
				 "port number parameter",
				 option);

		uNumValue = StrToPort (parms, "divert");
		break;

	case Numeric:
		if (parms)
			numValue = strtol (parms, &end, 10);
		else
			end = NULL;

		if (end == parms)
			errx (1, "%s needs numeric parameter", option);
		break;

	case String:
		strValue = parms;
		if (!strValue)
			errx (1, "%s needs parameter", option);
		break;

	case None:
		if (parms)
			errx (1, "%s does not take parameters", option);
		break;

	case Address:
		if (!parms)
			errx (1, "%s needs address/host parameter", option);

		StrToAddr (parms, &addrValue);
		break;
	}

	switch (info->type) {
	case PacketAliasOption:
	
		aliasValue = yesNoValue ? info->packetAliasOpt : 0;
		PacketAliasSetMode (aliasValue, info->packetAliasOpt);
		break;

	case Verbose:
		verbose = yesNoValue;
		break;

	case DynamicMode:
		dynamicMode = yesNoValue;
		break;

	case InPort:
		inPort = uNumValue;
		break;

	case OutPort:
		outPort = uNumValue;
		break;

	case Port:
		inOutPort = uNumValue;
		break;

	case AliasAddress:
		memcpy (&aliasAddr, &addrValue, sizeof (struct in_addr));
		break;

	case TargetAddress:
		PacketAliasSetTarget(addrValue);
		break;

	case RedirectPort:
		SetupPortRedirect (strValue);
		break;

	case RedirectProto:
		SetupProtoRedirect(strValue);
		break;

	case RedirectAddress:
		SetupAddressRedirect (strValue);
		break;

	case ProxyRule:
		PacketAliasProxyRule (strValue);
		break;

	case InterfaceName:
		if (ifName)
			free (ifName);

		ifName = strdup (strValue);
		break;

	case ConfigFile:
		ReadConfigFile (strValue);
		break;

	case LogDenied:
		logDropped = 1;
		break;

	case LogFacility:

		fac_record = facilitynames;
		while (fac_record->c_name != NULL) {

			if (!strcmp (fac_record->c_name, strValue)) {

				logFacility = fac_record->c_val;
				break;

			}
			else
				fac_record++;
		}

		if(fac_record->c_name == NULL)
			errx(1, "Unknown log facility name: %s", strValue);	

		break;

	case PunchFW:
		SetupPunchFW(strValue);
		break;
	}
}
Пример #11
0
int
nat_RedirectProto(struct cmdargs const *arg)
{
  if (!arg->bundle->NatEnabled) {
    prompt_Printf(arg->prompt, "nat not enabled\n");
    return 1;
  } else if (arg->argc >= arg->argn + 2 && arg->argc <= arg->argn + 4) {
    struct in_addr localIP, publicIP, remoteIP;
    struct alias_link *link;
    struct protoent *pe;
    int error;
    unsigned len;

    len = strlen(arg->argv[arg->argn]);
    if (len == 0) {
      prompt_Printf(arg->prompt, "proto redirect: invalid protocol\n");
      return 1;
    }
    if (strspn(arg->argv[arg->argn], "01234567") == len)
      pe = getprotobynumber(atoi(arg->argv[arg->argn]));
    else
      pe = getprotobyname(arg->argv[arg->argn]);
    if (pe == NULL) {
      prompt_Printf(arg->prompt, "proto redirect: invalid protocol\n");
      return 1;
    }

    error = StrToAddr(arg->argv[arg->argn + 1], &localIP);
    if (error) {
      prompt_Printf(arg->prompt, "proto redirect: invalid src address\n");
      return 1;
    }

    if (arg->argc >= arg->argn + 3) {
      error = StrToAddr(arg->argv[arg->argn + 2], &publicIP);
      if (error) {
        prompt_Printf(arg->prompt, "proto redirect: invalid alias address\n");
        prompt_Printf(arg->prompt, "usage: nat %s %s\n", arg->cmd->name,
                      arg->cmd->syntax);
        return 1;
      }
    } else
      publicIP.s_addr = INADDR_ANY;

    if (arg->argc == arg->argn + 4) {
      error = StrToAddr(arg->argv[arg->argn + 2], &remoteIP);
      if (error) {
        prompt_Printf(arg->prompt, "proto redirect: invalid dst address\n");
        prompt_Printf(arg->prompt, "usage: nat %s %s\n", arg->cmd->name,
                      arg->cmd->syntax);
        return 1;
      }
    } else
      remoteIP.s_addr = INADDR_ANY;

    link = LibAliasRedirectProto(la, localIP, remoteIP, publicIP, pe->p_proto);
    if (link == NULL) {
      prompt_Printf(arg->prompt, "proto redirect: packet aliasing"
                    " engine error\n");
      prompt_Printf(arg->prompt, "usage: nat %s %s\n", arg->cmd->name,
                    arg->cmd->syntax);
    }
  } else
    return -1;

  return 0;
}
Пример #12
0
        err = OpenDriver("\p.IPP", &refnum);
        if (err != noErr) {
            printf("Error initializing driver.\n");
            return IMCOMM_RET_ERROR;
        }
        err = OpenResolver(NULL);
        if (err != noErr) {
            printf("Error initializing resolver.\n");
            return IMCOMM_RET_ERROR;
        }
        mactcp_lookupdone_upp = NewResultProc(&mactcp_lookupdone);
        mactcp_asr_upp = NewTCPNotifyProc(&mactcp_asr);
        initialized = 1;
    }
    err =
        StrToAddr("login.oscar.aol.com", &hostinfo, mactcp_lookupdone_upp,
                  (char *) &resolverDone);
    if (err == cacheFault)
        while (!resolverDone)
            continue;

    upb.ioCRefNum = refnum;
    upb.csCode = UDPMaxMTUSize;
    upb.csParam.mtu.remoteHost = hostinfo.addr[0];
    upb.csParam.mtu.userDataPtr = (Ptr) handle;
    err = PBControlSync((ParmBlkPtr) & upb);
    if (err != noErr) {
        printf("Error retrieving MTU.\n");
        return IMCOMM_RET_ERROR;
    }
    buflen = upb.csParam.mtu.mtuSize * 4 + 1024;
    if (buflen < 4096)
Пример #13
0
/*
** View the source for the lines specified.
*/
int CommandView(char **ptrs)
{
DebugModule    *module;
char	       *srcEnd;
ULONG		addr;
ULONG		lineNum;
char		funcName[MAX_FUNCNAME];
char		sourceName[CCHMAXPATH];

    /*
    ** Get the common data.
    */
    module = FindModule(debugBuffer.MTE, NULL);
    FindSource(module, Linearize(debugBuffer.EIP, debugBuffer.CS),
	       funcName, sourceName, &lineNum);

    /*
    ** View the next lines to be displayed.
    */
    if(ptrs[2] == NULL) {
	DisplaySource(module, sourceName, GetLastLine(module) + 5);
	return -1;
    }

    /*
    ** View a line.
    */
    if(ptrs[2][0] == '.') {

	/*
	** Find the line number or the file name/line number
	*/
	if(isdigit(ptrs[2][1])) {
	    lineNum = atol(&ptrs[2][1]);
	} else {
	    strcpy(sourceName, &ptrs[2][1]);
	    *strrchr(sourceName, ':') = 0;
	    lineNum = atol(strrchr(ptrs[2], ':') + 1);
	}
	DisplaySource(module, sourceName, lineNum);
	return -1;
    }

    /*
    ** Get a view at a given offset.
    */
    if(isxdigit(ptrs[2][0])) {
	/*
	** Find the module associated with the address specified.
	*/
	debugBuffer.Addr = addr = StrToAddr(ptrs[2], TOADDR_CODE);
	DispatchCommand(DBG_C_AddrToObject);

	/*
	** Find the module/source associated with the information given.
	*/
	module = FindModule(debugBuffer.MTE, NULL);
	FindSource(NULL, addr, funcName, sourceName, &lineNum);
	DisplaySource(module, sourceName, lineNum);
	return -1;
    }

    /*
    ** ERROR!
    */
    fprintf(logFile, "Invalid syntax\n");
    return -1;
}
Пример #14
0
/*
** View the assembler for the address/line specified.
*/
int CommandUnassemble(char **ptrs)
{
DebugModule    *module;
View	       *viewData;
char	       *srcEnd;
ULONG		addr;
int		lineNum;
int		is32Bit;
char		sourceName[CCHMAXPATH];

    /*
    ** Get the common data.
    */
    module   = FindModule(debugBuffer.MTE, NULL);
    viewData = (View *) module->ViewData;
    if(viewData == NULL) {
	viewData = module->ViewData = calloc(sizeof(View), 1);
	viewData->lastSource = strdup("");
	viewData->basePath   = strdup("");
    }
    is32Bit  = (debugBuffer.CSAtr & 0x80) != 0;
    addr     = Linearize(debugBuffer.EIP, debugBuffer.CS);

    /*
    ** View the next lines to be displayed.
    */
    if(ptrs[2] == NULL) {
        DumpAsm(viewData->lastAddr, 0x20, is32Bit);
	viewData->lastAddr = addr + 0x20;
	return -1;
    }

    /*
    ** View a source line.
    */
    if(ptrs[2][0] == '.') {

	/*
	** Find the line number or the file name/line number
	*/
	if(isdigit(ptrs[2][1])) {
	    lineNum = atol(&ptrs[2][1]);
	    if(viewData->lastSource == NULL) {
		fprintf(logFile, "No source yet displayed\n");
		return -1;
	    }
	    strcpy(sourceName, viewData->lastSource);
	} else {
	    strcpy(sourceName, &ptrs[2][1]);
	    *strrchr(sourceName, ':') = 0;
	    lineNum = atol(strrchr(ptrs[2], ':') + 1);
	}
	addr = FindSourceLine(module, lineNum, sourceName);
	DumpAsm(addr, 0x20, is32Bit);
	viewData->lastAddr = addr + 0x20;
	return -1;
    }

    /*
    ** Get a view at a given offset.
    */
    if(isxdigit(ptrs[2][0])) {
	addr = StrToAddr(ptrs[2], TOADDR_CODE);
	DumpAsm(addr, 0x20, is32Bit);
	viewData->lastAddr = addr + 0x20;
	return -1;
    }

    /*
    ** ERROR!
    */
    fprintf(logFile, "Invalid syntax\n");
    return -1;
}
Пример #15
0
static int
setup_redir_port(char *buf, int *ac, char ***av)
{
	struct cfg_redir *r;
	char *sep, *protoName, *lsnat = NULL;
	size_t space;
	u_short numLocalPorts;
	port_range portRange;

	numLocalPorts = 0;

	r = (struct cfg_redir *)buf;
	r->mode = REDIR_PORT;
	/* Skip cfg_redir at beginning of buf. */
	buf = &buf[sizeof(struct cfg_redir)];
	space = sizeof(struct cfg_redir);

	/*
	 * Extract protocol.
	 */
	r->proto = StrToProto(**av);
	protoName = **av;
	(*av)++; (*ac)--;

	/*
	 * Extract local address.
	 */
	if (strchr(**av, ',') != NULL) {
		r->laddr.s_addr = INADDR_NONE;
		r->lport = ~0;
		numLocalPorts = 1;
		lsnat = **av;
	} else {
		/*
		 * The sctp nat does not allow the port numbers to be mapped to
		 * new port numbers. Therefore, no ports are to be specified
		 * in the target port field.
		 */
		if (r->proto == IPPROTO_SCTP) {
			if (strchr(**av, ':'))
				errx(EX_DATAERR, "redirect_port:"
				    "port numbers do not change in sctp, so do "
				    "not specify them as part of the target");
			else
				StrToAddr(**av, &r->laddr);
		} else {
			if (StrToAddrAndPortRange(**av, &r->laddr, protoName,
			    &portRange) != 0)
				errx(EX_DATAERR, "redirect_port: "
				    "invalid local port range");

			r->lport = GETLOPORT(portRange);
			numLocalPorts = GETNUMPORTS(portRange);
		}
	}
	(*av)++; (*ac)--;

	/*
	 * Extract public port and optionally address.
	 */
	if (strchr(**av, ':') != NULL) {
		if (StrToAddrAndPortRange(**av, &r->paddr, protoName,
		    &portRange) != 0)
			errx(EX_DATAERR, "redirect_port: "
			    "invalid public port range");
	} else {
		r->paddr.s_addr = INADDR_ANY;
		if (StrToPortRange(**av, protoName, &portRange) != 0)
			errx(EX_DATAERR, "redirect_port: "
			    "invalid public port range");
	}

	r->pport = GETLOPORT(portRange);
	if (r->proto == IPPROTO_SCTP) { /* so the logic below still works */
		numLocalPorts = GETNUMPORTS(portRange);
		r->lport = r->pport;
	}
	r->pport_cnt = GETNUMPORTS(portRange);
	(*av)++; (*ac)--;

	/*
	 * Extract remote address and optionally port.
	 */
	/*
	 * NB: isdigit(**av) => we've to check that next parameter is really an
	 * option for this redirect entry, else stop here processing arg[cv].
	 */
	if (*ac != 0 && isdigit(***av)) {
		if (strchr(**av, ':') != NULL) {
			if (StrToAddrAndPortRange(**av, &r->raddr, protoName,
			    &portRange) != 0)
				errx(EX_DATAERR, "redirect_port: "
				    "invalid remote port range");
		} else {
			SETLOPORT(portRange, 0);
			SETNUMPORTS(portRange, 1);
			StrToAddr(**av, &r->raddr);
		}
		(*av)++; (*ac)--;
	} else {
		SETLOPORT(portRange, 0);
		SETNUMPORTS(portRange, 1);
		r->raddr.s_addr = INADDR_ANY;
	}
	r->rport = GETLOPORT(portRange);
	r->rport_cnt = GETNUMPORTS(portRange);

	/*
	 * Make sure port ranges match up, then add the redirect ports.
	 */
	if (numLocalPorts != r->pport_cnt)
		errx(EX_DATAERR, "redirect_port: "
		    "port ranges must be equal in size");

	/* Remote port range is allowed to be '0' which means all ports. */
	if (r->rport_cnt != numLocalPorts &&
	    (r->rport_cnt != 1 || r->rport != 0))
		errx(EX_DATAERR, "redirect_port: remote port must"
		    "be 0 or equal to local port range in size");

	/* Setup LSNAT server pool. */
	if (lsnat != NULL) {
		struct cfg_spool *spool;

		sep = strtok(lsnat, ",");
		while (sep != NULL) {
			spool = (struct cfg_spool *)buf;
			space += sizeof(struct cfg_spool);
			/*
			 * The sctp nat does not allow the port numbers to
			 * be mapped to new port numbers. Therefore, no ports
			 * are to be specified in the target port field.
			 */
			if (r->proto == IPPROTO_SCTP) {
				if (strchr (sep, ':')) {
					errx(EX_DATAERR, "redirect_port:"
					    "port numbers do not change in "
					    "sctp, so do not specify them as "
					    "part of the target");
				} else {
					StrToAddr(sep, &spool->addr);
					spool->port = r->pport;
				}
			} else {
				if (StrToAddrAndPortRange(sep, &spool->addr,
					protoName, &portRange) != 0)
					errx(EX_DATAERR, "redirect_port:"
					    "invalid local port range");
				if (GETNUMPORTS(portRange) != 1)
					errx(EX_DATAERR, "redirect_port: "
					    "local port must be single in "
					    "this context");
				spool->port = GETLOPORT(portRange);
			}
			r->spool_cnt++;
			/* Point to the next possible cfg_spool. */
			buf = &buf[sizeof(struct cfg_spool)];
			sep = strtok(NULL, ",");
		}
	}

	return (space);
}
Пример #16
0
/*
** Take a string which is supposed to be an executable address,
** and find out what that address is.
*/
ULONG FindExecAddr(char *label, char **brkDesc)
{
ULONG	addr = 0;
char   *desc;
char   *dummy;
ULONG lineNum;
DebugModule *module;
char	funcName[MAX_FUNCNAME];
char	sourceName[CCHMAXPATH];

    /*
    ** If there is no label, give up the ghost!
    */
    if(label == NULL)
	return 0;

    /*
    ** Find the address of the line given a line number.
    */
    if(label[0] == '.') {
        module = FindModule(debugBuffer.MTE, NULL);
	FindSource(module, Linearize(debugBuffer.EIP, debugBuffer.CS),
		   funcName, sourceName, &lineNum);

	/* Cannot find source module. */
	if(strcmp(sourceName, "UNKNOWN") == 0) {
	    return 0;
	}
	lineNum = strtol(&label[1], &dummy, 0);
	addr = FindSourceLine(module, lineNum, sourceName);

	/*
	** Build a string which describes the breakpoint.
	*/
	desc = malloc(strlen(label) + strlen(sourceName) + 1);
	strcpy(desc, sourceName);
	strcat(desc, ":");
	strcat(desc, &label[1]);
	*brkDesc = desc;
	return addr;
    }

    /*
    ** If we have a '!' in the string, then it is a compound
    ** filename/line number
    */
    if(strchr(label, '!') != NULL) {
	char	    *line;

        line = strchr(label, '!');
        *line = '\0';
        module = FindModule(debugBuffer.MTE, NULL);
	FindSource(module, Linearize(debugBuffer.EIP, debugBuffer.CS),
		   funcName, sourceName, &lineNum);
	/* Cannot find source module. */
	if(strcmp(sourceName, "UNKNOWN") == 0) {
	    return 0;
	}
	lineNum = strtol(&label[1], &dummy, 0);
	addr = FindSourceLine(module, lineNum, sourceName);

	/*
	** Build a string which describes the breakpoint.
	*/
	desc = malloc(strlen(label) + strlen(sourceName) + 1);
	strcpy(desc, sourceName);
	strcat(desc, ":");
	strcat(desc, &label[1]);
	*brkDesc = desc;
	return addr;
    }

    /*
    ** Try finding the name as a function
    */
    if((addr = FindFuncAddr(NULL, label)) != 0) {
	desc = malloc(strlen(label) + 1);
	strcpy(desc, label);
	*brkDesc = desc;
	return addr;
    }

    /*
    ** If we could not find a function, try using the label as
    ** a hex offset to break at.
    */
    addr = StrToAddr(label, TOADDR_CODE);
    desc = malloc(strlen(label) + 1);
    strcpy(desc, label);
    *brkDesc = desc;
    return addr;
}
Пример #17
0
OSErr mactcp_connect(mactcp_inst *i, mactcp_conn *c, char *hostname, short port)
{
	volatile int resolverDone = FALSE;
	struct hostInfo hi;
	size_t buflen;
	UDPiopb upb;
	TCPiopb pb;
	OSErr err;
	
	if(!i->initialized) {
		printf("mactcp_connect(): not initialized\n");
		return -1;
	}
	
	c->i = i;
	err = StrToAddr(hostname, &hi, i->mactcp_lookupdone_upp, (char *)&resolverDone);
	if(err == cacheFault) {
		while(!resolverDone)
			continue;
	}

	if(err != noErr && err != cacheFault)
		return err;
		
	/* get the max MTU size for this path */
	/* we use this to calculate the buffer size */
	upb.ioCRefNum = i->refnum;
	upb.csCode = UDPMaxMTUSize;
	upb.csParam.mtu.remoteHost = hi.addr[0];
	err = PBControlSync((ParmBlkPtr) &upb);
	
	if(err != noErr) {
		printf("mactcp_connect(): error getting MTU, err=%d\n", err);
		return err;
	}
	
        /*
         * this is broken on my PM7500 w/ 7.6.1 
         * the MTU returned is always absurdly high
         */
#if 0
	buflen = upb.csParam.mtu.mtuSize * 4 + 1024;
	if(buflen < 4096)
		buflen = 4096;
#else
        buflen = 4096;
#endif
		
	pb.ioCRefNum = i->refnum;
	pb.csCode = TCPCreate;
	pb.csParam.create.rcvBuff = malloc(buflen);
	pb.csParam.create.rcvBuffLen = buflen;
	pb.csParam.create.notifyProc = i->mactcp_asr_upp;
	pb.csParam.create.userDataPtr = (Ptr)c;
	
	err = PBControlSync((ParmBlkPtr) &pb);
	if(err != noErr) {
		printf("mactcp_connect(): error creating TCP stream, err=%d", err);
		return err;
	}
	
	c->s = pb.tcpStream;
	
	pb.ioCRefNum = i->refnum;
	pb.csCode = TCPActiveOpen;
	pb.tcpStream = c->s;
	pb.csParam.open.validityFlags = 0;
	pb.csParam.open.remoteHost = hi.addr[0];
	pb.csParam.open.remotePort = port;
	pb.csParam.open.localPort = 0;
	pb.csParam.open.timeToLive = 0;
	pb.csParam.open.security = 0;
	pb.csParam.open.optionCnt = 0;
	pb.csParam.open.userDataPtr = (Ptr)c;
	err = PBControlSync((ParmBlkPtr) &pb);
	if(err != noErr) {
		printf("Error connecting TCP stream: %d\n", err);
		return err;
	}
	
	c->readable = 1;
	
	return noErr;
}