Exemple #1
0
/******************************************************
*                     build_buffer                    *
* input:                                              *
*       -list: pointer to the first element to build  *
*              http part from                         *
*       -buffer: pointer to the buffer to fill        *
*       -my_name: human readable mac of the AP        *
*       -nb_macs: number of macs requested in http    *
*                 GET request                         *
*       -requested_macs: array of nb_macs * 6 byte    *
*                        containing the byte macs     *
*                        requested by http request.   *
* output:                                             *
*       -pointer to the buffer filled                 *
* desc:                                               *
*       This function build the response buffer to    *
*       send back as a response to an http GET request*
*       in the form:                                  *
*  {"ap":"ap:ap:ap:ap:ap:ap", "rssi":["{1},{2},...]}  *
*   with each sample of rssi in the form :            *
*       {"XX:XX:XX:XX:XX:XX":"1", "samples":"2"}      *
*       - 1: rssi mean value                          *
*       - 2: number of samples used for mean value    *
*                                                     *
*******************************************************/
char *build_buffer(Element *list, char *buffer, char *my_name, u_char *requested_macs, unsigned short nb_macs, unsigned int n) {
    int i = 0;
    int j = 0;
    int written = 0;
    char *rssi_resp = NULL;
    Element * el = NULL;
    u_char looking_mac[6] = {0};

    /* TODO: Dynamically adapt the frame size according to the output.
     * Hope 248 will not overflow... */
    rssi_resp = (char *)calloc(248, sizeof(char));
    if (rssi_resp == NULL) {
        perror("[@] Allocation of the buffer failed.");
        return NULL;
    }

    written = snprintf(buffer, n, "{\"ap\":\"%s\", \"rssi\":[", my_name);
    for (i = 0; i < nb_macs; ++i) {
        /* Build the MAC address. */
        for (j = 0; j < 6; ++j)
            looking_mac[j] = requested_macs[i + j];

        el = find_mac( list, looking_mac);
        if (el != NULL)
            strncat(buffer, build_element(el, rssi_resp, 248), n - written);
    }
    strncat(buffer, "]}", n - written - sizeof(el));
    return buffer;
}
Exemple #2
0
string NetGuard_Command_Input_WH8::get_room_from_mac(mac_addr mac) {
	u_int32_t ip;
	int port;
	string name;
	if (find_mac(mac,&ip,&port,&name)) {
		return name;
	}
	return "";
}
Exemple #3
0
void tftp_request(struct listener *listen, time_t now)
{
  ssize_t len;
  char *packet = daemon->packet;
  char *filename, *mode, *p, *end, *opt;
  union mysockaddr addr, peer;
  struct msghdr msg;
  struct iovec iov;
  struct ifreq ifr;
  int is_err = 1, if_index = 0, mtu = 0;
  struct iname *tmp;
  struct tftp_transfer *transfer;
  int port = daemon->start_tftp_port; /* may be zero to use ephemeral port */
#if defined(IP_MTU_DISCOVER) && defined(IP_PMTUDISC_DONT)
  int mtuflag = IP_PMTUDISC_DONT;
#endif
  char namebuff[IF_NAMESIZE];
  char *name = NULL;
  char *prefix = daemon->tftp_prefix;
  struct tftp_prefix *pref;
  union all_addr addra;
  /* Can always get recvd interface for IPv6 */
  int check_dest = !option_bool(OPT_NOWILD) || listen->family == AF_INET6;
  union {
    struct cmsghdr align; /* this ensures alignment */
    char control6[CMSG_SPACE(sizeof(struct in6_pktinfo))];
#if defined(HAVE_LINUX_NETWORK)
    char control[CMSG_SPACE(sizeof(struct in_pktinfo))];
#elif defined(HAVE_SOLARIS_NETWORK)
    char control[CMSG_SPACE(sizeof(unsigned int))];
#elif defined(IP_RECVDSTADDR) && defined(IP_RECVIF)
    char control[CMSG_SPACE(sizeof(struct sockaddr_dl))];
#endif
  } control_u; 

  msg.msg_controllen = sizeof(control_u);
  msg.msg_control = control_u.control;
  msg.msg_flags = 0;
  msg.msg_name = &peer;
  msg.msg_namelen = sizeof(peer);
  msg.msg_iov = &iov;
  msg.msg_iovlen = 1;

  iov.iov_base = packet;
  iov.iov_len = daemon->packet_buff_sz;

  /* we overwrote the buffer... */
  daemon->srv_save = NULL;

  if ((len = recvmsg(listen->tftpfd, &msg, 0)) < 2)
    return;

  /* Can always get recvd interface for IPv6 */
  if (!check_dest)
    {
      if (listen->iface)
	{
	  addr = listen->iface->addr;
	  name = listen->iface->name;
	  mtu = listen->iface->mtu;
	  if (daemon->tftp_mtu != 0 && daemon->tftp_mtu < mtu)
	    mtu = daemon->tftp_mtu;
	}
      else
	{
	  /* we're listening on an address that doesn't appear on an interface,
	     ask the kernel what the socket is bound to */
	  socklen_t tcp_len = sizeof(union mysockaddr);
	  if (getsockname(listen->tftpfd, (struct sockaddr *)&addr, &tcp_len) == -1)
	    return;
	}
    }
  else
    {
      struct cmsghdr *cmptr;

      if (msg.msg_controllen < sizeof(struct cmsghdr))
        return;
      
      addr.sa.sa_family = listen->family;
      
#if defined(HAVE_LINUX_NETWORK)
      if (listen->family == AF_INET)
	for (cmptr = CMSG_FIRSTHDR(&msg); cmptr; cmptr = CMSG_NXTHDR(&msg, cmptr))
	  if (cmptr->cmsg_level == IPPROTO_IP && cmptr->cmsg_type == IP_PKTINFO)
	    {
	      union {
		unsigned char *c;
		struct in_pktinfo *p;
	      } p;
	      p.c = CMSG_DATA(cmptr);
	      addr.in.sin_addr = p.p->ipi_spec_dst;
	      if_index = p.p->ipi_ifindex;
	    }
      
#elif defined(HAVE_SOLARIS_NETWORK)
      if (listen->family == AF_INET)
	for (cmptr = CMSG_FIRSTHDR(&msg); cmptr; cmptr = CMSG_NXTHDR(&msg, cmptr))
	  {
	    union {
	      unsigned char *c;
	      struct in_addr *a;
	      unsigned int *i;
	    } p;
	    p.c = CMSG_DATA(cmptr);
	    if (cmptr->cmsg_level == IPPROTO_IP && cmptr->cmsg_type == IP_RECVDSTADDR)
	    addr.in.sin_addr = *(p.a);
	    else if (cmptr->cmsg_level == IPPROTO_IP && cmptr->cmsg_type == IP_RECVIF)
	    if_index = *(p.i);
	  }
      
#elif defined(IP_RECVDSTADDR) && defined(IP_RECVIF)
      if (listen->family == AF_INET)
	for (cmptr = CMSG_FIRSTHDR(&msg); cmptr; cmptr = CMSG_NXTHDR(&msg, cmptr))
	  {
	    union {
	      unsigned char *c;
	      struct in_addr *a;
	      struct sockaddr_dl *s;
	    } p;
	    p.c = CMSG_DATA(cmptr);
	    if (cmptr->cmsg_level == IPPROTO_IP && cmptr->cmsg_type == IP_RECVDSTADDR)
	      addr.in.sin_addr = *(p.a);
	    else if (cmptr->cmsg_level == IPPROTO_IP && cmptr->cmsg_type == IP_RECVIF)
	      if_index = p.s->sdl_index;
	  }
	  
#endif

      if (listen->family == AF_INET6)
        {
          for (cmptr = CMSG_FIRSTHDR(&msg); cmptr; cmptr = CMSG_NXTHDR(&msg, cmptr))
            if (cmptr->cmsg_level == IPPROTO_IPV6 && cmptr->cmsg_type == daemon->v6pktinfo)
              {
                union {
                  unsigned char *c;
                  struct in6_pktinfo *p;
                } p;
                p.c = CMSG_DATA(cmptr);
                  
                addr.in6.sin6_addr = p.p->ipi6_addr;
                if_index = p.p->ipi6_ifindex;
              }
        }
      
      if (!indextoname(listen->tftpfd, if_index, namebuff))
	return;

      name = namebuff;
      
      addra.addr4 = addr.in.sin_addr;

      if (listen->family == AF_INET6)
	addra.addr6 = addr.in6.sin6_addr;

      if (daemon->tftp_interfaces)
	{
	  /* dedicated tftp interface list */
	  for (tmp = daemon->tftp_interfaces; tmp; tmp = tmp->next)
	    if (tmp->name && wildcard_match(tmp->name, name))
	      break;

	  if (!tmp)
	    return;
	}
      else
	{
	  /* Do the same as DHCP */
	  if (!iface_check(listen->family, &addra, name, NULL))
	    {
	      if (!option_bool(OPT_CLEVERBIND))
		enumerate_interfaces(0); 
	      if (!loopback_exception(listen->tftpfd, listen->family, &addra, name) &&
		  !label_exception(if_index, listen->family, &addra))
		return;
	    }
	  
#ifdef HAVE_DHCP      
	  /* allowed interfaces are the same as for DHCP */
	  for (tmp = daemon->dhcp_except; tmp; tmp = tmp->next)
	    if (tmp->name && wildcard_match(tmp->name, name))
	      return;
#endif
	}

      safe_strncpy(ifr.ifr_name, name, IF_NAMESIZE);
      if (ioctl(listen->tftpfd, SIOCGIFMTU, &ifr) != -1)
	{
	  mtu = ifr.ifr_mtu;  
	  if (daemon->tftp_mtu != 0 && daemon->tftp_mtu < mtu)
	    mtu = daemon->tftp_mtu;    
	}
    }

  /* Failed to get interface mtu - can use configured value. */
  if (mtu == 0)
    mtu = daemon->tftp_mtu;

  if (name)
    {
      /* check for per-interface prefix */ 
      for (pref = daemon->if_prefix; pref; pref = pref->next)
	if (strcmp(pref->interface, name) == 0)
	  prefix = pref->prefix;  
    }

  if (listen->family == AF_INET)
    {
      addr.in.sin_port = htons(port);
#ifdef HAVE_SOCKADDR_SA_LEN
      addr.in.sin_len = sizeof(addr.in);
#endif
    }
  else
    {
      addr.in6.sin6_port = htons(port);
      addr.in6.sin6_flowinfo = 0;
      addr.in6.sin6_scope_id = 0;
#ifdef HAVE_SOCKADDR_SA_LEN
      addr.in6.sin6_len = sizeof(addr.in6);
#endif
    }

  if (!(transfer = whine_malloc(sizeof(struct tftp_transfer))))
    return;
  
  if ((transfer->sockfd = socket(listen->family, SOCK_DGRAM, 0)) == -1)
    {
      free(transfer);
      return;
    }
  
  transfer->peer = peer;
  transfer->timeout = now + 2;
  transfer->backoff = 1;
  transfer->block = 1;
  transfer->blocksize = 512;
  transfer->offset = 0;
  transfer->file = NULL;
  transfer->opt_blocksize = transfer->opt_transize = 0;
  transfer->netascii = transfer->carrylf = 0;
 
  prettyprint_addr(&peer, daemon->addrbuff);
  
  /* if we have a nailed-down range, iterate until we find a free one. */
  while (1)
    {
      if (bind(transfer->sockfd, &addr.sa, sa_len(&addr)) == -1 ||
#if defined(IP_MTU_DISCOVER) && defined(IP_PMTUDISC_DONT)
	  setsockopt(transfer->sockfd, IPPROTO_IP, IP_MTU_DISCOVER, &mtuflag, sizeof(mtuflag)) == -1 ||
#endif
	  !fix_fd(transfer->sockfd))
	{
	  if (errno == EADDRINUSE && daemon->start_tftp_port != 0)
	    {
	      if (++port <= daemon->end_tftp_port)
		{ 
		  if (listen->family == AF_INET)
		    addr.in.sin_port = htons(port);
		  else
		    addr.in6.sin6_port = htons(port);
		  
		  continue;
		}
	      my_syslog(MS_TFTP | LOG_ERR, _("unable to get free port for TFTP"));
	    }
	  free_transfer(transfer);
	  return;
	}
      break;
    }
  
  p = packet + 2;
  end = packet + len;

  if (ntohs(*((unsigned short *)packet)) != OP_RRQ ||
      !(filename = next(&p, end)) ||
      !(mode = next(&p, end)) ||
      (strcasecmp(mode, "octet") != 0 && strcasecmp(mode, "netascii") != 0))
    {
      len = tftp_err(ERR_ILL, packet, _("unsupported request from %s"), daemon->addrbuff);
      is_err = 1;
    }
  else
    {
      if (strcasecmp(mode, "netascii") == 0)
	transfer->netascii = 1;
      
      while ((opt = next(&p, end)))
	{
	  if (strcasecmp(opt, "blksize") == 0)
	    {
	      if ((opt = next(&p, end)) && !option_bool(OPT_TFTP_NOBLOCK))
		{
		  /* 32 bytes for IP, UDP and TFTP headers, 52 bytes for IPv6 */
		  int overhead = (listen->family == AF_INET) ? 32 : 52;
		  transfer->blocksize = atoi(opt);
		  if (transfer->blocksize < 1)
		    transfer->blocksize = 1;
		  if (transfer->blocksize > (unsigned)daemon->packet_buff_sz - 4)
		    transfer->blocksize = (unsigned)daemon->packet_buff_sz - 4;
		  if (mtu != 0 && transfer->blocksize > (unsigned)mtu - overhead)
		    transfer->blocksize = (unsigned)mtu - overhead;
		  transfer->opt_blocksize = 1;
		  transfer->block = 0;
		}
	    }
	  else if (strcasecmp(opt, "tsize") == 0 && next(&p, end) && !transfer->netascii)
	    {
	      transfer->opt_transize = 1;
	      transfer->block = 0;
	    }
	}

      /* cope with backslashes from windows boxen. */
      for (p = filename; *p; p++)
	if (*p == '\\')
	  *p = '/';
	else if (option_bool(OPT_TFTP_LC))
	  *p = tolower(*p);
		
      strcpy(daemon->namebuff, "/");
      if (prefix)
	{
	  if (prefix[0] == '/')
	    daemon->namebuff[0] = 0;
	  strncat(daemon->namebuff, prefix, (MAXDNAME-1) - strlen(daemon->namebuff));
	  if (prefix[strlen(prefix)-1] != '/')
	    strncat(daemon->namebuff, "/", (MAXDNAME-1) - strlen(daemon->namebuff));

	  if (option_bool(OPT_TFTP_APREF_IP))
	    {
	      size_t oldlen = strlen(daemon->namebuff);
	      struct stat statbuf;
	      
	      strncat(daemon->namebuff, daemon->addrbuff, (MAXDNAME-1) - strlen(daemon->namebuff));
	      strncat(daemon->namebuff, "/", (MAXDNAME-1) - strlen(daemon->namebuff));
	      
	      /* remove unique-directory if it doesn't exist */
	      if (stat(daemon->namebuff, &statbuf) == -1 || !S_ISDIR(statbuf.st_mode))
		daemon->namebuff[oldlen] = 0;
	    }
	  
	  if (option_bool(OPT_TFTP_APREF_MAC))
	    {
	      unsigned char *macaddr = NULL;
	      unsigned char macbuf[DHCP_CHADDR_MAX];
	      
#ifdef HAVE_DHCP
	      if (daemon->dhcp && peer.sa.sa_family == AF_INET)
	        {
		  /* Check if the client IP is in our lease database */
		  struct dhcp_lease *lease = lease_find_by_addr(peer.in.sin_addr);
		  if (lease && lease->hwaddr_type == ARPHRD_ETHER && lease->hwaddr_len == ETHER_ADDR_LEN)
		    macaddr = lease->hwaddr;
		}
#endif
	      
	      /* If no luck, try to find in ARP table. This only works if client is in same (V)LAN */
	      if (!macaddr && find_mac(&peer, macbuf, 1, now) > 0)
		macaddr = macbuf;
	      
	      if (macaddr)
	        {
		  size_t oldlen = strlen(daemon->namebuff);
		  struct stat statbuf;

		  snprintf(daemon->namebuff + oldlen, (MAXDNAME-1) - oldlen, "%.2x-%.2x-%.2x-%.2x-%.2x-%.2x/",
			   macaddr[0], macaddr[1], macaddr[2], macaddr[3], macaddr[4], macaddr[5]);
		  
		  /* remove unique-directory if it doesn't exist */
		  if (stat(daemon->namebuff, &statbuf) == -1 || !S_ISDIR(statbuf.st_mode))
		    daemon->namebuff[oldlen] = 0;
		}
	    }
	  
	  /* Absolute pathnames OK if they match prefix */
	  if (filename[0] == '/')
	    {
	      if (strstr(filename, daemon->namebuff) == filename)
		daemon->namebuff[0] = 0;
	      else
		filename++;
	    }
	}
      else if (filename[0] == '/')
	daemon->namebuff[0] = 0;
      strncat(daemon->namebuff, filename, (MAXDNAME-1) - strlen(daemon->namebuff));
      
      /* check permissions and open file */
      if ((transfer->file = check_tftp_fileperm(&len, prefix)))
	{
	  if ((len = get_block(packet, transfer)) == -1)
	    len = tftp_err_oops(packet, daemon->namebuff);
	  else
	    is_err = 0;
	}
    }
  
  while (sendto(transfer->sockfd, packet, len, 0, 
		(struct sockaddr *)&peer, sa_len(&peer)) == -1 && errno == EINTR);
  
  if (is_err)
    free_transfer(transfer);
  else
    {
      transfer->next = daemon->tftp_trans;
      daemon->tftp_trans = transfer;
    }
}
Exemple #4
0
int
experience(register struct monst *mtmp, register int nk)	/* return # of exp points for mtmp after nk killed */
               	            
            	   
#if defined(macintosh) && (defined(__SC__) || defined(__MRC__))
# pragma unused(nk)
#endif
{
    register struct permonst *ptr = mtmp->data;
    int	i, tmp, tmp2;

    tmp = 1 + mtmp->m_lev * mtmp->m_lev;

    /*	For higher ac values, give extra experience */
    if ((i = find_mac(mtmp)) < 3) tmp += (7 - i) * ((i < 0) ? 2 : 1);

    /*	For very fast monsters, give extra experience */
    if (ptr->mmove > NORMAL_SPEED)
        tmp += (ptr->mmove > (3*NORMAL_SPEED/2)) ? 5 : 3;

    /*	For each "special" attack type give extra experience */
    for(i = 0; i < NATTK; i++) {

        tmp2 = ptr->mattk[i].aatyp;
        if(tmp2 > AT_BUTT) {

            if(tmp2 == AT_WEAP) tmp += 5;
            else if(tmp2 == AT_MAGC) tmp += 10;
            else tmp += 3;
        }
    }

    /*	For each "special" damage type give extra experience */
    for(i = 0; i < NATTK; i++) {
        tmp2 = ptr->mattk[i].adtyp;
        if(tmp2 > AD_PHYS && tmp2 < AD_BLND) tmp += 2*mtmp->m_lev;
        else if((tmp2 == AD_DRLI) || (tmp2 == AD_STON) ||
                (tmp2 == AD_SLIM)) tmp += 50;
        else if(tmp != AD_PHYS) tmp += mtmp->m_lev;
        /* extra heavy damage bonus */
        if((int)(ptr->mattk[i].damd * ptr->mattk[i].damn) > 23)
            tmp += mtmp->m_lev;
        if (tmp2 == AD_WRAP && ptr->mlet == S_EEL && !Amphibious)
            tmp += 1000;
    }

    /*	For certain "extra nasty" monsters, give even more */
    if (extra_nasty(ptr)) tmp += (7 * mtmp->m_lev);

    /*	For higher level monsters, an additional bonus is given */
    if(mtmp->m_lev > 8) tmp += 50;

    /*	Dungeon fern spores give no experience */
    if(is_fern_spore(mtmp->data)) tmp = 0;

#ifdef MAIL
    /* Mail daemons put up no fight. */
    if(mtmp->data == &mons[PM_MAIL_DAEMON]) tmp = 1;
#endif

    return(tmp);
}
Exemple #5
0
/**
 * This is the main function of the DNS parser.
 *
 * This is where the each DNS 'answer' (or 'additional' or 'authoritative') 
 * record is parsed. Mostly, we ignore the return code, though some functions
 * pay attention to and provide slightly different information depending
 * upon the opcode.
 */
static void 
dns_parse_resource_record(struct Ferret *ferret, struct NetFrame *frame, 
						  const unsigned char *px, unsigned length, 
						  struct DNSRECORD *rec, struct DNS *dns)
{
	char name[512]; /* reserve a longer name than the max theoretical limit */
	unsigned name_length;
	char name2[512]; /* reserve a longer name than the max theoretical limit */
	unsigned name2_length;
	unsigned ip_address;
	unsigned offset = rec->rdata_offset;
	unsigned offset_max = MIN(rec->rdata_offset+rec->rdata_length, length);

	/* MULTICAST DNS (mDNS): handle the multicast DNS records differently
	 * from normal DNS records. */
	if (!dns->is_response && frame->dst_port == 5353) {
		bonjour_parse_resource_record(ferret, frame, px, length, rec, dns);
		return; 
	} else if (dns->is_response && (frame->src_port == 5353 || (frame->dst_port == 5353 && frame->src_port != 53))) {
		bonjour_parse_resource_record(ferret, frame, px, length, rec, dns);
		return;
	}

	/* NETBIOS: handle NetBIOS records differently from normal DNS records */
	if (!dns->is_response && frame->dst_port == 137) {
		netbios_parse_resource_record(ferret, frame, px, length, rec, dns);
		return; 
	} else if (dns->is_response && frame->src_port == 137) {
		netbios_parse_resource_record(ferret, frame, px, length, rec, dns);
		return;
	}


	/* First, let's extract a pretty version of the name */
	name_length = dns_extract_name(frame, px, length, rec->name_offset, name, sizeof(name));
	
	if (rec->type == 0x8001)
		FRAMERR(frame, "TODO\n");

	if (rec->clss == 0xfe)
		return;

	/* RFC2671 - Extension Mechanisms for DNS (EDNS0) */
	if (rec->type == 41) {
		/* Regress: defcon2008/dump000.pca(12541) */
		/* TODO: parse this */
		return;
	}

	/* Haven't implemented dynamic update yet
	 * TODO: */
	if (dns->opcode == 21 || dns->opcode == 5)
		return;

	switch (rec->type<<16 | rec->clss) {
	case TYPECLASS(1,0x8001): /* type=A(IPv4 address), class=INTERNET(cache flush) */
		bonjour_parse_resource_record(ferret, frame, px, length, rec, dns);
		break;
	case TYPECLASS(1,1): /* type=A(IPv4 address), class=INTERNET */
		if (!is_valid_opcode(dns->opcode, 0x10, 5, -1)) {
			FRAMERR(frame, "%s: unknown opcode=%d\n", "DNS", dns->opcode);
			return;
		}

		ip_address = ex32be(px+rec->rdata_offset);
		if (rec->rdata_length != 4)
			FRAMERR(frame, "dns: data not 4-bytes long, was %d-bytes instead (class=%d, type=%d, name=%s)\n", rec->rdata_length, rec->clss, rec->type, name);

		JOTDOWN(ferret,
			JOT_PRINT("ID-DNS", name,	name_length),
			JOT_IPv4("address",	ip_address),
			0);
		break;
	case TYPECLASS(2,1): /* type=NS, class=INTERNET */
		if (!is_valid_opcode(dns->opcode, 0x10, -1)) {
			FRAMERR(frame, "%s: unknown opcode=%d\n", "DNS", dns->opcode);
			return;
		}
		name2_length = dns_extract_name(frame, px, length, rec->rdata_offset, name2, sizeof(name2));
		ip_address = dns_resolve_alias(frame, px, length, dns, name2, 0);

		JOTDOWN(ferret,
			JOT_PRINT("ID-DNS",	name, name_length),
			JOT_PRINT("Name-Server", name2, name2_length),
			JOT_IPv4("address", ip_address),
			0);
		break;
	case TYPECLASS(5,1): /*type=CNAME(aliased canonical name), class=INTERNET */
		if (!is_valid_opcode(dns->opcode, 0x10, 5, -1)) {
			FRAMERR(frame, "%s: unknown opcode=%d\n", "DNS", dns->opcode);
			return;
		}
		name2_length = dns_extract_name(frame, px, length, rec->rdata_offset, name2, sizeof(name2));

		ip_address = dns_resolve_alias(frame, px, length, dns, name2, 0);

		if (ip_address != 0) {
			JOTDOWN(ferret,
				JOT_PRINT("ID-DNS", name,	name_length),
				JOT_IPv4("alias",ip_address),
				0);
		}
		JOTDOWN(ferret,
			JOT_PRINT("ID-DNS", name,	name_length),
			JOT_PRINT("alias", name2, name2_length),
			0);
		break;
	case TYPECLASS(6,1): /*type=SOA, class=INTERNET*/
		if (!is_valid_opcode(dns->opcode, 0x10, -1)) {
			FRAMERR(frame, "%s: unknown opcode=%d\n", "DNS", dns->opcode);
			return;
		}
		/*
		 * Authoritative Name Server
		 */
		name2_length = dns_extract_name(frame, px, length, offset, name2, sizeof(name2));
		JOTDOWN(ferret,
			JOT_PRINT("ID-DNS",	name, name_length),
			JOT_SZ("SOA", "Start of zone authority"),
			JOT_PRINT("Name-Server", name2, name2_length),
			0);
		ip_address = dns_resolve_alias(frame, px, length, dns, name2, 0);
		if (ip_address)
		JOTDOWN(ferret,
			JOT_PRINT("ID-DNS",	name, name_length),
			JOT_SZ("SOA", "Start of zone authority"),
			JOT_PRINT("Name-Server", name2, name2_length),
			JOT_IPv4("address", ip_address),
			0);
		skip_name(px, length, &offset);

		/* Contact */
		if (offset < offset_max) {
			name2_length = dns_extract_name(frame, px, length, offset, name2, sizeof(name2));
			JOTDOWN(ferret,
				JOT_PRINT("ID-DNS",	name, name_length),
				JOT_SZ("SOA", "Start of zone authority"),
				JOT_PRINT("Contact", name2, name2_length),
				0);
			skip_name(px, length, &offset);
		}

		break;
	case TYPECLASS(10,1): /* type=NULL, class=INTERNET*/
		/* Regress: defcon2008-dns2.pcap(100803): name=Vaaaaiaqaac.tunnel.fastcoder.net */
		/* I'm not sure what this is, other than passing data as Null records.
		 * This would be a good thing for an intrusion-detection system to trigger
		 * on. */
		break;
	case TYPECLASS(12,0x8001): /*type=PTR, class=INTERNET */
		bonjour_parse_resource_record(ferret, frame, px, length, rec, dns);
		break;
	case TYPECLASS(12,1): /*type=PTR(pointer reverse lookup), class=INTERNET */
		if (!is_valid_opcode(dns->opcode, 0x10, -1)) {
			FRAMERR(frame, "%s: unknown opcode=%d\n", "DNS", dns->opcode);
			return;
		}
		if (name_length > 6 && memcmp(name+name_length-6, ".local", 6) == 0) {

			JOTDOWN(ferret,
				JOT_SRC("ID-IP", frame),
				JOT_PRINT("Service", name,name_length),
				0);

			/* Extract MAC address */
			{
				const unsigned char *p_name;
				unsigned name_length;
				const unsigned char *p_mac = find_mac(px, MIN(length, rec->rdata_offset+rec->rdata_length), rec->rdata_offset, &p_name, &name_length);
				if (p_mac) {
					JOTDOWN(ferret,
						JOT_SRC("ID-IP", frame),
						JOT_PRINT("mac",		 	p_mac,						19),
						0);
					JOTDOWN(ferret,
						JOT_SRC("ID-IP", frame),
						JOT_PRINT("name",		 	p_name,						name_length),
						0);
				}
			}

		} else if (endsWith(name, ".in-addr.arpa")) {
			/* Extract a 4-byte IPv4 address 
			 * Example: "18.0.0.10.in-addr.arpa"*/
			unsigned ipv4=0;
			unsigned i;
			unsigned j=0;

			for (i=0; i<4; i++) {
				unsigned num = 0;

				for (; name[j] && name[j] != '.'; j++) {
					if ('0' <= name[j] && name[j] <= '9')
						num = num * 10 + name[j]-'0';
				}
				while (name[j] == '.')
					j++;
				ipv4 |= num<<(i*8);
			}
			/* Now get the name it points to */
			name2_length = dns_extract_name(frame, px, length, offset, name2, sizeof(name2));

			JOTDOWN(ferret,
				JOT_PRINT("ID-DNS", name2, name2_length),
				JOT_IPv4("ID-IP", ipv4),
				JOT_SRC("dnssrv", frame),
				0);
		} else
			; //FRAMERR(frame, "dns: unknown PTR record\n");
		break;
	case TYPECLASS(13,0x8001): /*type=HINFO, class=INTERNET */
		bonjour_parse_resource_record(ferret, frame, px, length, rec, dns);
		break;
	case TYPECLASS(15,1): /*type=MX, class=INTERNET */
		/* Regress: defcon2008-dns2.pcap(18661) */
		break;
	case TYPECLASS(16,0x8001):		/*type=TXT, class=INTERNET(cache flush)*/
		bonjour_parse_resource_record(ferret, frame, px, length, rec, dns);
		break;
	case TYPECLASS(16,1):		/*type=TXT, class=INTERNET */
		if (!is_valid_opcode(dns->opcode, 0x10, 5, -1)) {
			FRAMERR(frame, "%s: unknown opcode=%d\n", "DNS", dns->opcode);
			return;
		}

		if (stricmp(name, "current.cvd.clamav.net") == 0) {
			/* This is a single string containing a version string, like:
			 * 0.91.1:44:3855:1186270141:1
			 */
			break;
		} else if (starts_with("_DM-NOTIFICATION.", name, strlen(name))) {
			/* Regress: defcon2008\dump001.pcap(87082) */
			/* TODO */
			break;
		} else if (endsWith(name, "._workstation._tcp.local")) {
			/* Regress: defcon2008-dns2.pcap(56127): "mike-desktop [00:0c:29:f6:58:ca]._workstation._tcp.local" */
			break;
		} else if (endsWith(name, ".asn.cymru.com")) {
			/* Regress: defcon2008-dns2.pcap(98958) */
			/* This is a system for mapping IP to ASN numbers:
			 * http://www.team-cymru.org/Services/ip-to-asn.html */
			break;
		} else if (endsWith(name, ".wrs.trendmicro.com")) {
			/* Regress: defcon2008-dns2.pcap(184904) */
			/* Appears to check whether IP addresses are trustworthy */
			break;
		} else {
			FRAMERR(frame, "%s: unknown TXT record %s", "DNS", name);
		}
		break;
	case TYPECLASS(0x1c,1): /*type=AAAA(IPv6 address), class=INTERNET*/
	case TYPECLASS(0x1c,255): /*type=AAAA(IPv6 address), class=INTERNET*/
		if (!is_valid_opcode(dns->opcode, 0x10, 5, -1)) {
			FRAMERR(frame, "%s: unknown opcode=%d\n", "DNS", dns->opcode);
			return;
		}
		switch (dns->opcode) {
		case 0x10:
			{
				const unsigned char *ipv6_address = px+rec->rdata_offset;
				if (rec->rdata_length != 16)
					FRAMERR(frame, "dns: data not 16-bytes long, was %d-bytes instead (class=%d, type=%d, name=%s)\n", rec->rdata_length, rec->clss, rec->type, name);

				JOTDOWN(ferret,
					JOT_SZ("proto","DNS"),
					JOT_SZ("op","lookup"),
					JOT_SRC("ip.src", frame),
					JOT_PRINT("name", name, name_length),
					JOT_IPv6("address", ipv6_address,				16),
					0);
			}
		case 5: /* dynamic update*/
			/* Regress: defcon2008-dns2.pcap(7958) */
			break;
		default:
			FRAMERR(frame, "%s: unknown opcode=%d\n", "DNS", dns->opcode);
		}
		break;
	case TYPECLASS(33,1): /*type=SRV, class=INTERNET */
		if (!is_valid_opcode(dns->opcode, 0x10, -1)) {
			FRAMERR(frame, "%s: unknown opcode=%d\n", "DNS", dns->opcode);
			return;
		}

		if (rec->rdata_length < 7)
			FRAMERR(frame, "dns: unknown type=%d (class=%d, name=%s)\n", rec->type, rec->clss, name);
		else {
			unsigned port = px[rec->rdata_offset+4]<<8 | px[rec->rdata_offset+5];
			name2_length = dns_extract_name(frame, px, length, rec->rdata_offset+6, name2, sizeof(name2));
			ip_address = dns_resolve_alias(frame, px, length, dns, name2, 0);

			if (ip_address != 0) {
				JOTDOWN(ferret,
					JOT_PRINT("ID-DNS", name,	name_length),
					JOT_PRINT("Server", name2,	name2_length),
					JOT_NUM("Port", port),
					JOT_IPv4("IPv4",ip_address),
					0);
			} else
				JOTDOWN(ferret,
					JOT_PRINT("ID-DNS", name,	name_length),
					JOT_PRINT("Server", name2,	name2_length),
					JOT_NUM("Port", port),
					0);
		}
		break;
	default:
		FRAMERR(frame, "dns: unknown type=%d (class=%d, name=%s)\n", rec->type, rec->clss, name);
	}
}
/* return TRUE if the caller needs to place the ball and chain down again
 *
 *  Should not be called while swallowed.  Should be called before movement,
 *  because we might want to move the ball or chain to the hero's old position.
 *
 * It is called if we are moving.  It is also called if we are teleporting
 * *if* the ball doesn't move and we thus must drag the chain.  It is not
 * called for ordinary teleportation.
 *
 * allow_drag is only used in the ugly special case where teleporting must
 * drag the chain, while an identical-looking movement must drag both the ball
 * and chain.
 */
boolean
drag_ball(xchar x, xchar y, int *bc_control, xchar * ballx, xchar * bally,
          xchar * chainx, xchar * chainy, boolean * cause_delay,
          boolean allow_drag)
{
    struct trap *t = NULL;
    boolean already_in_rock;

    *ballx = uball->ox;
    *bally = uball->oy;
    *chainx = uchain->ox;
    *chainy = uchain->oy;
    *bc_control = 0;
    *cause_delay = FALSE;

    if (dist2(x, y, uchain->ox, uchain->oy) <= 2) {     /* nothing moved */
        move_bc(1, *bc_control, *ballx, *bally, *chainx, *chainy);
        return TRUE;
    }

    /* only need to move the chain? */
    if (carried(uball) || distmin(x, y, uball->ox, uball->oy) <= 2) {
        xchar oldchainx = uchain->ox, oldchainy = uchain->oy;

        *bc_control = BC_CHAIN;
        move_bc(1, *bc_control, *ballx, *bally, *chainx, *chainy);
        if (carried(uball)) {
            /* move chain only if necessary */
            if (distmin(x, y, uchain->ox, uchain->oy) > 1) {
                *chainx = u.ux;
                *chainy = u.uy;
            }
            return TRUE;
        }
#define CHAIN_IN_MIDDLE(chx, chy) \
    (distmin(x, y, chx, chy) <= 1 && \
     distmin(chx, chy, uball->ox, uball->oy) <= 1)
#define IS_CHAIN_ROCK(x,y) \
    (IS_ROCK(level->locations[x][y].typ) || \
     (IS_DOOR(level->locations[x][y].typ) && \
      (level->locations[x][y].doormask & (D_CLOSED|D_LOCKED))))
/* Don't ever move the chain into solid rock.  If we have to, then instead
 * undo the move_bc() and jump to the drag ball code.  Note that this also
 * means the "cannot carry and drag" message will not appear, since unless we
 * moved at least two squares there is no possibility of the chain position
 * being in solid rock.
 */
#define SKIP_TO_DRAG { *chainx = oldchainx; *chainy = oldchainy; \
    move_bc(0, *bc_control, *ballx, *bally, *chainx, *chainy); \
    goto drag; }
        if (IS_CHAIN_ROCK(u.ux, u.uy) || IS_CHAIN_ROCK(*chainx, *chainy)
            || IS_CHAIN_ROCK(uball->ox, uball->oy))
            already_in_rock = TRUE;
        else
            already_in_rock = FALSE;

        switch (dist2(x, y, uball->ox, uball->oy)) {
            /* two spaces diagonal from ball, move chain inbetween */
        case 8:
            *chainx = (uball->ox + x) / 2;
            *chainy = (uball->oy + y) / 2;
            if (IS_CHAIN_ROCK(*chainx, *chainy) && !already_in_rock)
                SKIP_TO_DRAG;
            break;

            /* player is distance 2/1 from ball; move chain to one of the two
               spaces between @ __ 0 */
        case 5:{
                xchar tempx, tempy, tempx2, tempy2;

                /* find position closest to current position of chain */
                /* no effect if current position is already OK */
                if (abs(x - uball->ox) == 1) {
                    tempx = x;
                    tempx2 = uball->ox;
                    tempy = tempy2 = (uball->oy + y) / 2;
                } else {
                    tempx = tempx2 = (uball->ox + x) / 2;
                    tempy = y;
                    tempy2 = uball->oy;
                }
                if (IS_CHAIN_ROCK(tempx, tempy) &&
                    !IS_CHAIN_ROCK(tempx2, tempy2) && !already_in_rock) {
                    if (allow_drag) {
                        /* Avoid pathological case *if* not teleporting: 0 0_
                           _X move northeast -----> X@ @ */
                        if (dist2(u.ux, u.uy, uball->ox, uball->oy) == 5 &&
                            dist2(x, y, tempx, tempy) == 1)
                            SKIP_TO_DRAG;
                        /* Avoid pathological case *if* not teleporting: 0 0 _X 
                           move east -----> X_ @ @ */
                        if (dist2(u.ux, u.uy, uball->ox, uball->oy) == 4 &&
                            dist2(x, y, tempx, tempy) == 2)
                            SKIP_TO_DRAG;
                    }
                    *chainx = tempx2;
                    *chainy = tempy2;
                } else if (!IS_CHAIN_ROCK(tempx, tempy) &&
                           IS_CHAIN_ROCK(tempx2, tempy2) && !already_in_rock) {
                    if (allow_drag) {
                        if (dist2(u.ux, u.uy, uball->ox, uball->oy) == 5 &&
                            dist2(x, y, tempx2, tempy2) == 1)
                            SKIP_TO_DRAG;
                        if (dist2(u.ux, u.uy, uball->ox, uball->oy) == 4 &&
                            dist2(x, y, tempx2, tempy2) == 2)
                            SKIP_TO_DRAG;
                    }
                    *chainx = tempx;
                    *chainy = tempy;
                } else if (IS_CHAIN_ROCK(tempx, tempy) &&
                           IS_CHAIN_ROCK(tempx2, tempy2) && !already_in_rock) {
                    SKIP_TO_DRAG;
                } else if (dist2(tempx, tempy, uchain->ox, uchain->oy) <
                           dist2(tempx2, tempy2, uchain->ox, uchain->oy) ||
                           ((dist2(tempx, tempy, uchain->ox, uchain->oy) ==
                             dist2(tempx2, tempy2, uchain->ox, uchain->oy)) &&
                            rn2(2))) {
                    *chainx = tempx;
                    *chainy = tempy;
                } else {
                    *chainx = tempx2;
                    *chainy = tempy2;
                }
                break;
            }

            /* ball is two spaces horizontal or vertical from player; move */
            /* chain inbetween *unless* current chain position is OK */
        case 4:
            if (CHAIN_IN_MIDDLE(uchain->ox, uchain->oy))
                break;
            *chainx = (x + uball->ox) / 2;
            *chainy = (y + uball->oy) / 2;
            if (IS_CHAIN_ROCK(*chainx, *chainy) && !already_in_rock)
                SKIP_TO_DRAG;
            break;

            /* ball is one space diagonal from player.  Check for the following 
               special case: @ _ moving southwest becomes @_ 0 0 (This will
               also catch teleporting that happens to resemble this case, but
               oh well.) Otherwise fall through. */
        case 2:
            if (dist2(x, y, uball->ox, uball->oy) == 2 &&
                dist2(x, y, uchain->ox, uchain->oy) == 4) {
                if (uchain->oy == y)
                    *chainx = uball->ox;
                else
                    *chainy = uball->oy;
                if (IS_CHAIN_ROCK(*chainx, *chainy) && !already_in_rock)
                    SKIP_TO_DRAG;
                break;
            }
            /* fall through */
        case 1:
        case 0:
            /* do nothing if possible */
            if (CHAIN_IN_MIDDLE(uchain->ox, uchain->oy))
                break;
            /* otherwise try to drag chain to player's old position */
            if (CHAIN_IN_MIDDLE(u.ux, u.uy)) {
                *chainx = u.ux;
                *chainy = u.uy;
                break;
            }
            /* otherwise use player's new position (they must have teleported,
               for this to happen) */
            *chainx = x;
            *chainy = y;
            break;

        default:
            impossible("bad chain movement");
            break;
        }
#undef SKIP_TO_DRAG
#undef IS_CHAIN_ROCK
#undef CHAIN_IN_MIDDLE
        return TRUE;
    }

drag:

    if (near_capacity() > SLT_ENCUMBER && dist2(x, y, u.ux, u.uy) <= 2) {
        pline("You cannot %sdrag the heavy iron ball.",
              invent ? "carry all that and also " : "");
        action_completed();
        return FALSE;
    }

    if ((is_pool(level, uchain->ox, uchain->oy) &&
         /* water not mere continuation of previous water */
         (level->locations[uchain->ox][uchain->oy].typ == POOL ||
          !is_pool(level, uball->ox, uball->oy) ||
          level->locations[uball->ox][uball->oy].typ == POOL))
        || ((t = t_at(level, uchain->ox, uchain->oy)) &&
            (t->ttyp == PIT || t->ttyp == SPIKED_PIT || t->ttyp == HOLE ||
             t->ttyp == TRAPDOOR))) {

        if (Levitation) {
            pline("You feel a tug from the iron ball.");
            if (t)
                t->tseen = 1;
        } else {
            struct monst *victim;

            pline("You are jerked back by the iron ball!");
            if ((victim = m_at(level, uchain->ox, uchain->oy)) != 0) {
                int tmp;

                tmp = -2 + Luck + find_mac(victim);
                tmp += omon_adj(victim, uball, TRUE);
                if (tmp >= rnd(20))
                    hmon(victim, uball, 1);
                else
                    miss(xname(uball), victim);

            }   /* now check again in case mon died */
            if (!m_at(level, uchain->ox, uchain->oy)) {
                u.ux = uchain->ox;
                u.uy = uchain->oy;
                newsym(u.ux0, u.uy0);
            }
            action_interrupted();

            *bc_control = BC_BALL;
            move_bc(1, *bc_control, *ballx, *bally, *chainx, *chainy);
            *ballx = uchain->ox;
            *bally = uchain->oy;
            move_bc(0, *bc_control, *ballx, *bally, *chainx, *chainy);
            spoteffects(TRUE);
            return FALSE;
        }
    }

    *bc_control = BC_BALL | BC_CHAIN;

    move_bc(1, *bc_control, *ballx, *bally, *chainx, *chainy);
    if (dist2(x, y, u.ux, u.uy) > 2) {
        /* Awful case: we're still in range of the ball, so we thought we could 
           only move the chain, but it turned out that the target square for
           the chain was rock, so we had to drag it instead. But we can't drag
           it either, because we teleported and are more than one square from
           our old position.  Revert to the teleport behavior. */
        *ballx = *chainx = x;
        *bally = *chainy = y;
    } else {
        *ballx = uchain->ox;
        *bally = uchain->oy;
        *chainx = u.ux;
        *chainy = u.uy;
    }
    *cause_delay = TRUE;
    return TRUE;
}
Exemple #7
0
  int readInterfaces(HSP *sp)
  {
    
    char *a;
    u_char dest_mac[6];
    struct sockaddr_in *foo;
    if(sp->adaptorList == NULL) sp->adaptorList = adaptorListNew();
    else adaptorListReset(sp->adaptorList);
    
    // Walk the interfaces and collect the non-loopback interfaces so that we
    // have a list of MAC addresses for each interface (usually only 1).
    //
    // May need to come back and run a variation of this where we supply
    // a domain and collect the virtual interfaces for that domain in a
    // similar way.  It looks like we do that by just parsing the numbers
    // out of the interface name.
    
    struct ifaddrs *ifap;
    
    getifaddrs(&ifap);
    for(struct ifaddrs *ifp = ifap; ifp; ifp = ifp->ifa_next) {
      char *devName = ifp->ifa_name;
      if(devName) {
	devName = trimWhitespace(devName);
	// Get the flags for this interface
	int up = (ifp->ifa_flags & IFF_UP) ? YES : NO;
	int loopback = (ifp->ifa_flags & IFF_LOOPBACK) ? YES : NO;
	int promisc =  (ifp->ifa_flags & IFF_PROMISC) ? YES : NO;
	int address_family = ifp->ifa_addr->sa_family;
	if(debug > 1) {
	  myLog(LOG_INFO, "reading interface %s (up=%d, loopback=%d, family=%d)",
		devName,
		up,
		loopback,
		address_family);
	}
	//int hasBroadcast = (ifp->ifa_flags & IFF_BROADCAST);
	//int pointToPoint = (ifp->ifa_flags & IFF_POINTOPOINT);
	
	if(up && !loopback && address_family == AF_INET) {
	  
	  /***** THE NEW WAY ******/
	  
	  find_mac(devName,&dest_mac[0]);
	  SFLAdaptor *adaptor = adaptorListAdd(sp->adaptorList, devName, 
					       (u_char *)&dest_mac); 
	  /*
	    SFLAdaptor *adaptor = adaptorListAdd(sp->adaptorList, devName, 
	    (u_char *)&(ifp->ifa_addr->sa_data)); 
	  */
	  adaptor->promiscuous = promisc;
	  
	  address_family = ifp->ifa_addr->sa_family;
	  
	  if(debug > 1) {
	    myLog(LOG_INFO, "Device: %s",devName);
	    myLog(LOG_INFO, "Address family: %d",address_family);
	  }
	  
	  foo = (struct sockaddr_in *)&ifp->ifa_addr;
	  if (address_family == AF_INET) {
	    
	    a=(char *)&(ifp->ifa_addr->sa_data);
	    a++; a++; // Yep... it really is 2 bytes over 
	    // Only IPV4 below ....
	    memcpy(&adaptor->ipAddr.addr, a, 4);
	    if(debug > 1) {
	      myLog(LOG_INFO, "My IP address = %d.%d.%d.%d", a[0], a[1], a[2], a[3]);
	    }
	  }
	}	  
      }
    }
    updateAdaptorNIO(sp);
    freeifaddrs(ifap);
    return sp->adaptorList->num_adaptors;
    
  }
Exemple #8
0
static void
make_player_info(struct nh_player_info *pi)
{
    int cap, advskills, i;

    memset(pi, 0, sizeof (struct nh_player_info));

    pi->moves = moves;
    strncpy(pi->plname, u.uplname, sizeof (pi->plname));
    pi->align = u.ualign.type;

    /* This function could be called before the game is fully inited. Test
       youmonst.data as it is required for near_capacity().
       program_state.game_running is no good, as we need this data before
       game_running is set.

       TODO: Wow this is hacky. */
    if (!youmonst.data)
        return;
    API_ENTRY_CHECKPOINT_RETURN_VOID_ON_ERROR();

    pi->x = youmonst.mx;
    pi->y = youmonst.my;
    pi->z = u.uz.dlevel;

    if (Upolyd) {
        strncpy(pi->rank, msgtitlecase(mons[u.umonnum].mname),
                sizeof (pi->rank));
    } else
        strncpy(pi->rank, rank(), sizeof (pi->rank));

    strncpy(pi->rolename, (u.ufemale && urole.name.f) ?
            urole.name.f : urole.name.m, sizeof (pi->rolename));
    strncpy(pi->racename, urace.noun, sizeof (pi->racename));
    strncpy(pi->gendername, genders[u.ufemale].adj,
            sizeof(pi->gendername));

    pi->max_rank_sz = mrank_sz;

    /* abilities */
    pi->st = ACURR(A_STR);
    pi->st_extra = 0;
    if (pi->st > 118) {
        pi->st = pi->st - 100;
        pi->st_extra = 0;
    } else if (pi->st > 18) {
        pi->st_extra = pi->st - 18;
        pi->st = 18;
    }

    pi->dx = ACURR(A_DEX);
    pi->co = ACURR(A_CON);
    pi->in = ACURR(A_INT);
    pi->wi = ACURR(A_WIS);
    pi->ch = ACURR(A_CHA);

    pi->score = botl_score();

    /* hp and energy */
    pi->hp = Upolyd ? u.mh : u.uhp;
    pi->hpmax = Upolyd ? u.mhmax : u.uhpmax;
    if (pi->hp < 0)
        pi->hp = 0;

    pi->en = u.uen;
    pi->enmax = u.uenmax;
    pi->ac = find_mac(&youmonst);

    pi->gold = money_cnt(invent);
    pi->coinsym = def_oc_syms[COIN_CLASS];
    describe_level(pi->level_desc);

    pi->monnum = u.umonster;
    pi->cur_monnum = u.umonnum;

    /* level and exp points */
    if (Upolyd)
        pi->level = mons[u.umonnum].mlevel;
    else
        pi->level = youmonst.m_lev;
    pi->xp = youmonst.exp;

    cap = near_capacity();

    /* check if any skills could be anhanced */
    advskills = 0;
    for (i = 0; i < P_NUM_SKILLS; i++) {
        if (P_RESTRICTED(i))
            continue;
        if (can_advance(i, FALSE))
            advskills++;
    }
    pi->can_enhance = advskills > 0;

    /* add status items for various problems there can be at most 24 items here 
       at any one time or we overflow the buffer */
    if (hu_stat[u.uhs]) /* 1 */
        strncpy(pi->statusitems[pi->nr_items++], hu_stat[u.uhs], ITEMLEN);

    if (Confusion)      /* 2 */
        strncpy(pi->statusitems[pi->nr_items++], "Conf", ITEMLEN);

    if (sick(&youmonst)) { /* 3 */
        if (u.usick_type & SICK_VOMITABLE)
            strncpy(pi->statusitems[pi->nr_items++], "FoodPois", ITEMLEN);
        if (u.usick_type & SICK_NONVOMITABLE)
            strncpy(pi->statusitems[pi->nr_items++], "Ill", ITEMLEN);
    }
    if (Blind)  /* 4 */
        strncpy(pi->statusitems[pi->nr_items++], "Blind", ITEMLEN);
    if (slippery_fingers(&youmonst))   /* 5 */
        strncpy(pi->statusitems[pi->nr_items++], "Greasy", ITEMLEN);
    if (leg_hurt(&youmonst))       /* 6 */
        strncpy(pi->statusitems[pi->nr_items++], "Lame", ITEMLEN);
    if (stunned(&youmonst))        /* 7 */
        strncpy(pi->statusitems[pi->nr_items++], "Stun", ITEMLEN);
    if (hallucinating(&youmonst))  /* 8 */
        strncpy(pi->statusitems[pi->nr_items++], "Hallu", ITEMLEN);
    if (strangled(&youmonst))      /* 9 */
        strncpy(pi->statusitems[pi->nr_items++], "Strangle", ITEMLEN);
    if (sliming(&youmonst))        /* 10 */
        strncpy(pi->statusitems[pi->nr_items++], "Slime", ITEMLEN);
    if (petrifying(&youmonst))     /* 11 */
        strncpy(pi->statusitems[pi->nr_items++], "Petrify", ITEMLEN);
    if (u.ustuck && !Engulfed && !sticks(youmonst.data))      /* 12 */
        strncpy(pi->statusitems[pi->nr_items++], "Held", ITEMLEN);
    if (enc_stat[cap]           )  /* 13 */
        strncpy(pi->statusitems[pi->nr_items++], enc_stat[cap], ITEMLEN);
    if (cancelled(&youmonst))
        strncpy(pi->statusitems[pi->nr_items++], "Cancelled", ITEMLEN);
    if (slow(&youmonst))
        strncpy(pi->statusitems[pi->nr_items++], "Slow", ITEMLEN);
    if (Levitation)     /* 14 */
        strncpy(pi->statusitems[pi->nr_items++], "Lev", ITEMLEN);
    else if (Flying)
        strncpy(pi->statusitems[pi->nr_items++], "Fly", ITEMLEN);
    if (uwep && is_pick(uwep)) /* 15 (first case) */
        strncpy(pi->statusitems[pi->nr_items++], "Dig", ITEMLEN);
    else if (uwep && is_launcher(uwep))
        strncpy(pi->statusitems[pi->nr_items++], "Ranged", ITEMLEN);
    else if (uwep && (uwep->otyp == CORPSE) && (touch_petrifies(&mons[uwep->corpsenm])))
        strncpy(pi->statusitems[pi->nr_items++], "cWielded", ITEMLEN);
    else if (!uwep)
        strncpy(pi->statusitems[pi->nr_items++], "Unarmed", ITEMLEN);
    else if (!is_wep(uwep))
        strncpy(pi->statusitems[pi->nr_items++], "NonWeap", ITEMLEN);
    else {
        /* strncpy(pi->statusitems[pi->nr_items++], "Melee", ITEMLEN); */
        /* Don't show the default Melee status light, as that's the most common case. */
        /* 15 (last case) */
    }
    if (u.utrap)        /* 16 */
        strncpy(pi->statusitems[pi->nr_items++], trap_stat[u.utraptype],
                ITEMLEN);

    API_EXIT();
}
void *pcap_function(void *arg)
{
	char *iface = (char *) arg;
	char errbuf[PCAP_ERRBUF_SIZE];
	pcap_t * handle = NULL;
	struct ieee80211_radiotap_header * rtap_head;
	struct ieee80211_header * eh;
	struct pcap_pkthdr header;
	const u_char * packet;
	u_char * mac;
	u_char first_flags;
	int offset = 0;
	char rssi;
	Element * dev_info;
	
	u_char alc_mac[6];
	string_to_mac("00:73:8d:9e:cb:ab", alc_mac);
	
	// Open pcap handle to sniff traffic
	handle = pcap_open_live(iface, BUFSIZ, 1, 1000, errbuf);
	if (handle == NULL) {
		printf("Could not open pcap on %s\n", iface);
		pthread_exit((void *) -1);
	}

	while (got_sigint == 0) {
		packet = pcap_next(handle, &header);
		if (!packet)
			continue;

		rtap_head = (struct ieee80211_radiotap_header *) packet;

		int len = (int) rtap_head->it_len[0] + 256 * (int) rtap_head->it_len[1];
		eh = (struct ieee80211_header *) (packet + len);
		if ((eh->frame_control & 0x03) == 0x01) {
			mac = eh->source_addr;
			first_flags = rtap_head->it_present[0];
			u_char* last_flag = &rtap_head->it_present[3];
			offset = 8;
			offset += ((first_flags & 0x01) == 0x01) ? 8 : 0 ;
			offset += ((first_flags & 0x02) == 0x02) ? 1 : 0 ;
			offset += ((first_flags & 0x04) == 0x04) ? 1 : 0 ;
			offset += ((first_flags & 0x08) == 0x08) ? 4 : 0 ;
			offset += ((first_flags & 0x10) == 0x10) ? 2 : 0 ;
			/*while((*(last_flag) & 0x80) == 0x80)
			{
				offset += 4;
				last_flag += 4;
			}*/
			rssi = *((char *) rtap_head + 18) - 0x100;
			if(rssi == 4)
				continue;
			
			printf("RADIOTAP Header Dump :\n");
			printf("\t%x\n\t%x\n\t%x\t%x\n", rtap_head->it_version, rtap_head->it_pad, rtap_head->it_len[0], rtap_head->it_len[1]);
			printf("\t%x\t%x\t%x\t%x\n", rtap_head->it_present[0], rtap_head->it_present[1], rtap_head->it_present[2], rtap_head->it_present[3]);
			int i;
			for(i=0 ; i<len ; i+=4)
			{
				if(len-i > 4)
				{
					printf("\t%x\t%x\t%x\t%x\n", *( (u_char*)rtap_head + i), *( (u_char*)rtap_head + i+1), *( (u_char*)rtap_head + i+2), *( (u_char*)rtap_head + i+3));
				}
				else
				{
					int j;
					for(j=i; j<len ; ++j)
					{
						printf("\t%x", *( (u_char*)rtap_head + j));
					}					
					break;
				}
				
					
			}
			
			printf("%d bytes -- %02X:%02X:%02X:%02X:%02X:%02X -- RSSI: %d dBm\n",
			       len, mac[0], mac[1], mac[2], mac[3], mac[4], mac[5], (int) rssi);
			// We got some message issued by a terminal (FromDS=0,ToDS=1)
			sem_wait(&synchro);
			if ((dev_info = find_mac(rssi_list, mac)) == NULL) {
				dev_info = add_element(&rssi_list, mac);
			}
			clear_outdated_values(&dev_info->measurements);
			add_value(&dev_info->measurements, (int) rssi);
			
			if ((dev_info = find_mac(rssi_list, alc_mac)) != NULL) {
				print_element(dev_info);
			}
			sem_post(&synchro);
		}
	}
	pcap_close(handle);
	pthread_exit((void *) 0);
}
Exemple #10
0
/* an object launched by someone/thing other than player attacks a monster;
   return 1 if the object has stopped moving (hit or its range used up) */
int
ohitmon(struct monst *mtmp, /* accidental target */
        struct obj *otmp,   /* missile; might be destroyed by drop_throw */
        int range,  /* how much farther will object travel if it misses */
        /* Use -1 to signify to keep going even after hit, unless it's gone
           (used for rolling_boulder_traps) */
        boolean verbose) {  /* give message(s) even when you can't see what
                               happened */
    int damage, tmp;
    boolean vis, ismimic;
    int objgone = 1;

    ismimic = mtmp->m_ap_type && mtmp->m_ap_type != M_AP_MONSTER;
    vis = cansee(bhitpos.x, bhitpos.y);

    tmp = 5 + find_mac(mtmp) + omon_adj(mtmp, otmp, FALSE);
    if (tmp < rnd(20)) {
        if (!ismimic) {
            if (vis)
                miss(distant_name(otmp, mshot_xname), mtmp);
            else if (verbose)
                pline("It is missed.");
        }
        if (!range) {   /* Last position; object drops */
            if (is_pole(otmp))
                return 1;

            drop_throw(otmp, 0, mtmp->mx, mtmp->my);
            return 1;
        }
    } else if (otmp->oclass == POTION_CLASS) {
        if (ismimic)
            seemimic(mtmp);
        mtmp->msleeping = 0;
        if (vis)
            otmp->dknown = 1;
        potionhit(mtmp, otmp, FALSE);
        return 1;
    } else {
        damage = dmgval(otmp, mtmp);

        if (otmp->otyp == ACID_VENOM && resists_acid(mtmp))
            damage = 0;
        if (otmp->otyp == VAMPIRE_BLOOD && resists_drli(mtmp))
            damage = 0;
        if (ismimic)
            seemimic(mtmp);
        mtmp->msleeping = 0;
        if (vis)
            hit(distant_name(otmp, mshot_xname), mtmp, exclam(damage));
        else if (verbose)
            pline("%s is hit%s", Monnam(mtmp), exclam(damage));

        if (otmp->opoisoned && is_poisonable(otmp)) {
            if (resists_poison(mtmp)) {
                if (vis)
                    pline("The poison doesn't seem to affect %s.",
                          mon_nam(mtmp));
            } else {
                if (rn2(30)) {
                    damage += rnd(6);
                } else {
                    if (vis)
                        pline("The poison was deadly...");
                    damage = mtmp->mhp;
                }
            }
        }
        if (objects[otmp->otyp].oc_material == SILVER &&
            hates_silver(mtmp->data)) {
            if (vis)
                pline("The silver sears %s flesh!", s_suffix(mon_nam(mtmp)));
            else if (verbose)
                pline("Its flesh is seared!");
        }
        if (otmp->otyp == ACID_VENOM && cansee(mtmp->mx, mtmp->my)) {
            if (resists_acid(mtmp)) {
                if (vis || verbose)
                    pline("%s is unaffected.", Monnam(mtmp));
                damage = 0;
            } else {
                if (vis)
                    pline("The acid burns %s!", mon_nam(mtmp));
                else if (verbose)
                    pline("It is burned!");
            }
        }
        mtmp->mhp -= damage;
        if (mtmp->mhp < 1) {
            if (vis || verbose)
                pline("%s is %s!", Monnam(mtmp),
                      (nonliving(mtmp->data) || !canclassifymon(mtmp))
                      ? "destroyed" : "killed");
            /* don't blame hero for unknown rolling boulder trap */
            if (!flags.mon_moving &&
                (otmp->otyp != BOULDER || range >= 0 || otmp->otrapped))
                xkilled(mtmp, 0);
            else
                mondied(mtmp);
        }

        if (can_blnd
            (NULL, mtmp,
             (uchar) (otmp->otyp == BLINDING_VENOM ? AT_SPIT : AT_WEAP),
             otmp)) {
            if (vis && mtmp->mcansee)
                pline("%s is blinded by %s.", Monnam(mtmp), the(xname(otmp)));
            mtmp->mcansee = 0;
            tmp = (int)mtmp->mblinded + rnd(25) + 20;
            if (tmp > 127)
                tmp = 127;
            mtmp->mblinded = tmp;
        }

        if (otmp->otyp == VAMPIRE_BLOOD) {
            if (!resists_drli(mtmp)) {
                int xtmp = dice(2, 6);
                if (vis)
                    pline("%s suddenly seems weaker!", Monnam(mtmp));
                mtmp->mhpmax -= xtmp;
                if ((mtmp->mhp -= xtmp) <= 0 || !mtmp->m_lev) {
                    if (vis)
                        pline("%s dies!", Monnam(mtmp));
                    xkilled(mtmp, 0);
                } else
                    mtmp->m_lev--;
            }
            obfree(otmp, NULL);
            return 1;
        }

        if (is_pole(otmp))
            return 1;

        objgone = drop_throw(otmp, 1, bhitpos.x, bhitpos.y);
        if (!objgone && range == -1) {  /* special case */
            obj_extract_self(otmp);     /* free it for motion again */
            return 0;
        }
        return 1;
    }
    return 0;
}
void
mstatusline(struct monst *mtmp)
{
    aligntyp alignment;
    const char *info, *monnambuf;

    if (mtmp->ispriest || (mtmp->isminion && roamer_type(mtmp->data)))
        alignment = CONST_EPRI(mtmp)->shralign;
    else if (mtmp->isminion)
        alignment = EMIN(mtmp)->min_align;
    else {
        alignment = mtmp->data->maligntyp;
        alignment =
            (alignment > 0) ? A_LAWFUL :
            (alignment == A_NONE) ? A_NONE :
            (alignment < 0) ? A_CHAOTIC : A_NEUTRAL;
    }

    info = "";
    if (mtmp->mtame) {
        info = msgcat(info, ", tame");
        if (wizard) {
            info = msgprintf("%s (%d", info, mtmp->mtame);
            if (!mtmp->isminion)
                info = msgprintf("%s; hungry %u; apport %d", info,
                                 EDOG(mtmp)->hungrytime, EDOG(mtmp)->apport);
            info = msgcat(info, ")");
        }
    } else if (mtmp->mpeaceful)
        info = msgcat(info, ", peaceful");
    if (mtmp->meating)
        info = msgcat(info, ", eating");
    if (mtmp->mcan)
        info = msgcat(info, ", cancelled");
    if (mtmp->mconf)
        info = msgcat(info, ", confused");
    if (mtmp->mblinded || !mtmp->mcansee)
        info = msgcat(info, ", blind");
    if (mtmp->mstun)
        info = msgcat(info, ", stunned");
    if (mtmp->msleeping)
        info = msgcat(info, ", asleep");
    else if (mtmp->mfrozen || !mtmp->mcanmove)
        info = msgcat(info, ", can't move");
    /* [arbitrary reason why it isn't moving] */
    else if (mtmp->mstrategy & STRAT_WAITMASK)
        info = msgcat(info, ", meditating");
    else if (mtmp->mflee)
        info = msgcat(info, ", scared");
    if (mtmp->mtrapped)
        info = msgcat(info, ", trapped");
    if (mtmp->mspeed)
        info = msgcat(info,
                      mtmp->mspeed == MFAST ? ", fast" :
                      mtmp->mspeed == MSLOW ? ", slow" : ", ???? speed");
    if (mtmp->mundetected)
        info = msgcat(info, ", concealed");
    if (mtmp->minvis)
        info = msgcat(info, ", invisible");
    if (mtmp == u.ustuck)
        info = msgcat(info,
                      (sticks(youmonst.data)) ? ", held by you" : Engulfed
                      ? (is_animal(u.ustuck->data) ? ", swallowed you" :
                         ", engulfed you") : ", holding you");
    if (mtmp == u.usteed)
        info = msgcat(info, ", carrying you");

    /* avoid "Status of the invisible newt ..., invisible" */
    /* and unlike a normal mon_nam, use "saddled" even if it has a name */
    monnambuf = x_monnam(mtmp, ARTICLE_THE, NULL,
                         (SUPPRESS_IT | SUPPRESS_INVISIBLE), FALSE);

    pline("Status of %s (%s):  Level %d  HP %d(%d)  Def %d%s.", monnambuf,
          align_str(alignment), mtmp->m_lev, mtmp->mhp, mtmp->mhpmax,
          10 - find_mac(mtmp), info);
}
Exemple #12
0
void NetGuard_Command_Input_WH8::got_input(std::vector<std::string> params, std::vector<int> intparams, std::string command)
{
	//here you get all commands send to netguard
	//in params you see the commands - intparams get filled if the param is an int and in command you see the unparsed input
	if (params[0] == "version")
	{
		ng_logext(100,"%s - Version: %s build: %s from %s at %s with %s",NetGuard_NAME, NetGuard_VERSION,NetGuard_COMPILE_DATE,NetGuard_COMPILE_BY,NetGuard_COMPILE_HOST,NetGuard_COMPILER);
	}

	if (params[0] == "help")
	{
		ng_logout("wh8_mac <mac> - search for an mac in the hostel");
		ng_logout("wh8_mac_dump <mac> - search for an mac in the hostel - and display the status of the port where it was found");
		ng_logout("wh8_ip <ip> - show status of a port based on a given hostel ip");
		ng_logout("wh8_loaduser - load all logins from a db containing login -> ip");
		ng_logout("wh8_loadrooms - load all rooms from a db containing ip -> room");
		ng_logout("wh8_set_login <ip> <login> - set hostel login - like loadusers");
		ng_logout("wh8_clear_history <ip> - !!caution!! delete history for ip");
	}

	if (params[0] == "wh8_loaduser")
	{
		user_state_load_logins();
	}

	if (params[0] == "wh8_loadrooms")
	{
		user_state_load_rooms();
	}


	if (params[0] == "wh8_mac")
	{
		if (params.size() < 1)
		{
			ng_logout_ret(RET_WRONG_SYNTAX,"usage: wh8_mac <mac>");
			return;
		}
		mac_addr mac;
		if (!getmacfromchar(params[1].c_str(), &mac))
		{
			ng_logout_ret(RET_WRONG_SYNTAX,"usage: wh8_mac <mac>");
			return;
		}
		string room;
		u_int32_t ip;
		int port;
		if (find_mac(mac,&ip,&port,&room)) {
			ng_logout_ok("found room: %s \t\t-ip %s -port %d",room.c_str(),inet_ntoa(*(struct in_addr *)&ip),port);
		} else ng_logout_not_found("room not found!");
	}

	if (params[0] == "wh8_mac_dump")
	{
		if (params.size() < 1)
		{
			ng_logout_ret(RET_WRONG_SYNTAX,"usage: wh8_mac <mac>");
			return;
		}
		mac_addr mac;
		if (!getmacfromchar(params[1].c_str(), &mac))
		{
			ng_logout_ret(RET_WRONG_SYNTAX,"usage: wh8_mac <mac>");
			return;
		}
		string room;
		u_int32_t ip;
		int port;
		if (find_mac(mac,&ip,&port,&room)) {
			ng_logout("found room: %s \t\t-ip %s -port %d",room.c_str(),inet_ntoa(*(struct in_addr *)&ip),port);
			ng_logout("port details - admin status:[%d] max macs:[%d] learned macs:[%d]",getadminstatus(ip,port),getmaxmacs(ip,port),getmacslearned(ip,port));

			mac_vector macs = getmacs(ip,port);
			mac_vector::iterator it;
			for (it=macs.begin(); it != macs.end(); it++) {
				mac_addr *mymac = (*it);
				ng_logout("port learned mac: %02x:%02x:%02x:%02x:%02x:%02x", printf_mac_params((*mymac)));
			}
			macs.clear();
		} else ng_logout_not_found("room not found!");
	}

	if (params[0] == "wh8_ip")
	{
		if (params.size() < 1)
		{
			ng_logout_ret(RET_WRONG_SYNTAX,"usage: wh8_ip <ip>");
			return;
		}

		struct in_addr m_ip;
		if (!inet_aton(params[1].c_str(),&m_ip ))
		{	
			ng_logout_ret(RET_WRONG_SYNTAX,"usage: %s <ip>",params[0].c_str());
			return;
		}
		string room;
		u_int32_t ip;
		int port;
		if (resolve_room(&(m_ip.s_addr),&ip,&port)) {
			ng_logout("found room: %s \t\t-ip %s -port %d",room.c_str(),inet_ntoa(*(struct in_addr *)&ip),port);
			ng_logout("port details - admin status:[%d] max macs:[%d] learned macs:[%d]",getadminstatus(ip,port),getmaxmacs(ip,port),getmacslearned(ip,port));

			mac_vector macs = getmacs(ip,port);
			mac_vector::iterator it;
			for (it=macs.begin(); it != macs.end(); it++) {
				mac_addr *mymac = (*it);
				ng_logout("port learned mac: %02x:%02x:%02x:%02x:%02x:%02x", printf_mac_params((*mymac)));
			}
			macs.clear();
		} else ng_logout_not_found("room not found!");
	}

	if (params[0] == "wh8_set_login")
	{
		if (params.size() < 2)
		{
			ng_logout_ret(RET_WRONG_SYNTAX,"usage: wh8_set_login <ip> <login>");
			return;
		}

		struct in_addr m_ip;
		if (!inet_aton(params[1].c_str(),&m_ip ))
		{	
			ng_logout_ret(RET_WRONG_SYNTAX,"usage: wh8_set_login <ip> <login>",params[0].c_str());
			return;
		}

		unsigned int tmpvlan = (GlobalCFG::GetInt("wh8.user_vlan",0));
		struct user_data *u_data = muser_data->get_user(&m_ip.s_addr,&tmpvlan);
		if (!u_data) {
			ng_logout_not_found("user not found!");
			return;
		}
		if (u_data->saddr != m_ip.s_addr) {
			ng_logout_not_found("user not found!");
			return;
		}
		NetGuard_User_State *user_state = NetGuard_State_Handler::user_state(u_data);
		if (!user_state) return;
		user_state->params()->SetStr("login",params[2]);
		ng_logout_ok("user updated");

	}

	if (params[0] == "wh8_clear_history")
	{
		if (params.size() < 1)
		{
			ng_logout_ret(RET_WRONG_SYNTAX,"usage: wh8_clear_history <ip>");
			return;
		}

		struct in_addr m_ip;
		if (!inet_aton(params[1].c_str(),&m_ip ))
		{	
			ng_logout_ret(RET_WRONG_SYNTAX,"usage: wh8_set_login <ip> <login>",params[0].c_str());
			return;
		}

		unsigned int tmpvlan = (GlobalCFG::GetInt("wh8.user_vlan",0));
		struct user_data *u_data = muser_data->get_user(&m_ip.s_addr,&tmpvlan);
		if (!u_data) {
			ng_logout_not_found("user not found!");
			return;
		}
		if (u_data->saddr != m_ip.s_addr) {
			ng_logout_not_found("user not found!");
			return;
		}
		NetGuard_User_State *user_state = NetGuard_State_Handler::user_state(u_data);
		if (!user_state) return;
		user_state->clear();
		ng_logout_ok("user history cleared");

	}

}