/*-----------------------------------------------------------------------------------*/ static void low_level_init(struct netif *netif) { struct tunif *tunif; char buf[sizeof(IFCONFIG_CALL) + 50]; tunif = (struct tunif *)netif->state; /* Obtain MAC address from network interface. */ /* Do whatever else is needed to initialize interface. */ tunif->fd = open("/dev/tun0", O_RDWR); LWIP_DEBUGF(TUNIF_DEBUG, ("tunif_init: fd %d\n", tunif->fd)); if (tunif->fd == -1) { perror("tunif_init"); exit(1); } sprintf(buf, IFCONFIG_CALL, ip4_addr1(&(netif->gw)), ip4_addr2(&(netif->gw)), ip4_addr3(&(netif->gw)), ip4_addr4(&(netif->gw)), ip4_addr1(&(netif->ip_addr)), ip4_addr2(&(netif->ip_addr)), ip4_addr3(&(netif->ip_addr)), ip4_addr4(&(netif->ip_addr))); LWIP_DEBUGF(TUNIF_DEBUG, ("tunif_init: system(\"%s\");\n", buf)); system(buf); sys_thread_new("tunif_thread", tunif_thread, netif, DEFAULT_THREAD_STACKSIZE, DEFAULT_THREAD_PRIO); }
int ethGetNetConfig(u8 *ip_address, u8 *netmask, u8 *gateway) { t_ip_info ip_info; int result; if((result = ps2ip_getconfig("sm0", &ip_info)) >= 0) { ip_address[0] = ip4_addr1((struct ip_addr*)&ip_info.ipaddr); ip_address[1] = ip4_addr2((struct ip_addr*)&ip_info.ipaddr); ip_address[2] = ip4_addr3((struct ip_addr*)&ip_info.ipaddr); ip_address[3] = ip4_addr4((struct ip_addr*)&ip_info.ipaddr); netmask[0] = ip4_addr1((struct ip_addr*)&ip_info.netmask); netmask[1] = ip4_addr2((struct ip_addr*)&ip_info.netmask); netmask[2] = ip4_addr3((struct ip_addr*)&ip_info.netmask); netmask[3] = ip4_addr4((struct ip_addr*)&ip_info.netmask); gateway[0] = ip4_addr1((struct ip_addr*)&ip_info.gw); gateway[1] = ip4_addr2((struct ip_addr*)&ip_info.gw); gateway[2] = ip4_addr3((struct ip_addr*)&ip_info.gw); gateway[3] = ip4_addr4((struct ip_addr*)&ip_info.gw); }else{ memset(ip_address, 0, 4); memset(netmask, 0, 4); memset(gateway, 0, 4); } return result; }
/*-----------------------------------------------------------------------------------*/ static void low_level_init(struct netif *netif) { struct tunif *tunif; char buf[100]; tunif = netif->state; /* Obtain MAC address from network interface. */ /* Do whatever else is needed to initialize interface. */ tunif->fd = open("/dev/tun0", O_RDWR); DEBUGF(TUNIF_DEBUG, ("tunif_init: fd %d\n", tunif->fd)); if(tunif->fd == -1) { perror("tunif_init"); exit(1); } snprintf(buf, sizeof(buf), "ifconfig tun0 inet %d.%d.%d.%d %d.%d.%d.%d", ip4_addr1(&(netif->gw)), ip4_addr2(&(netif->gw)), ip4_addr3(&(netif->gw)), ip4_addr4(&(netif->gw)), ip4_addr1(&(netif->ip_addr)), ip4_addr2(&(netif->ip_addr)), ip4_addr3(&(netif->ip_addr)), ip4_addr4(&(netif->ip_addr))); DEBUGF(TUNIF_DEBUG, ("tunif_init: system(\"%s\");\n", buf)); system(buf); sys_thread_new(tunif_thread, netif); }
static void show_netif_config(struct netif *netif) { diag_printf( "%c%c%d: IP: %d.%d.%d.%d Submask: %d.%d.%d.%d Gateway: %d.%d.%d.%d\n", netif->name[0], netif->name[1], netif->num, ip4_addr1(&netif->ip_addr), ip4_addr2(&netif->ip_addr), ip4_addr3(&netif->ip_addr), ip4_addr4(&netif->ip_addr), ip4_addr1(&netif->netmask), ip4_addr2(&netif->netmask), ip4_addr3(&netif->netmask), ip4_addr4(&netif->netmask), ip4_addr1(&netif->gw), ip4_addr2(&netif->gw), ip4_addr3(&netif->gw), ip4_addr4(&netif->gw) ); }
/****************************************************************************** * Name: print_ip * Description: Prints network address information to standard output * * Arguments: char *msg - the message to print * struct ip_addr *ip - the IP address to print ******************************************************************************/ void print_ip( char *msg, struct ip_addr *ip ) { xil_printf( msg ); xil_printf( "%d.%d.%d.%d\n\r", ip4_addr1(ip), ip4_addr2(ip), ip4_addr3(ip), ip4_addr4(ip) ); } /* print_ip */
/* * get_ip_addr() * * This routine is called by InterNiche to obtain an IP address for the * specified network adapter. Like the MAC address, obtaining an IP address is * very system-dependant and therefore this function is exported for the * developer to control. * * In our system, we are either attempting DHCP auto-negotiation of IP address, * or we are setting our own static IP, Gateway, and Subnet Mask addresses our * self. This routine is where that happens. */ int get_ip_addr(alt_iniche_dev *p_dev, ip_addr* ipaddr, ip_addr* netmask, ip_addr* gw, int* use_dhcp) { IP4_ADDR(*ipaddr, IPADDR0, IPADDR1, IPADDR2, IPADDR3); IP4_ADDR(*gw, GWADDR0, GWADDR1, GWADDR2, GWADDR3); IP4_ADDR(*netmask, MSKADDR0, MSKADDR1, MSKADDR2, MSKADDR3); #ifdef DHCP_CLIENT *use_dhcp = 1; #else /* not DHCP_CLIENT */ *use_dhcp = 0; printf("Static IP Address is %d.%d.%d.%d\n", ip4_addr1(*ipaddr), ip4_addr2(*ipaddr), ip4_addr3(*ipaddr), ip4_addr4(*ipaddr)); #endif /* not DHCP_CLIENT */ /* Non-standard API: return 1 for success */ return 1; }
static void sys_net_status_changed(u8 status) { #if TLS_CONFIG_TLS_DEBUG struct tls_ethif * ethif; #endif switch(status) { case NETIF_WIFI_JOIN_SUCCESS: TLS_DBGPRT_INFO("join net success\n"); tls_sys_net_up(); break; case NETIF_WIFI_JOIN_FAILED: TLS_DBGPRT_INFO("join net failed\n"); tls_sys_connect_failed(); break; case NETIF_WIFI_DISCONNECTED: TLS_DBGPRT_INFO("net disconnected\n"); tls_sys_net_down(); break; case NETIF_IP_NET_UP: #if TLS_CONFIG_TLS_DEBUG ethif = tls_netif_get_ethif(); TLS_DBGPRT_INFO("net up ==> ip = %d.%d.%d.%d\n",ip4_addr1(ðif->ip_addr.addr),ip4_addr2(ðif->ip_addr.addr), ip4_addr3(ðif->ip_addr.addr),ip4_addr4(ðif->ip_addr.addr)); #endif break; default: break; } }
void create_raw_socket_server_demo(void) { struct tls_ethif * ethif; ethif = tls_netif_get_ethif(); printf("\nip=%d.%d.%d.%d\n",ip4_addr1(ðif->ip_addr.addr),ip4_addr2(ðif->ip_addr.addr), ip4_addr3(ðif->ip_addr.addr),ip4_addr4(ðif->ip_addr.addr)); DemoRawSockOneshotSendMac(); memset(&socket_desc, 0, sizeof(struct tls_socket_desc)); socket_desc.recvf = raw_sk_server_recv; socket_desc.errf = raw_sk_server_err; socket_desc.pollf = raw_sk_server_poll; socket_desc.cs_mode = SOCKET_CS_MODE_SERVER; socket_desc.acceptf = raw_sk_server_accept; socket_desc.protocol = SOCKET_PROTO_TCP; socket_desc.port = LocalPort; printf("\nlisten port=%d\n",socket_desc.port); if(gDemoSys.socket_ok != true) { tls_socket_create(&socket_desc); } }
static err_t ethernetif_igmp_mac_filter(struct netif *netif, ip_addr_t *group, u8_t action) { u8 m_addr[6] = {0x01, 0x00, 0x5E}; int ret = ERR_OK; LWIP_DEBUGF(IGMP_DEBUG, ("IPaddr: %d.%d.%d.%d\n", ip4_addr1(&group->addr), ip4_addr2(&group->addr), ip4_addr3(&group->addr), ip4_addr4(&group->addr))); //create group mac address: memcpy(m_addr+3, (u8*)&(group->addr)+1, 3); m_addr[3] &= 0x7F; //clear bit24 LWIP_DEBUGF(IGMP_DEBUG, ("MACaddr: %x:%x:%x:%x:%x:%x\n",m_addr[0], m_addr[1], m_addr[2], m_addr[3], m_addr[4], m_addr[5])); if(action == IGMP_ADD_MAC_FILTER) { ret = tls_hw_set_multicast_key(m_addr); } else if(action == IGMP_DEL_MAC_FILTER) { ret = tls_hw_del_multicast_key(m_addr); } if (ret < 0) return ret; else return ERR_OK; }
void prvvMBPortReleaseClient( struct tcp_pcb *pxPCB ) { if( pxPCB != NULL ) { if( tcp_close( pxPCB ) != ERR_OK ) { tcp_abort( pxPCB ); } if( pxPCB == pxPCBClient ) { #ifdef MB_TCP_DEBUG vMBPortLog( MB_LOG_DEBUG, "MBTCP-CLOSE", "Closed connection to %d.%d.%d.%d.\r\n", ip4_addr1( &( pxPCB->remote_ip ) ), ip4_addr2( &( pxPCB->remote_ip ) ), ip4_addr3( &( pxPCB->remote_ip ) ), ip4_addr4( &( pxPCB->remote_ip ) ) ); #endif pxPCBClient = NULL; } if( pxPCB == pxPCBListen ) { pxPCBListen = NULL; } } }
void create_raw_socket_client_demo(void) { int idx; struct tls_ethif * ethif; ethif = tls_netif_get_ethif(); printf("\nip=%d.%d.%d.%d\n",ip4_addr1(ðif->ip_addr.addr),ip4_addr2(ðif->ip_addr.addr), ip4_addr3(ðif->ip_addr.addr),ip4_addr4(ðif->ip_addr.addr)); DemoRawSockOneshotSendMac(); memset(&raw_socket_c_desc, 0, sizeof(struct tls_socket_desc)); raw_socket_c_desc.recvf = raw_sk_client_recv; raw_socket_c_desc.errf = raw_sk_client_err; raw_socket_c_desc.pollf = raw_sk_client_poll; raw_socket_c_desc.cs_mode = SOCKET_CS_MODE_CLIENT; raw_socket_c_desc.connf = raw_sk_client_connected; raw_socket_c_desc.protocol = SOCKET_PROTO_TCP; for(idx = 0; idx < 4; idx++){ raw_socket_c_desc.ip_addr[idx] = RemoteIp[idx]; } raw_socket_c_desc.port = RemotePort; printf("\nserver ip=%d.%d.%d.%d,port=%d\n",RemoteIp[0],RemoteIp[1],RemoteIp[2],RemoteIp[3],raw_socket_c_desc.port); if(gDemoSys.socket_ok != true) { tls_socket_create(&raw_socket_c_desc); } }
static void low_level_init (struct netif *netif) { struct genericif *genericif; char buf[100]; genericif = netif->state; /* Do whatever else is needed to initialize interface. */ netif->fd = genericif->fd = open (genericif->device_name, 0, 0); if (genericif->fd < 0) die ("can't open %s", genericif->device_name); ioctl (genericif->fd, ETHGETHWADDR, genericif->ethaddr->addr); printf ("HW Addr: %02x:%02x:%02x:%02x:%02x:%02x\n", genericif->ethaddr->addr[0], genericif->ethaddr->addr[1], genericif->ethaddr->addr[2], genericif->ethaddr->addr[3], genericif->ethaddr->addr[4], genericif->ethaddr->addr[5]); snprintf (buf, sizeof (buf), "ifconfig tap0 inet %d.%d.%d.%d", ip4_addr1 (&(netif->gw)), ip4_addr2 (&(netif->gw)), ip4_addr3 (&(netif->gw)), ip4_addr4 (&(netif->gw))); DEBUGF (TAPIF_DEBUG, ("paulosif_init: system(\"%s\");\n", buf)); callmelater_register ((void (*)(void *)) paulosif_input, (void *) netif, 1); }
void idc_get_ip(void) { if (is_owner) { assert(!"owner of lwip should never ask for ip through API\n"); abort(); } LWIPBF_DEBUG("On the way of getting IP\n"); errval_t err; struct ip_addr ip, gw, nm; err = net_ports_rpc.vtbl.get_ip_info(&net_ports_rpc, &ip.addr, &gw.addr, &nm.addr); if (err_is_fail(err)) { USER_PANIC_ERR(err, "error sending get_ip_info"); } LWIPBF_DEBUG("got answer, now setting up things\n"); netif_add(&netif, &ip, &nm, &gw, NULL, bfeth_init, ethernet_input); netif_set_default(&netif); netif_set_up(&netif); LWIPBF_DEBUG("client: owner has the IP address %d.%d.%d.%d\n", ip4_addr1(&netif.ip_addr), ip4_addr2(&netif.ip_addr), ip4_addr3(&netif.ip_addr), ip4_addr4(&netif.ip_addr)); }
static void netif_status_callback(struct netif *netif) { ip_addr_t addr; if(netif_is_up(netif) && (netif->dhcp)) { addr = netif->ip_addr; printf("DHCP IP:%d.%d.%d.%d\r\n", ip4_addr1(&addr), ip4_addr2(&addr),ip4_addr3(&addr),ip4_addr4(&addr)); addr = netif->gw; printf("DHCP GW:%d.%d.%d.%d\r\n", ip4_addr1(&addr), ip4_addr2(&addr),ip4_addr3(&addr),ip4_addr4(&addr)); addr = netif->netmask; printf("DHCP MASK:%d.%d.%d.%d\r\n", ip4_addr1(&addr), ip4_addr2(&addr),ip4_addr3(&addr),ip4_addr4(&addr)); } }
void print_ip(char *msg, struct ip_addr *ip) { print(msg); xil_printf("%d.%d.%d.%d\r\n", ip4_addr1(ip), ip4_addr2(ip), ip4_addr3(ip), ip4_addr4(ip)); }
/********************************************************************************************************* ** 函数名称: __netIfShowAll ** 功能描述: 显示所有网络接口信息 (ip v4) ** 输 入 : NONE ** 输 出 : NONE ** 全局变量: ** 调用模块: *********************************************************************************************************/ static VOID __netIfShowAll (VOID) { struct netif *netif = netif_list; INT iCounter = 0; INT i; CHAR cName[5] = "null"; /* 当前默认路由网络接口名 */ for (; netif != LW_NULL; netif = netif->next) { __netIfShow(LW_NULL, netif); iCounter++; } #if LWIP_DNS > 0 for (i = 0; i < DNS_MAX_SERVERS; i++) { ip_addr_t ipaddr = dns_getserver((u8_t)i); printf("dns%d: %d.%d.%d.%d\n", (i), ip4_addr1(&ipaddr), ip4_addr2(&ipaddr), ip4_addr3(&ipaddr), ip4_addr4(&ipaddr)); } #endif /* LWIP_DNS */ if (netif_default) { cName[0] = netif_default->name[0]; cName[1] = netif_default->name[1]; cName[2] = (CHAR)(netif_default->num + '0'); cName[3] = PX_EOS; } printf("default device is: %s\n", cName); /* 显示路由端口 */ printf("total net interface: %d\n", iCounter); }
/** * Sends an generic or enterprise specific trap message. * * @param generic_trap is the trap code * @param eoid points to enterprise object identifier * @param specific_trap used for enterprise traps when generic_trap == 6 * @return ERR_OK when success, ERR_MEM if we're out of memory * * @note the caller is responsible for filling in outvb in the trap_msg * @note the use of the enterpise identifier field * is per RFC1215. * Use .iso.org.dod.internet.mgmt.mib-2.snmp for generic traps * and .iso.org.dod.internet.private.enterprises.yourenterprise * (sysObjectID) for specific traps. */ err_t snmp_send_trap(s8_t generic_trap, struct snmp_obj_id *eoid, s32_t specific_trap) { struct snmp_trap_dst *td; struct netif *dst_if; ip_addr_t dst_ip; struct pbuf *p; u16_t i,tot_len; for (i=0, td = &trap_dst[0]; i<SNMP_TRAP_DESTINATIONS; i++, td++) { if ((td->enable != 0) && !ip_addr_isany(&td->dip)) { /* network order trap destination */ ip_addr_copy(trap_msg.dip, td->dip); /* lookup current source address for this dst */ dst_if = ip_route(&td->dip); ip_addr_copy(dst_ip, dst_if->ip_addr); /* @todo: what about IPv6? */ trap_msg.sip_raw[0] = ip4_addr1(&dst_ip); trap_msg.sip_raw[1] = ip4_addr2(&dst_ip); trap_msg.sip_raw[2] = ip4_addr3(&dst_ip); trap_msg.sip_raw[3] = ip4_addr4(&dst_ip); trap_msg.gen_trap = generic_trap; trap_msg.spc_trap = specific_trap; if (generic_trap == SNMP_GENTRAP_ENTERPRISESPC) { /* enterprise-Specific trap */ trap_msg.enterprise = eoid; } else { /* generic (MIB-II) trap */ snmp_get_snmpgrpid_ptr(&trap_msg.enterprise); } snmp_get_sysuptime(&trap_msg.ts); /* pass 0, calculate length fields */ tot_len = snmp_varbind_list_sum(&trap_msg.outvb); tot_len = snmp_trap_header_sum(&trap_msg, tot_len); /* allocate pbuf(s) */ p = pbuf_alloc(PBUF_TRANSPORT, tot_len, PBUF_POOL); if (p != NULL) { u16_t ofs; /* pass 1, encode packet ino the pbuf(s) */ ofs = snmp_trap_header_enc(&trap_msg, p); snmp_varbind_list_enc(&trap_msg.outvb, p, ofs); snmp_inc_snmpouttraps(); snmp_inc_snmpoutpkts(); /** send to the TRAP destination */ udp_sendto(trap_msg.pcb, p, &trap_msg.dip, SNMP_TRAP_PORT); pbuf_free(p); } else { return ERR_MEM; } } } return ERR_OK; }
void netif_set_ipaddr(struct netif *netif, struct ip_addr *ipaddr) { /* TODO: Handling of obsolete pcbs */ /* See: http://mail.gnu.org/archive/html/lwip-users/2003-03/msg00118.html */ #if LWIP_TCP struct tcp_pcb *pcb; struct tcp_pcb_listen *lpcb; /* address is actually being changed? */ if ((ip_addr_cmp(ipaddr, &(netif->ip_addr))) == 0) { /* extern struct tcp_pcb *tcp_active_pcbs; defined by tcp.h */ LWIP_DEBUGF(NETIF_DEBUG | 1, ("netif_set_ipaddr: netif address being changed\n")); pcb = tcp_active_pcbs; while (pcb != NULL) { /* PCB bound to current local interface address? */ if (ip_addr_cmp(&(pcb->local_ip), &(netif->ip_addr))) { /* this connection must be aborted */ struct tcp_pcb *next = pcb->next; LWIP_DEBUGF(NETIF_DEBUG | 1, ("netif_set_ipaddr: aborting TCP pcb %p\n", (void *)pcb)); tcp_abort(pcb); pcb = next; } else { pcb = pcb->next; } } for (lpcb = tcp_listen_pcbs.listen_pcbs; lpcb != NULL; lpcb = lpcb->next) { /* PCB bound to current local interface address? */ if (ip_addr_cmp(&(lpcb->local_ip), &(netif->ip_addr))) { /* The PCB is listening to the old ipaddr and * is set to listen to the new one instead */ ip_addr_set(&(lpcb->local_ip), ipaddr); } } } #endif snmp_delete_ipaddridx_tree(netif); snmp_delete_iprteidx_tree(0,netif); /* set new IP address to netif */ ip_addr_set(&(netif->ip_addr), ipaddr); snmp_insert_ipaddridx_tree(netif); snmp_insert_iprteidx_tree(0,netif); #if 0 /* only allowed for Ethernet interfaces TODO: how can we check? */ /** For Ethernet network interfaces, we would like to send a * "gratuitous ARP"; this is an ARP packet sent by a node in order * to spontaneously cause other nodes to update an entry in their * ARP cache. From RFC 3220 "IP Mobility Support for IPv4" section 4.6. */ etharp_query(netif, ipaddr, NULL); #endif LWIP_DEBUGF(NETIF_DEBUG | DBG_TRACE | DBG_STATE | 3, ("netif: IP address of interface %c%c set to %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n", netif->name[0], netif->name[1], ip4_addr1(&netif->ip_addr), ip4_addr2(&netif->ip_addr), ip4_addr3(&netif->ip_addr), ip4_addr4(&netif->ip_addr))); }
int netstack_get_ipmask(u8 *addr) { addr[0] = ip4_addr1(&lns.nif.netmask); addr[1] = ip4_addr2(&lns.nif.netmask); addr[2] = ip4_addr3(&lns.nif.netmask); addr[3] = ip4_addr4(&lns.nif.netmask); return VMM_OK; }
int netstack_get_ipaddr(u8 *addr) { addr[0] = ip4_addr1(&lns.nif.ip_addr); addr[1] = ip4_addr2(&lns.nif.ip_addr); addr[2] = ip4_addr3(&lns.nif.ip_addr); addr[3] = ip4_addr4(&lns.nif.ip_addr); return VMM_OK; }
/** * Conversion from lwIP ip_addr to oid * @param ip points to input struct * @param ident points to s32_t ident[4] output */ void snmp_iptooid(ip_addr_t *ip, s32_t *ident) { ident[0] = ip4_addr1(ip); ident[1] = ip4_addr2(ip); ident[2] = ip4_addr3(ip); ident[3] = ip4_addr4(ip); }
/** * @brief Initializes the lwIP stack * @param None * @retval None */ void Netif_Config(void) { ip_addr_t ipaddr; ip_addr_t netmask; ip_addr_t gw; #if LWIP_DHCP ipaddr.addr = 0; netmask.addr = 0; gw.addr = 0; #else IP4_ADDR(&ipaddr, IP_ADDR0, IP_ADDR1, IP_ADDR2, IP_ADDR3); IP4_ADDR(&netmask, NETMASK_ADDR0, NETMASK_ADDR1 , NETMASK_ADDR2, NETMASK_ADDR3); IP4_ADDR(&gw, GW_ADDR0, GW_ADDR1, GW_ADDR2, GW_ADDR3); printf("STATIC IP:%d.%d.%d.%d\r\n",ip4_addr1(&ipaddr), ip4_addr2(&ipaddr),ip4_addr3(&ipaddr),ip4_addr4(&ipaddr)); printf("STATIC GW:%d.%d.%d.%d\r\n",ip4_addr1(&gw), ip4_addr2(&gw),ip4_addr3(&gw),ip4_addr4(&gw)); printf("STATIC MASK:%d.%d.%d.%d\r\n",ip4_addr1(&netmask), ip4_addr2(&netmask),ip4_addr3(&netmask),ip4_addr4(&netmask)); #endif /* - netif_add(struct netif *netif, struct ip_addr *ipaddr, struct ip_addr *netmask, struct ip_addr *gw, void *state, err_t (* init)(struct netif *netif), err_t (* input)(struct pbuf *p, struct netif *netif)) Adds your network interface to the netif_list. Allocate a struct netif and pass a pointer to this structure as the first argument. Give pointers to cleared ip_addr structures when using DHCP, or fill them with sane numbers otherwise. The state pointer may be NULL. The init function pointer must point to a initialization function for your ethernet netif interface. The following code illustrates it's use.*/ netif_add(&wireless_netif, &ipaddr, &netmask, &gw, NULL, &wlan_ethernetif_init, &tcpip_input); /* Registers the default network interface.*/ netifapi_netif_common(&wireless_netif, netif_set_default, NULL); #if LWIP_DHCP netif_set_status_callback(&wireless_netif, netif_status_callback); #else netifapi_netif_common(&wireless_netif, netif_set_up, NULL); #endif }
/** * Convert ip4_addr to InetAddressIPv4 (no InetAddressType) * @param ip points to input struct * @param oid points to u32_t ident[4] output */ void snmp_ip4_to_oid(const ip4_addr_t *ip, u32_t *oid) { oid[0] = ip4_addr1(ip); oid[1] = ip4_addr2(ip); oid[2] = ip4_addr3(ip); oid[3] = ip4_addr4(ip); }
/* Copy IP address as dotted decimal to 'dest', must be at least 16 bytes long */ inline static void sprintf_ipaddr(const ip_addr_t *addr, char *dest) { if(addr == NULL) sprintf(dest, "NULL"); else sprintf(dest, "%d.%d.%d.%d", ip4_addr1(addr), ip4_addr2(addr), ip4_addr3(addr), ip4_addr4(addr)); }
int netstack_get_gatewayip(u8 *addr) { addr[0] = ip4_addr1(&lns.nif.gw); addr[1] = ip4_addr2(&lns.nif.gw); addr[2] = ip4_addr3(&lns.nif.gw); addr[3] = ip4_addr4(&lns.nif.gw); return VMM_OK; }
/** * Update (or insert) a IP/MAC address pair in the ARP cache. * * If a pending entry is resolved, any queued packets will be sent * at this point. * * @param ipaddr IP address of the inserted ARP entry. * @param ethaddr Ethernet address of the inserted ARP entry. * @param flags Defines behaviour: * - ETHARP_TRY_HARD Allows ARP to insert this as a new item. If not specified, * only existing ARP entries will be updated. * * @return * - ERR_OK Succesfully updated ARP cache. * - ERR_MEM If we could not add a new ARP entry when ETHARP_TRY_HARD was set. * - ERR_ARG Non-unicast address given, those will not appear in ARP cache. * * @see pbuf_free() */ static err_t update_arp_entry(struct netif *netif, struct ip_addr *ipaddr, struct eth_addr *ethaddr, u8_t flags) { s8_t i, k; LWIP_DEBUGF(ETHARP_DEBUG | DBG_TRACE | 3, ("update_arp_entry()\n")); LWIP_ASSERT("netif->hwaddr_len != 0", netif->hwaddr_len != 0); LWIP_DEBUGF(ETHARP_DEBUG | DBG_TRACE, ("update_arp_entry: %"U16_F".%"U16_F".%"U16_F".%"U16_F" - %02"X16_F":%02"X16_F":%02"X16_F":%02"X16_F":%02"X16_F":%02"X16_F"\n", ip4_addr1(ipaddr), ip4_addr2(ipaddr), ip4_addr3(ipaddr), ip4_addr4(ipaddr), ethaddr->addr[0], ethaddr->addr[1], ethaddr->addr[2], ethaddr->addr[3], ethaddr->addr[4], ethaddr->addr[5])); /* non-unicast address? */ if (ip_addr_isany(ipaddr) || ip_addr_isbroadcast(ipaddr, netif) || ip_addr_ismulticast(ipaddr)) { LWIP_DEBUGF(ETHARP_DEBUG | DBG_TRACE, ("update_arp_entry: will not add non-unicast IP address to ARP cache\n")); return ERR_ARG; } /* find or create ARP entry */ i = find_entry(ipaddr, flags); /* bail out if no entry could be found */ if (i < 0) return (err_t)i; /* mark it stable */ arp_table[i].state = ETHARP_STATE_STABLE; LWIP_DEBUGF(ETHARP_DEBUG | DBG_TRACE, ("update_arp_entry: updating stable entry %"S16_F"\n", (s16_t)i)); /* update address */ for (k = 0; k < netif->hwaddr_len; ++k) { arp_table[i].ethaddr.addr[k] = ethaddr->addr[k]; } /* reset time stamp */ arp_table[i].ctime = 0; /* this is where we will send out queued packets! */ #if ARP_QUEUEING while (arp_table[i].p != NULL) { /* get the first packet on the queue */ struct pbuf *p = arp_table[i].p; /* Ethernet header */ struct eth_hdr *ethhdr = p->payload; /* remember (and reference) remainder of queue */ /* note: this will also terminate the p pbuf chain */ arp_table[i].p = pbuf_dequeue(p); /* fill-in Ethernet header */ for (k = 0; k < netif->hwaddr_len; ++k) { ethhdr->dest.addr[k] = ethaddr->addr[k]; ethhdr->src.addr[k] = netif->hwaddr[k]; } ethhdr->type = htons(ETHTYPE_IP); LWIP_DEBUGF(ETHARP_DEBUG | DBG_TRACE, ("update_arp_entry: sending queued IP packet %p.\n", (void *)p)); /* send the queued IP packet */ netif->linkoutput(netif, p); /* free the queued IP packet */ pbuf_free(p); } #endif return ERR_OK; }
void netif_set_netmask(struct netif *netif, struct ip_addr *netmask) { ip_addr_set(&(netif->netmask), netmask); LWIP_DEBUGF(NETIF_DEBUG | DBG_TRACE | DBG_STATE | 3, ("netif: netmask of interface %c%c set to %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n", netif->name[0], netif->name[1], ip4_addr1(&netif->netmask), ip4_addr2(&netif->netmask), ip4_addr3(&netif->netmask), ip4_addr4(&netif->netmask))); }
void netif_set_gw(struct netif *netif, struct ip_addr *gw) { ip_addr_set(&(netif->gw), gw); LWIP_DEBUGF(NETIF_DEBUG | DBG_TRACE | DBG_STATE | 3, ("netif: GW address of interface %c%c set to %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n", netif->name[0], netif->name[1], ip4_addr1(&netif->gw), ip4_addr2(&netif->gw), ip4_addr3(&netif->gw), ip4_addr4(&netif->gw))); }
/*-----------------------------------------------------------------------------------*/ static void low_level_init(struct netif *netif) { struct tapif *tapif; char buf[sizeof(IFCONFIG_ARGS) + sizeof(IFCONFIG_BIN) + 50]; tapif = (struct tapif *)netif->state; /* Obtain MAC address from network interface. */ /* (We just fake an address...) */ tapif->ethaddr->addr[0] = 0x1; tapif->ethaddr->addr[1] = 0x2; tapif->ethaddr->addr[2] = 0x3; tapif->ethaddr->addr[3] = 0x4; tapif->ethaddr->addr[4] = 0x5; tapif->ethaddr->addr[5] = 0x6; /* Do whatever else is needed to initialize interface. */ tapif->fd = open(DEVTAP, O_RDWR); LWIP_DEBUGF(TAPIF_DEBUG, ("tapif_init: fd %d\n", tapif->fd)); if(tapif->fd == -1) { #ifdef linux perror("tapif_init: try running \"modprobe tun\" or rebuilding your kernel with CONFIG_TUN; cannot open "DEVTAP); #else perror("tapif_init: cannot open "DEVTAP); #endif exit(1); } #ifdef linux { struct ifreq ifr; memset(&ifr, 0, sizeof(ifr)); ifr.ifr_flags = IFF_TAP|IFF_NO_PI; if (ioctl(tapif->fd, TUNSETIFF, (void *) &ifr) < 0) { perror("tapif_init: "DEVTAP" ioctl TUNSETIFF"); exit(1); } } #endif /* Linux */ sprintf(buf, IFCONFIG_BIN IFCONFIG_ARGS, ip4_addr1(&(netif->gw)), ip4_addr2(&(netif->gw)), ip4_addr3(&(netif->gw)), ip4_addr4(&(netif->gw))); LWIP_DEBUGF(TAPIF_DEBUG, ("tapif_init: system(\"%s\");\n", buf)); system(buf); sys_thread_new("tapif_thread", tapif_thread, netif, DEFAULT_THREAD_STACKSIZE, DEFAULT_THREAD_PRIO); }
void ip_debug_print(struct pbuf *p) { struct ip_hdr *iphdr = p->payload; u8_t *payload; payload = (u8_t *)iphdr + IP_HLEN; LWIP_DEBUGF(IP_DEBUG, ("IP header:\n")); LWIP_DEBUGF(IP_DEBUG, ("+-------------------------------+\n")); LWIP_DEBUGF(IP_DEBUG, ("|%2"S16_F" |%2"S16_F" | 0x%02"X16_F" | %5"U16_F" | (v, hl, tos, len)\n", IPH_V(iphdr), IPH_HL(iphdr), IPH_TOS(iphdr), ntohs(IPH_LEN(iphdr)))); LWIP_DEBUGF(IP_DEBUG, ("+-------------------------------+\n")); LWIP_DEBUGF(IP_DEBUG, ("| %5"U16_F" |%"U16_F"%"U16_F"%"U16_F"| %4"U16_F" | (id, flags, offset)\n", ntohs(IPH_ID(iphdr)), ntohs(IPH_OFFSET(iphdr)) >> 15 & 1, ntohs(IPH_OFFSET(iphdr)) >> 14 & 1, ntohs(IPH_OFFSET(iphdr)) >> 13 & 1, ntohs(IPH_OFFSET(iphdr)) & IP_OFFMASK)); LWIP_DEBUGF(IP_DEBUG, ("+-------------------------------+\n")); LWIP_DEBUGF(IP_DEBUG, ("| %3"U16_F" | %3"U16_F" | 0x%04"X16_F" | (ttl, proto, chksum)\n", IPH_TTL(iphdr), IPH_PROTO(iphdr), ntohs(IPH_CHKSUM(iphdr)))); LWIP_DEBUGF(IP_DEBUG, ("+-------------------------------+\n")); LWIP_DEBUGF(IP_DEBUG, ("| %3"U16_F" | %3"U16_F" | %3"U16_F" | %3"U16_F" | (src)\n", ip4_addr1(&iphdr->src), ip4_addr2(&iphdr->src), ip4_addr3(&iphdr->src), ip4_addr4(&iphdr->src))); LWIP_DEBUGF(IP_DEBUG, ("+-------------------------------+\n")); LWIP_DEBUGF(IP_DEBUG, ("| %3"U16_F" | %3"U16_F" | %3"U16_F" | %3"U16_F" | (dest)\n", ip4_addr1(&iphdr->dest), ip4_addr2(&iphdr->dest), ip4_addr3(&iphdr->dest), ip4_addr4(&iphdr->dest))); LWIP_DEBUGF(IP_DEBUG, ("+-------------------------------+\n")); }