예제 #1
0
파일: dhcp.c 프로젝트: dafyddcrosby/L4OS
/**
 * Bind the interface to the offered IP address.
 *
 */
static void dhcp_bind(struct dhcp_state *state)
{
  struct ip_addr sn_mask, gw_addr;
  dhcp_set_state(state, DHCP_BOUND);

  if (state->offered_t1_renew != 0xffffffffUL)
  {
    DEBUGF(DHCP_DEBUG, ("dhcp_bind(): t1 renewal timer %u secs\n", state->offered_t1_renew));
    state->t1_timeout = (state->offered_t1_renew + DHCP_COARSE_TIMER_SECS / 2) / DHCP_COARSE_TIMER_SECS;
    if (state->t1_timeout == 0) state->t1_timeout = 1;
    DEBUGF(DHCP_DEBUG, ("dhcp_bind(): request timeout %u msecs\n", state->offered_t1_renew*1000));
  }
  if (state->offered_t2_rebind != 0xffffffffUL)
  {
    DEBUGF(DHCP_DEBUG, ("dhcp_bind(): t2 rebind timer %u secs\n", state->offered_t2_rebind));
    state->t2_timeout = (state->offered_t2_rebind + DHCP_COARSE_TIMER_SECS / 2) / DHCP_COARSE_TIMER_SECS;
    if (state->t2_timeout == 0) state->t2_timeout = 1;
    DEBUGF(DHCP_DEBUG, ("dhcp_bind(): request timeout %u msecs\n", state->offered_t2_rebind*1000));
  }

  ip_addr_set(&sn_mask, &state->offered_sn_mask);
  // subnet mask not given
  if (sn_mask.addr == 0)
  {
    // choose a safe subnet mask given the network class
    u8_t first_octet = ip4_addr1(&sn_mask);
    if (first_octet <= 127) sn_mask.addr = htonl(0xff000000);
    else if (first_octet >= 192) sn_mask.addr = htonl(0xffffff00);
    else sn_mask.addr = htonl(0xffff0000);
  }
  DEBUGF(DHCP_DEBUG, ("dhcp_bind(): SN: 0x%08x\n", sn_mask.addr));
  netif_set_netmask(state->netif, &sn_mask);

  ip_addr_set(&gw_addr, &state->offered_gw_addr);
  // gateway address not given
  if (gw_addr.addr == 0)
  {
    gw_addr.addr &= sn_mask.addr;
    gw_addr.addr |= 0x01000000;
  }
  DEBUGF(DHCP_DEBUG, ("dhcp_bind(): GW: 0x%08x\n", gw_addr.addr));
  netif_set_gw(state->netif, &gw_addr);

  DEBUGF(DHCP_DEBUG, ("dhcp_bind(): IP: 0x%08x\n", state->offered_ip_addr.addr));
  netif_set_ipaddr(state->netif, &state->offered_ip_addr);

  l4e_printf("dhcp: %hd.%hd.%hd.%hd/%hd.%hd.%hd.%hd, gw %hd.%hd.%hd.%hd\n",
      ip_split(&state->offered_ip_addr), ip_split(&sn_mask),
      ip_split(&gw_addr));
}
예제 #2
0
int main(int argc, char *argv[]){
	char str[]="192.168.10.1 ,193.23.34.45,12.23.34.4";
	const char *split = ",";
    ARRAY p;
	p = ip_split(str, split);
	int i = 0; 
	while(p[i][0] != '\0'){
		printf("%saa",p[i]);
		i++;
	}
	return 0;
}