target.cc
来自「Ubuntu packages of security software。 相」· CC 代码 · 共 463 行 · 第 1/2 页
CC
463 行
struct in_addr Target::v4host() { const struct in_addr *addy = v4hostip(); struct in_addr in; if (addy) return *addy; in.s_addr = 0; return in;}// Returns IPv4 host address or NULL if unavailable.const struct in_addr *Target::v4hostip() { struct sockaddr_in *sin = (struct sockaddr_in *) &targetsock; if (sin->sin_family == AF_INET) { return &(sin->sin_addr); } return NULL;} /* The source address used to reach the target */int Target::SourceSockAddr(struct sockaddr_storage *ss, size_t *ss_len) { if (sourcesocklen <= 0) return 1; assert(sourcesocklen <= sizeof(*ss)); if (ss) memcpy(ss, &sourcesock, sourcesocklen); if (ss_len) *ss_len = sourcesocklen; return 0;}/* Note that it is OK to pass in a sockaddr_in or sockaddr_in6 casted to sockaddr_storage */void Target::setSourceSockAddr(struct sockaddr_storage *ss, size_t ss_len) { assert(ss_len > 0 && ss_len <= sizeof(*ss)); memcpy(&sourcesock, ss, ss_len); sourcesocklen = ss_len;}// Returns IPv4 host address or {0} if unavailable.struct in_addr Target::v4source() { const struct in_addr *addy = v4sourceip(); struct in_addr in; if (addy) return *addy; in.s_addr = 0; return in;}// Returns IPv4 host address or NULL if unavailable.const struct in_addr *Target::v4sourceip() { struct sockaddr_in *sin = (struct sockaddr_in *) &sourcesock; if (sin->sin_family == AF_INET) { return &(sin->sin_addr); } return NULL;} /* You can set to NULL to erase a name or if it failed to resolve -- or just don't call this if it fails to resolve */void Target::setHostName(char *name) { char *p; if (hostname) { free(hostname); hostname = NULL; } if (name) { p = hostname = strdup(name); while (*p) { // I think only a-z A-Z 0-9 . and - are allowed, but I'll be a little more // generous. if (!isalnum(*p) && !strchr(".-+=:_~*", *p)) { log_write(LOG_STDOUT, "Illegal character(s) in hostname -- replacing with '*'\n"); *p = '*'; } p++; } }} /* Generates a printable string consisting of the host's IP address and hostname (if available). Eg "www.insecure.org (64.71.184.53)" or "fe80::202:e3ff:fe14:1102". The name is written into the buffer provided, which is also returned. Results that do not fit in buflen will be truncated. */const char *Target::NameIP(char *buf, size_t buflen) { assert(buf); assert(buflen > 8); if (hostname) { Snprintf(buf, buflen, "%s (%s)", hostname, targetipstring); } else Strncpy(buf, targetipstring, buflen); return buf;}/* This next version returns a static buffer -- so no concurrency */const char *Target::NameIP() { if (!nameIPBuf) nameIPBuf = (char *) safe_malloc(MAXHOSTNAMELEN + INET6_ADDRSTRLEN); return NameIP(nameIPBuf, MAXHOSTNAMELEN + INET6_ADDRSTRLEN);} /* Returns the next hop for sending packets to this host. Returns true if next_hop was filled in. It might be false, for example, if next_hop has never been set */bool Target::nextHop(struct sockaddr_storage *next_hop, size_t *next_hop_len) { if (nexthopsocklen <= 0) return false; assert(nexthopsocklen <= sizeof(*next_hop)); if (next_hop) memcpy(next_hop, &nexthopsock, nexthopsocklen); if (next_hop_len) *next_hop_len = nexthopsocklen; return true;} /* If the host is directly connected on a network, set and retrieve that information here. directlyConnected() will abort if it hasn't been set yet. */void Target::setDirectlyConnected(bool connected) { directly_connected = connected? 1 : 0;}int Target::directlyConnectedOrUnset(){ return directly_connected;}bool Target::directlyConnected() { assert(directly_connected == 0 || directly_connected == 1); return directly_connected;}/* Note that it is OK to pass in a sockaddr_in or sockaddr_in6 casted to sockaddr_storage */void Target::setNextHop(struct sockaddr_storage *next_hop, size_t next_hop_len) { assert(next_hop_len > 0 && next_hop_len <= sizeof(nexthopsock)); memcpy(&nexthopsock, next_hop, next_hop_len); nexthopsocklen = next_hop_len;} /* Starts the timeout clock for the host running (e.g. you are beginning a scan). If you do not have the current time handy, you can pass in NULL. When done, call stopTimeOutClock (it will also automatically be stopped of timedOut() returns true) */void Target::startTimeOutClock(const struct timeval *now) { assert(htn.toclock_running == false); htn.toclock_running = true; if (now) htn.toclock_start = *now; else gettimeofday(&htn.toclock_start, NULL);} /* The complement to startTimeOutClock. */void Target::stopTimeOutClock(const struct timeval *now) { struct timeval tv; assert(htn.toclock_running == true); htn.toclock_running = false; if (now) tv = *now; else gettimeofday(&tv, NULL); htn.msecs_used += TIMEVAL_MSEC_SUBTRACT(tv, htn.toclock_start);} /* Returns whether the host is timedout. If the timeoutclock is running, counts elapsed time for that. Pass NULL if you don't have the current time handy. You might as well also pass NULL if the clock is not running, as the func won't need the time. */bool Target::timedOut(const struct timeval *now) { unsigned long used = htn.msecs_used; struct timeval tv; if (!o.host_timeout) return false; if (htn.toclock_running) { if (now) tv = *now; else gettimeofday(&tv, NULL); used += TIMEVAL_MSEC_SUBTRACT(tv, htn.toclock_start); } return (used > o.host_timeout)? true : false;}/* Returns zero if MAC address set successfully */int Target::setMACAddress(const u8 *addy) { if (!addy) return 1; memcpy(MACaddress, addy, 6); MACaddress_set = 1; return 0;}int Target::setSrcMACAddress(const u8 *addy) { if (!addy) return 1; memcpy(SrcMACaddress, addy, 6); SrcMACaddress_set = 1; return 0;}int Target::setNextHopMACAddress(const u8 *addy) { if (!addy) return 1; memcpy(NextHopMACaddress, addy, 6); NextHopMACaddress_set = 1; return 0;}/* Set the device names so that they can be returned by deviceName() and deviceFullName(). The normal name may not include alias qualifier, while the full name may include it (e.g. "eth1:1"). If these are non-null, they will overwrite the stored version */void Target::setDeviceNames(const char *name, const char *fullname) { if (name) Strncpy(devname, name, sizeof(devname)); if (fullname) Strncpy(devfullname, fullname, sizeof(devfullname));}/* Returns the 6-byte long MAC address, or NULL if none has been set */const u8 *Target::MACAddress() { return (MACaddress_set)? MACaddress : NULL;}const u8 *Target::SrcMACAddress() { return (SrcMACaddress_set)? SrcMACaddress : NULL;}const u8 *Target::NextHopMACAddress() { return (NextHopMACaddress_set)? NextHopMACaddress : NULL;}int Target::osscanPerformed(void) { return osscan_flag;}void Target::osscanSetFlag(int flag) { if(osscan_flag == OS_PERF_UNREL) return; else osscan_flag = flag;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?