本文整理汇总了C++中SockAddr::HasPort方法的典型用法代码示例。如果您正苦于以下问题:C++ SockAddr::HasPort方法的具体用法?C++ SockAddr::HasPort怎么用?C++ SockAddr::HasPort使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SockAddr
的用法示例。
在下文中一共展示了SockAddr::HasPort方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char *argv[])
{
bool ret;
openbfdd::Beacon app;
bool tee = false;
bool doFork = true;
int argIndex;
list<SockAddr> controlPorts;
list<IpAddr> listenAddrs;
const char *valueString;
#ifdef BFD_DEBUG
tee = true;
#endif
//Parse command line options.
//Be careful what we do here, since we are pre-fork, and we have not initialized
//utils, logging, etc.
for (argIndex = 1; argIndex < argc; argIndex++)
{
if (0 == strcmp("--notee", argv[argIndex]))
{
tee = false;
}
else if (0 == strcmp("--tee", argv[argIndex]))
{
tee = true;
}
else if (0 == strcmp("--nofork", argv[argIndex]))
{
doFork = false;
}
else if (0 == strcmp("--version", argv[argIndex]))
{
fprintf(stdout, "%s version %s\n", openbfdd::BeaconAppName, openbfdd::SofwareVesrion);
exit(0);
}
else if (CheckArg("--control", argv[argIndex], &valueString))
{
SockAddr addrVal;
if (!valueString || *valueString == '\0')
{
fprintf(stderr, "--control must be followed by an '=' and a ip address with a port.\n");
exit(1);
}
if (!addrVal.FromString(valueString))
{
fprintf(stderr, "--control address <%s> is not an IPv4 or IPv6 address.\n", valueString);
exit(1);
}
if (!addrVal.HasPort())
{
fprintf(stderr, "--control address must have a port specified. The address <%s> does not conatin a port.\n", valueString);
exit(1);
}
controlPorts.push_back(addrVal);
}
else if (CheckArg("--listen", argv[argIndex], &valueString))
{
IpAddr addrVal;
if (!valueString || *valueString == '\0')
{
fprintf(stderr, "--listen must be followed by an '=' and a ip address (may be 0.0.0.0 or ::).\n");
exit(1);
}
if (!addrVal.FromString(valueString))
{
fprintf(stderr, "--listen address <%s> is not an IPv4 or IPv6 address.\n", valueString);
exit(1);
}
listenAddrs.push_back(addrVal);
}
else
{
fprintf(stderr, "Unrecognized %s command line option %s.\n", openbfdd::BeaconAppName, argv[argIndex]);
exit(1);
}
}
if (doFork)
{
tee = false;
if (0 != daemon(1, 0))
{
fprintf(stderr, "Failed to daemonize. Exiting.\n");
exit(1);
}
}
srand(time(NULL));
if (!openbfdd::UtilsInit() || !openbfdd::UtilsInitThread())
{
//.........这里部分代码省略.........
示例2: bfddMain
static int bfddMain(int argc, char *argv[])
{
int argIndex;
SockAddr connectAddr;
const char *valueString;
//gLog.LogToFile("/tmp/bfd.log");
UtilsInit();
gLog.LogToSyslog("bfdd-control", false);
gLog.Optional(Log::App, "Startup %x", getpid());
//Parse command line options
for (argIndex = 1; argIndex < argc; argIndex++)
{
if (0 == strcmp("--altport", argv[argIndex]))
{
if (connectAddr.IsValid())
{
fprintf(stderr, "Only a single --altport or --control option is allowed.\n");
exit(1);
}
// Backwards compatability only ... use --control
connectAddr.FromString("127.0.0.1", ALT_PORTNUM);
}
else if (CheckArg("--control", argv[argIndex], &valueString))
{
if (!valueString || *valueString == '\0')
{
fprintf(stderr, "--control must be followed by an '=' and a ip address with a port.\n");
exit(1);
}
if (!connectAddr.FromString(valueString))
{
fprintf(stderr, "--control address <%s> is not an IPv4 or IPv6 address.\n", valueString);
exit(1);
}
if (!connectAddr.HasPort())
{
fprintf(stderr, "--control address must have a port specified. The address <%s> does not conatin a port.\n", valueString);
exit(1);
}
}
else if (0 == strncmp("--", argv[argIndex], 2))
{
fprintf(stderr, "Unrecognized %s command line option %s.\n", ControlAppName, argv[argIndex]);
exit(1);
}
else
break;
}
if (argIndex >= argc)
{
fprintf(stderr, "No command. Try \"man %s\" for a list of commands.\n", ControlAppName);
exit(1);
}
// "version" is special because we tell first. Than lest the beacon handle it.
if (0 == strcmp(argv[argIndex], "version"))
{
fprintf(stdout, "%s v%s\n", ControlAppName, SofwareVesrion);
}
if (!connectAddr.IsValid())
connectAddr.FromString("127.0.0.1", PORTNUM);
// "load" is special because we send a series of commands..
if (0 == strcmp(argv[argIndex], "load"))
{
argIndex++;
if (argIndex >= argc)
{
fprintf(stderr, "Must supply a script file after 'load'\n");
exit(1);
}
fprintf(stdout, "Running script from file <%s>\n", argv[argIndex]);
if (!doLoadScript(argv[argIndex], connectAddr))
{
fprintf(stderr, "Script load failed.\n");
exit(1);
}
fprintf(stdout, "Completed script from file <%s>\n", argv[argIndex]);
exit(0);
}
// To allow for quotes, we concatenate all the arguments, separating them with
// "NULL".
vector<char> buffer;
buffer.reserve(MaxCommandSize);
for (; argIndex < argc; argIndex++)
{
AddParamToBuffer(buffer, argv[argIndex]);
}
//.........这里部分代码省略.........