static void parse_arp(arp_hdr *a) { char mac1[macbuf_size]; char mac2[macbuf_size]; char ip1[ipbuf_size]; char ip2[ipbuf_size]; print_mac(mac1, &a->snd_hw_addr); print_mac(mac2, &a->target_hw_addr); print_ip(ip1, &a->snd_prot_addr); print_ip(ip2, &a->target_prot_addr); if (PA_ARP) { switch(ntohs(a->op)) { case arp_op_request: printf(" REQ from %s (%s) for %s\n", mac1, ip1, ip2); break; case arp_op_reply: printf(" REPLY from %s (%s), target = %s (%s)\n", mac1, ip1, mac2, ip2); break; case arp_op_rarp_request: printf(" RARP REQ from %s (%s) for %s\n", mac1, ip1, ip2); break; case arp_op_rarp_reply: printf(" RARP REPLY from %s (%s), target = %s (%s)\n", mac1, ip1, mac2, ip2); break; } } }
static void print_stuff() { printf("tmr now = %ss\n", time_now_f()); printf("SDK version: %s\n", system_get_sdk_version()); printf("APP version: %s built: %s %s\n", BUILD_DATE, __DATE__, __TIME__); printf("CPU freq was %d\n", system_get_cpu_freq()); printf("CPU freq = %d\n", set_cpu_freq(160)); printf("tmr now = %ss\n", time_now_f()); printf("tout = %sV\n", ffp(3, read_tout(0)*123/10)); printf("vdd = %sV\n", ffp(3, read_vdd())); print_mac(STATION_IF); print_mac(SOFTAP_IF); print_ip_info(SOFTAP_IF); print_ip_info(STATION_IF); printf("tmr now = %ss\n", time_now_f()); printf("sleeping 2s\n"); system_deep_sleep(2*1000000); vTaskDelete(NULL); }
void dissect_ether(const u_char *packet) { ether_hdr *hdr = (ether_hdr*) packet; u_char *pdu = (u_char*)(packet + 14); uint16 ether_type = ntohs(hdr->ether_type); print_line(); printf("Dst MAC: "); print_mac(hdr->dst_MAC); printf("\n"); printf("Src MAC: "); print_mac(hdr->src_MAC); printf("\n"); switch(ether_type){ case ETHER_TYPE_VLAN: dissect_vlan(pdu); break; case ETHER_TYPE_IPv4: dissect_ipv4(pdu); break; case ETHER_TYPE_IPv6: dissect_ipv6(pdu); break; case ETHER_TYPE_ARP: dissect_arp(pdu); break; default: printf("Ether type is: %x\n", ether_type); break; } }
static void dump_ehdr(struct ethhdr *ehdr) { DECLARE_MAC_BUF(mac); DECLARE_MAC_BUF(mac2); printk("ehdr[h_dst(%s)" "h_source(%s)" "h_proto(%04x)]\n", print_mac(mac, ehdr->h_dest), print_mac(mac2, ehdr->h_source), ehdr->h_proto); }
static inline void nlm_vnet_dump_ether_hdr(struct ethhdr* eth) { DECLARE_MAC_BUF(dest); DECLARE_MAC_BUF(src); VNET_DBG("eth header: dest %s source %s proto %04x\n", print_mac(dest, eth->h_dest), print_mac(src, eth->h_source), ntohs(eth->h_proto)); }
short update_asset_arp(u_int8_t arp_sha[MAC_ADDR_LEN], packetinfo *pi) { if (asset_lookup(pi) == SUCCESS) { if (pi->asset != NULL) { goto arp_update; } else { printf("\nBAD ERROR in update_asset_arp\n"); return ERROR; } } else { add_asset(pi); update_asset(pi); if ( pi->asset == NULL ) { elog("update_asset(pi) failed! Asset does not exist! Cant enter MAC!!! die();\n"); return ERROR; } if (update_asset_arp(arp_sha, pi) == SUCCESS) { return SUCCESS; } else { return ERROR; } } arp_update: /* Check the ARP data structure for an existing entry */ if (memcmp(pi->asset->mac_addr, arp_sha, MAC_ADDR_LEN) == 0) { /* UPDATE TIME STAMP */ pi->asset->last_seen = pi->pheader->ts.tv_sec; return SUCCESS; } else { /* UPDATE MAC AND TIME STAMP */ /* XXX: this handler suxx! */ if(memcmp(pi->asset->mac_addr, "\0\0\0\0\0\0", 6)){ printf("ACHTUNG! MAC changed! : "); print_mac(pi->asset->mac_addr); printf(" -> "); print_mac(arp_sha); printf("\n"); } if(pi->asset->macentry == NULL) { // vendor entry did not exist. mac_entry *match = match_mac(config.sig_mac, arp_sha, 48); pi->asset->macentry = match; } memcpy(&pi->asset->mac_addr, arp_sha, MAC_ADDR_LEN); pi->asset->last_seen = pi->pheader->ts.tv_sec; log_asset_arp(pi->asset); return SUCCESS; } }
static void print_mac_and_mask(const unsigned char *mac, const unsigned char *mask, int l) { int i; print_mac(mac, l); for (i = 0; i < l ; i++) if (mask[i] != 255) break; if (i == l) return; printf("/"); print_mac(mask, l); }
void emit_dbus_signal(int action, struct dhcp_lease *lease, char *hostname) { DBusConnection *connection = (DBusConnection *)daemon->dbus; DBusMessage* message = NULL; DBusMessageIter args; char *action_str, *mac = daemon->namebuff; unsigned char *p; int i; if (!connection) return; if (!hostname) hostname = ""; #ifdef HAVE_DHCP6 if (lease->flags & (LEASE_TA | LEASE_NA)) { print_mac(mac, lease->clid, lease->clid_len); inet_ntop(AF_INET6, lease->hwaddr, daemon->addrbuff, ADDRSTRLEN); } else #endif { p = extended_hwaddr(lease->hwaddr_type, lease->hwaddr_len, lease->hwaddr, lease->clid_len, lease->clid, &i); print_mac(mac, p, i); inet_ntop(AF_INET, &lease->addr, daemon->addrbuff, ADDRSTRLEN); } if (action == ACTION_DEL) action_str = "DhcpLeaseDeleted"; else if (action == ACTION_ADD) action_str = "DhcpLeaseAdded"; else if (action == ACTION_OLD) action_str = "DhcpLeaseUpdated"; else return; if (!(message = dbus_message_new_signal(DNSMASQ_PATH, daemon->dbus_name, action_str))) return; dbus_message_iter_init_append(message, &args); if (dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &daemon->addrbuff) && dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &mac) && dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &hostname)) dbus_connection_send(connection, message, NULL); dbus_message_unref(message); }
/* Saves the union ipt_matchinfo in parsable form to stdout. */ static void save(const struct ipt_ip *ip, const struct ipt_entry_match *match) { if (((struct ipt_mac_info *)match->data)->invert) printf("! "); if (((struct ipt_mac_info *)match->data)->type==0) { printf("--mac-source "); print_mac(((struct ipt_mac_info *)match->data)->srcaddr); }else { printf("--mac-destination "); print_mac(((struct ipt_mac_info *)match->data)->srcaddr); } }
static void ieee80211_key_enable_hw_accel(struct ieee80211_key *key) { const u8 *addr; int ret; DECLARE_MAC_BUF(mac); assert_key_lock(); might_sleep(); if (!key->local->ops->set_key) return; addr = get_mac_for_key(key); ret = key->local->ops->set_key(local_to_hw(key->local), SET_KEY, key->sdata->dev->dev_addr, addr, &key->conf); if (!ret) { spin_lock(&todo_lock); key->flags |= KEY_FLAG_UPLOADED_TO_HARDWARE; spin_unlock(&todo_lock); } if (ret && ret != -ENOSPC && ret != -EOPNOTSUPP) printk(KERN_ERR "mac80211-%s: failed to set key " "(%d, %s) to hardware (%d)\n", wiphy_name(key->local->hw.wiphy), key->conf.keyidx, print_mac(mac, addr), ret); }
void ieee80211_sta_debugfs_add(struct sta_info *sta) { struct dentry *stations_dir = sta->local->debugfs.stations; DECLARE_MAC_BUF(mbuf); u8 *mac; if (!stations_dir) return; mac = print_mac(mbuf, sta->addr); sta->debugfs.dir = debugfs_create_dir(mac, stations_dir); if (!sta->debugfs.dir) return; DEBUGFS_ADD(flags); DEBUGFS_ADD(num_ps_buf_frames); DEBUGFS_ADD(inactive_ms); DEBUGFS_ADD(last_seq_ctrl); #ifdef CONFIG_MAC80211_DEBUG_COUNTERS DEBUGFS_ADD(wme_rx_queue); DEBUGFS_ADD(wme_tx_queue); #endif DEBUGFS_ADD(agg_status); }
static void ieee80211_key_disable_hw_accel(struct ieee80211_key *key) { const u8 *addr; int ret; DECLARE_MAC_BUF(mac); assert_key_lock(); might_sleep(); if (!key || !key->local->ops->set_key) return; spin_lock(&todo_lock); if (!(key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)) { spin_unlock(&todo_lock); return; } spin_unlock(&todo_lock); addr = get_mac_for_key(key); ret = key->local->ops->set_key(local_to_hw(key->local), DISABLE_KEY, key->sdata->dev->dev_addr, addr, &key->conf); if (ret) printk(KERN_ERR "mac80211-%s: failed to remove key " "(%d, %s) from hardware (%d)\n", wiphy_name(key->local->hw.wiphy), key->conf.keyidx, print_mac(mac, addr), ret); spin_lock(&todo_lock); key->flags &= ~KEY_FLAG_UPLOADED_TO_HARDWARE; spin_unlock(&todo_lock); }
//int convert_mac_str2hex(char *str1, char *hex) int convert_mac_str2hex(void) { /* std::string mac = "00:00:12:24:36:4f"; unsigned u[6]; int c=sscanf(mac.c_str(),"%x:%x:%x:%x:%x:%x",u,u+1,u+2,u+3,u+4,u+5); if (c!=6) raise_error("input format error"); uint64_t r=0; for (int i=0;i<6;i++) r=(r<<8)+u[i]; or: for (int i=0;i<6;i++) r=(r<<8)+u[5-i]; */ const char *str = STR; unsigned u[6]; int c = sscanf(str, "%x:%x:%x:%x:%x:%x", u, u + 1, u + 2, u + 3, u + 4, u + 5); if (c != 6) { printf("input format error\n"); } uint64_t r = 0; int i = 0; for (i = 0; i < 6; i++) { r = (r << 8) + u[i]; } printf("%02X\n", (char )u[0]); printf("%02X\n", u[1]); printf("%02X\n", u[2]); print_mac(u, 6); return 0; }
int zd_mac_set_mac_address(struct net_device *netdev, void *p) { int r; unsigned long flags; struct sockaddr *addr = p; struct zd_mac *mac = zd_netdev_mac(netdev); struct zd_chip *chip = &mac->chip; DECLARE_MAC_BUF(mac2); if (!is_valid_ether_addr(addr->sa_data)) return -EADDRNOTAVAIL; dev_dbg_f(zd_mac_dev(mac), "Setting MAC to %s\n", print_mac(mac2, addr->sa_data)); r = zd_write_mac_addr(chip, addr->sa_data); if (r) return r; spin_lock_irqsave(&mac->lock, flags); memcpy(netdev->dev_addr, addr->sa_data, ETH_ALEN); spin_unlock_irqrestore(&mac->lock, flags); return 0; }
/* Saves the union ip6t_matchinfo in parsable form to stdout. */ static void save(const struct ip6t_ip6 *ip, const struct ip6t_entry_match *match) { if (((struct ip6t_mac_info *)match->data)->invert) printf("! "); printf("--mac-source "); print_mac(((struct ip6t_mac_info *)match->data)->srcaddr); }
static void mac80211_hwsim_remove_interface( struct ieee80211_hw *hw, struct ieee80211_if_init_conf *conf) { DECLARE_MAC_BUF(mac); printk(KERN_DEBUG "%s:%s (type=%d mac_addr=%s)\n", wiphy_name(hw->wiphy), __func__, conf->type, print_mac(mac, conf->mac_addr)); }
struct network_dev *e1000_init() { struct network_dev *device = kcalloc(sizeof(*device), 1); struct e1000 *e = (struct e1000 *)kmalloc(sizeof(*e)); e1000_global = e; device->device = e; e->dev = device; e->pci = pci_get_device(INTEL_VEND, E1000_DEV); if(e->pci == NULL) { e->pci = pci_get_device(INTEL_VEND, 0x109a); } if(e->pci == NULL) { e->pci = pci_get_device(INTEL_VEND, 0x100f); } if(e->pci != NULL) { e->pci_hdr = e->pci->header; printf("Intel Pro/1000 Ethernet adapter Rev %i found at ", e->pci_hdr->rev); e->io_base = pci_get_bar(e->pci, PCI_BAR_IO) & ~1; printf("I/O base address %x\n",e->io_base); //e->mem_base = (uint8_t *)(pci_get_bar(e->pci, PCI_BAR_MEM) & ~3); //printf("mem base %x\n",e->mem_base); printf("IRQ %i PIN %i\n",e->pci_hdr->int_line, e->pci_hdr->int_pin); e1000_eeprom_gettype(e); e1000_getmac(e, (char *)device->mac); print_mac((char *)&device->mac); // for(int i = 0; i < 6; i++) // e1000_outb(e,0x5400 + i, device->mac[i]); pci_register_irq(e->pci, &e1000_handler, e); e1000_start(e); device->send = e1000_send; // device->receive = e1000_receive; uint32_t flags = e1000_inl(e, REG_RCTRL); e1000_outl(e, REG_RCTRL, flags | RCTRL_EN);//RCTRL_8192 | RCTRL_MPE | RCTRL_UPE |RCTRL_EN); } else { kfree(e); kfree(device); e = NULL; device = NULL; } return device; }
/* Saves the union ipt_matchinfo in parsable form to stdout. */ static void save(const struct ipt_ip *ip, const struct ipt_entry_match *match) { if(((struct ipt_mac_info *)match->data)->flag & IPTMAC_SRC){ if (((struct ipt_mac_info *)match->data)->invert & IPTMAC_SRC) printf("! "); printf("--mac-source "); print_mac(((struct ipt_mac_info *)match->data)->srcaddr); } if(((struct ipt_mac_info *)match->data)->flag & IPTMAC_DST){ if (((struct ipt_mac_info *)match->data)->invert & IPTMAC_DST) printf("! "); printf("--mac-dest "); print_mac(((struct ipt_mac_info *)match->data)->dstaddr); } }
/* Prints out the matchinfo. */ static void print(const struct ip6t_ip6 *ip, const struct ip6t_entry_match *match, int numeric) { printf("MAC "); print_mac(((struct ip6t_mac_info *)match->data)->srcaddr, ((struct ip6t_mac_info *)match->data)->invert); }
static void mac_print(const void *ip, const struct xt_entry_match *match, int numeric) { struct xt_mac_info *macinfo = (struct xt_mac_info *)(match->data); if (macinfo->flags & MAC_SRC) { printf("source MAC "); if (macinfo->flags & MAC_SRC_INV) printf("! "); print_mac(&macinfo->srcaddr); } if (macinfo->flags & MAC_DST) { printf("destination MAC "); if (macinfo->flags & MAC_DST_INV) printf("! "); print_mac(&macinfo->dstaddr); } }
static int start_xmit(struct sk_buff *skb, struct net_device *dev) { struct virtnet_info *vi = netdev_priv(dev); int num, err; struct scatterlist sg[1+MAX_SKB_FRAGS]; struct virtio_net_hdr *hdr; const unsigned char *dest = ((struct ethhdr *)skb->data)->h_dest; DECLARE_MAC_BUF(mac); sg_init_table(sg, 1+MAX_SKB_FRAGS); pr_debug("%s: xmit %p %s\n", dev->name, skb, print_mac(mac, dest)); free_old_xmit_skbs(vi); /* Encode metadata header at front. */ hdr = skb_vnet_hdr(skb); if (skb->ip_summed == CHECKSUM_PARTIAL) { hdr->flags = VIRTIO_NET_HDR_F_NEEDS_CSUM; hdr->csum_start = skb->csum_start - skb_headroom(skb); hdr->csum_offset = skb->csum_offset; } else { hdr->flags = 0; hdr->csum_offset = hdr->csum_start = 0; } if (skb_is_gso(skb)) { hdr->gso_size = skb_shinfo(skb)->gso_size; if (skb_shinfo(skb)->gso_type & SKB_GSO_TCP_ECN) hdr->gso_type = VIRTIO_NET_HDR_GSO_TCPV4_ECN; else if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV4) hdr->gso_type = VIRTIO_NET_HDR_GSO_TCPV4; else if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6) hdr->gso_type = VIRTIO_NET_HDR_GSO_TCPV6; else if (skb_shinfo(skb)->gso_type & SKB_GSO_UDP) hdr->gso_type = VIRTIO_NET_HDR_GSO_UDP; else BUG(); } else { hdr->gso_type = VIRTIO_NET_HDR_GSO_NONE; hdr->gso_size = 0; } vnet_hdr_to_sg(sg, skb); num = skb_to_sgvec(skb, sg+1, 0, skb->len) + 1; __skb_queue_head(&vi->send, skb); err = vi->svq->vq_ops->add_buf(vi->svq, sg, num, 0, skb); if (err) { pr_debug("%s: virtio not prepared to send\n", dev->name); skb_unlink(skb, &vi->send); netif_stop_queue(dev); return NETDEV_TX_BUSY; } vi->svq->vq_ops->kick(vi->svq); return 0; }
/* Prints out the matchinfo. */ static void mac_print(const void *ip, const struct xt_entry_match *match, int numeric) { printf("MAC "); if (((struct xt_mac_info *)match->data)->invert) printf("! "); print_mac(((struct xt_mac_info *)match->data)->srcaddr); }
static void mac_save(const void *ip, const struct xt_entry_match *match) { const struct xt_mac_info *info = (void *)match->data; if (info->invert) printf("! "); printf("--mac-source "); print_mac(info->srcaddr); }
static void zd_op_configure_filter(struct ieee80211_hw *hw, unsigned int changed_flags, unsigned int *new_flags, int mc_count, struct dev_mc_list *mclist) { struct zd_mc_hash hash; struct zd_mac *mac = zd_hw_mac(hw); unsigned long flags; int i; /* Only deal with supported flags */ changed_flags &= SUPPORTED_FIF_FLAGS; *new_flags &= SUPPORTED_FIF_FLAGS; /* changed_flags is always populated but this driver * doesn't support all FIF flags so its possible we don't * need to do anything */ if (!changed_flags) return; if (*new_flags & (FIF_PROMISC_IN_BSS | FIF_ALLMULTI)) { zd_mc_add_all(&hash); } else { DECLARE_MAC_BUF(macbuf); zd_mc_clear(&hash); for (i = 0; i < mc_count; i++) { if (!mclist) break; dev_dbg_f(zd_mac_dev(mac), "mc addr %s\n", print_mac(macbuf, mclist->dmi_addr)); zd_mc_add_addr(&hash, mclist->dmi_addr); mclist = mclist->next; } } spin_lock_irqsave(&mac->lock, flags); mac->pass_failed_fcs = !!(*new_flags & FIF_FCSFAIL); mac->pass_ctrl = !!(*new_flags & FIF_CONTROL); mac->multicast_hash = hash; spin_unlock_irqrestore(&mac->lock, flags); queue_work(zd_workqueue, &mac->set_multicast_hash_work); if (changed_flags & FIF_CONTROL) queue_work(zd_workqueue, &mac->set_rx_filter_work); /* no handling required for FIF_OTHER_BSS as we don't currently * do BSSID filtering */ /* FIXME: in future it would be nice to enable the probe response * filter (so that the driver doesn't see them) until * FIF_BCN_PRBRESP_PROMISC is set. however due to atomicity here, we'd * have to schedule work to enable prbresp reception, which might * happen too late. For now we'll just listen and forward them all the * time. */ }
static char *eth_addr2str(struct tipc_media_addr *a, char *str_buf, int str_size) { unchar *addr = (unchar *)&a->dev_addr; DECLARE_MAC_BUF(mac); if (str_size < 18) *str_buf = '\0'; else sprintf(str_buf, "%s", print_mac(mac, addr)); return str_buf; }
void dump_arp() { struct arp_entry *t; for( t = arptable ; t ; t=t->next ) { printf("dump_arp: %0x ", t->ip); print_mac(t->mac); printf("\n"); } }
static void mac_save(const void *ip, const struct xt_entry_match *match) { struct xt_mac_info *macinfo = (struct xt_mac_info *)(match->data); if (macinfo->flags & MAC_SRC) { if (macinfo->flags & MAC_SRC_INV) printf("! "); printf("--mac-source "); print_mac(&macinfo->srcaddr); if (macinfo->flags & MAC_DST) fputc(' ', stdout); } if (macinfo->flags & MAC_DST) { if (macinfo->flags & MAC_DST_INV) printf("! "); printf("--mac-destination "); print_mac(&macinfo->dstaddr); } }
/* * Set the station MAC address. * Note that the passed-in value must already be in network byte order. */ int netxen_niu_macaddr_set(struct netxen_adapter *adapter, netxen_ethernet_macaddr_t addr) { u8 temp[4]; u32 val; int phy = adapter->physical_port; unsigned char mac_addr[6]; int i; DECLARE_MAC_BUF(mac); for (i = 0; i < 10; i++) { temp[0] = temp[1] = 0; memcpy(temp + 2, addr, 2); val = le32_to_cpu(*(__le32 *)temp); if (netxen_nic_hw_write_wx (adapter, NETXEN_NIU_GB_STATION_ADDR_1(phy), &val, 4)) return -EIO; memcpy(temp, ((u8 *) addr) + 2, sizeof(__le32)); val = le32_to_cpu(*(__le32 *)temp); if (netxen_nic_hw_write_wx (adapter, NETXEN_NIU_GB_STATION_ADDR_0(phy), &val, 4)) return -2; netxen_niu_macaddr_get(adapter, (netxen_ethernet_macaddr_t *) mac_addr); if (memcmp(mac_addr, addr, 6) == 0) break; } if (i == 10) { printk(KERN_ERR "%s: cannot set Mac addr for %s\n", netxen_nic_driver_name, adapter->netdev->name); printk(KERN_ERR "MAC address set: %s.\n", print_mac(mac, addr)); printk(KERN_ERR "MAC address get: %s.\n", print_mac(mac, mac_addr)); } return 0; }
void ieee80211_debugfs_key_sta_link(struct ieee80211_key *key, struct sta_info *sta) { char buf[50]; DECLARE_MAC_BUF(mac); if (!key->debugfs.dir) return; sprintf(buf, "../../stations/%s", print_mac(mac, sta->addr)); key->debugfs.stalink = debugfs_create_symlink("station", key->debugfs.dir, buf); }
static inline void load_eaddr(struct net_device *dev) { int i; DECLARE_MAC_BUF(mac); u64 macaddr; DPRINTK("Loading MAC Address: %s\n", print_mac(mac, dev->dev_addr)); macaddr = 0; for (i = 0; i < 6; i++) macaddr |= (u64)dev->dev_addr[i] << ((5 - i) * 8); mace->eth.mac_addr = macaddr; }