Example #1
0
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;
}
Example #2
0
void
netif_create_ip4_linklocal_address(struct netif * netif)
{
#if 1
	ip_addr_t linklocal;
	ip_addr_t linklocal_mask;
	ip4_addr_t addr = {0};
	/* Link-local prefix and mask. */
	IP4_ADDR(ip_2_ip4(&linklocal), 169, 254, 0, 0);
	IP4_ADDR(ip_2_ip4(&linklocal_mask), 255, 255, 0, 0);

	if (!ip4_addr_netcmp( ip_2_ip4(&linklocal), ip_2_ip4(&netif->link_local_addr), ip_2_ip4(&linklocal_mask) ) &&
		!ip4_addr_isany(ip_2_ip4(&netif->ip_addr)) ) {
		IP4_ADDR( ip_2_ip4(&netif->link_local_addr), 169, 254, ip4_addr3( ip_2_ip4(&netif->ip_addr) )
                                    , ip4_addr4( ip_2_ip4(&netif->ip_addr) )  );
		return;
	}

	while ( !(addr.addr) || !ip4_addr4(&addr) )
		//os_get_random((unsigned char *)&addr, sizeof(addr));
            addr.addr = LWIP_RAND();


	if ( ip_2_ip4(&netif->netmask)->addr > IP_CLASSB_NET &&
		!ip4_addr_isany( ip_2_ip4(&netif->ip_addr) )) {  // random host address
		IP4_ADDR( ip_2_ip4(&netif->link_local_addr), 169, 254, ip4_addr3( ip_2_ip4(&netif->ip_addr))
                                , ip4_addr4(&addr));
	} else {
		IP4_ADDR( ip_2_ip4(&netif->link_local_addr), 169, 254, ip4_addr3(&addr), ip4_addr4(&addr) );
	}
#endif
}
Example #3
0
/*-----------------------------------------------------------------------------------*/
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);

}
Example #4
0
/*-----------------------------------------------------------------------------------*/
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);

}
Example #5
0
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)
    );
}
Example #6
0
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
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));
}
Example #8
0
/*
 * 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;
}
Example #9
0
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 create_raw_socket_server_demo(void)
{	
	struct tls_ethif * ethif;

	ethif = tls_netif_get_ethif();
	printf("\nip=%d.%d.%d.%d\n",ip4_addr1(&ethif->ip_addr.addr),ip4_addr2(&ethif->ip_addr.addr),
		ip4_addr3(&ethif->ip_addr.addr),ip4_addr4(&ethif->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);
	}
}
/******************************************************************************
* 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 */
Example #12
0
// Lua: ip = wifi.ap.dhcp.config()
static int wifi_ap_dhcp_config( lua_State* L )
{
  if (!lua_istable(L, 1))
    return luaL_error( L, "wrong arg type" );

  struct dhcps_lease lease;
  uint32_t ip;

  ip = parse_key(L, "start");
  if (ip == 0)
    return luaL_error( L, "wrong arg type" );

  lease.start_ip = ip;
  NODE_DBG(IPSTR, IP2STR(&lease.start_ip));
  NODE_DBG("\n");

  // use configured max_connection to determine end
  struct softap_config config;
  wifi_softap_get_config(&config);
  lease.end_ip = lease.start_ip;
  ip4_addr4(&lease.end_ip) += config.max_connection - 1;

  char temp[64];
  c_sprintf(temp, IPSTR, IP2STR(&lease.start_ip));
  lua_pushstring(L, temp);
  c_sprintf(temp, IPSTR, IP2STR(&lease.end_ip));
  lua_pushstring(L, temp);

  // note: DHCP max range = 101 from start_ip to end_ip
  wifi_softap_dhcps_stop();
  wifi_softap_set_dhcps_lease(&lease);
  wifi_softap_dhcps_start();

  return 2;
}
Example #13
0
static void handle_dhcp_discover(struct dhcp_msg *dhcpmsg)
{
    if(dhcpmsg->htype != DHCP_HTYPE_ETH)
        return;
    if(dhcpmsg->hlen > NETIF_MAX_HWADDR_LEN)
        return;

    dhcp_lease_t *freelease = find_lease_slot(dhcpmsg->chaddr);
    if(!freelease) {
        printf("DHCP Server: All leases taken.\r\n");
        return; /* Nothing available, so do nothing */
    }

    /* Reuse the DISCOVER buffer for the OFFER response */
    dhcpmsg->op = DHCP_BOOTREPLY;
    bzero(dhcpmsg->options, DHCP_OPTIONS_LEN);

    ip_addr_copy(dhcpmsg->yiaddr, state->first_client_addr);
    ip4_addr4(&(dhcpmsg->yiaddr)) += (freelease - state->leases);

    uint8_t *opt = (uint8_t *)&dhcpmsg->options;
    opt = add_dhcp_option_byte(opt, DHCP_OPTION_MESSAGE_TYPE, DHCP_OFFER);
    opt = add_dhcp_option_bytes(opt, DHCP_OPTION_SERVER_ID, &state->server_if->ip_addr, 4);
    opt = add_dhcp_option_bytes(opt, DHCP_OPTION_SUBNET_MASK, &state->server_if->netmask, 4);
    opt = add_dhcp_option_bytes(opt, DHCP_OPTION_END, NULL, 0);

    struct netbuf *netbuf = netbuf_new();
    netbuf_alloc(netbuf, sizeof(struct dhcp_msg));
    netbuf_take(netbuf, dhcpmsg, sizeof(struct dhcp_msg));
    netconn_sendto(state->nc, netbuf, IP_ADDR_BROADCAST, 68);
    netbuf_delete(netbuf);
}
Example #14
0
/*********************************************************************************************************
** 函数名称: __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);
}
Example #15
0
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));
}
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(&ethif->ip_addr.addr),ip4_addr2(&ethif->ip_addr.addr),
		ip4_addr3(&ethif->ip_addr.addr),ip4_addr4(&ethif->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);
	}
}
Example #17
0
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;
        }
    }
}
Example #18
0
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(&ethif->ip_addr.addr),ip4_addr2(&ethif->ip_addr.addr),
		ip4_addr3(&ethif->ip_addr.addr),ip4_addr4(&ethif->ip_addr.addr));
#endif			
            break;
        default:
            break;
    }
}
Example #19
0
/**
 * 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;
}
Example #20
0
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)));
}
Example #21
0
/**
 * 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);
}
Example #22
0
/* 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));
}
Example #23
0
/**
 * 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);
}
Example #24
0
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;
}
Example #25
0
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;
}
Example #26
0
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;
}
Example #27
0
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)));
}
Example #28
0
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)));
}
Example #29
0
/*-----------------------------------------------------------------------------------*/
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"));
}