예제 #1
0
/*---------------------------------------------------------------------------*/
void
ip64_dhcpc_appcall(process_event_t ev, void *data)
{
  if(ev == tcpip_event || ev == PROCESS_EVENT_TIMER) {
    handle_dhcp(ev, data);
  }
}
예제 #2
0
파일: dhcpc.c 프로젝트: Faeriol/SEG4545
/*
#define	DHCP_DISCOVER			1
#define DHCP_OFFER				2
#define	DHCP_REQUEST			3
#define	DHCP_DECLINE			4
#define	DHCP_ACK				5
#define DHCP_NAK				6
#define	DHCP_RELEASE			7
#define DHCP_INFORM				8
*/
void
dhcpc_appcall(void)
{
	int8_t message;

//	PRINTF("dhcpc_appcall() %d\r\n", dhcpc_state.state); // just for debugging

	if ( uip_newdata() && (message = msg_for_me()) > 0 )
	{
		handle_dhcp( (uint8_t) message );
	}

	if(dhcpc_state.state == DHCP_STATE_INITIAL || dhcpc_state.state == DHCP_STATE_LEASED)
	{
		handle_dhcp(0); // no message if DHCP_STATE_INITIAL or DHCP_STATE_LEASED, but we need to handle timer and initialisation.
	}
}
예제 #3
0
파일: dhcpc.c 프로젝트: EmuxEvans/6lp-gw
/*---------------------------------------------------------------------------*/
void
dhcpc_request(void)
{
  if(s.state == STATE_INITIAL) {
    uipv4_sethostaddr(&uipv4_all_zeroes_addr);
    handle_dhcp(PROCESS_EVENT_NONE, NULL);
  }
}
예제 #4
0
파일: dhcpc.c 프로젝트: hokim72/AVR-Common
/*---------------------------------------------------------------------------*/
void
dhcpc_appcall(void)
{
  // only when we ask for a new ip if we have a udp conn setup
  // since the dhcpc_appcall will be called as part of the normal uip app loop
  if ((s.conn != NULL) && (s.state != STATE_CONFIG_RECEIVED))
  {
//sendString("\r\ndhcpc appcall w/o config received");
    (void) handle_dhcp();
  }
}
예제 #5
0
/*---------------------------------------------------------------------------*/
void
ip64_dhcpc_request(void)
{
  uip_ipaddr_t ipaddr;
  
  if(s.state == STATE_INITIAL) {
    uip_ipaddr(&ipaddr, 0,0,0,0);
    uip_sethostaddr(&ipaddr);
    handle_dhcp(PROCESS_EVENT_NONE, NULL);
  }
}
예제 #6
0
파일: dhcpc.c 프로젝트: Faeriol/SEG4545
void
dhcpc_request(void)
{
  uip_ipaddr_t ipaddr;

  if(dhcpc_state.state == DHCP_STATE_INITIAL) {
    uip_ipaddr(&ipaddr, 0,0,0,0);
    uip_sethostaddr(&ipaddr);
    handle_dhcp(0);
  }
}
예제 #7
0
파일: udp.c 프로젝트: agraf/SLOF
/**
 * NET: Handles UDP-packets according to Receive-handle diagram.
 *
 * @param  udp_packet UDP-packet to be handled
 * @param  packetsize Length of the packet
 * @return            ZERO - packet handled successfully;
 *                    NON ZERO - packet was not handled (e.g. bad format)
 * @see               receive_ether
 * @see               udphdr
 */
int8_t
handle_udp(uint8_t * udp_packet, int32_t packetsize) {
	struct udphdr * udph = (struct udphdr *) udp_packet;

	if (packetsize < sizeof(struct udphdr))
		return -1; // packet is too small

	switch (htons(udph -> uh_dport)) {
	case UDPPORT_BOOTPC:
		if (udph -> uh_sport == htons(UDPPORT_BOOTPS))
			return handle_dhcp(udp_packet + sizeof(struct udphdr),
			                    packetsize - sizeof(struct udphdr));
		else
			return -1;
	case UDPPORT_DNSC:
		if (udph -> uh_sport == htons(UDPPORT_DNSS))
			return handle_dns(udp_packet + sizeof(struct udphdr),
			                  packetsize - sizeof(struct udphdr));
		else
			return -1;
        case UDPPORT_DHCPV6C:
                return handle_dhcpv6(udp_packet+sizeof(struct udphdr),
                                     packetsize - sizeof(struct udphdr));
	case UDPPORT_TFTPC:
#ifdef USE_MTFTP
	return handle_tftp(udp_packet + sizeof(struct udphdr),
			               packetsize - sizeof(struct udphdr));
#else
	return handle_tftp(udp_packet, packetsize);
#endif
	default:
#ifdef USE_MTFTP
		if (htons(udph -> uh_dport) == net_tftp_uport)
		return handle_tftp(udp_packet + sizeof(struct udphdr),
                       packetsize - sizeof(struct udphdr));
		else if (htons(udph -> uh_dport) == net_mtftp_uport)
		return handle_tftp(udp_packet + sizeof(struct udphdr),
                       packetsize - sizeof(struct udphdr));
#endif
		return -1;
	}
}
예제 #8
0
파일: ethernet.c 프로젝트: Talustus/culfw
void
udp_appcall()
{
  if(dhcp_state != PT_ENDED) {
    dhcp_state = handle_dhcp();

  } else if(uip_udp_conn &&
            uip_newdata() &&
            uip_udp_conn->lport == HTONS(NTP_PORT)) {
    ntp_digestpacket();

#ifdef HAS_MDNS
  } else if(uip_udp_conn &&
            uip_newdata() &&
            uip_udp_conn->lport == HTONS(MDNS_PORT)) {
    mdns_new_data();

#endif
  } 
}
예제 #9
0
파일: dhcpc.c 프로젝트: Anil8590/tiva-c
/*---------------------------------------------------------------------------*/
void
dhcpc_appcall(void)
{
  handle_dhcp();
}
예제 #10
0
파일: dhcpc.c 프로젝트: mogorman/stevie
/*---------------------------------------------------------------------------*/
void
dhcpc_appcall(void)
{
	if(s.state != STATE_CONFIG_RECEIVED)
		handle_dhcp();
}
예제 #11
0
파일: main.c 프로젝트: frozensunq/thudhcp
int main(int argc, char **argv)
{
	mode = IPv4;
	daemon = 1;
	err = stderr;
	portset = 0;
	srand(time(NULL));
	int i;
	for (i = 1; i < argc; ++i) {
		if (strcmp(argv[i], "-f") == 0) {
			daemon = 0;
		} else if (strcmp(argv[i], "-p") == 0) {
			portset = 1;
		} else if (i + 1 < argc && strcmp(argv[i], "--network-interface") == 0) {
			++i;
			strcpy(network_interface_name, argv[i]);
		} else if (i + 1 < argc && strcmp(argv[i], "--encap-mode") == 0) {
			++i;
			if (strcmp(argv[i], "ipv4") == 0) {
				mode = IPv4;
			} else if (strcmp(argv[i], "ipv6") == 0) {
				mode = IPv6;
			} else if (strcmp(argv[i], "dhcpv6") == 0) {
				mode = DHCPv6;
			} else {
				usage();
				exit(0);
			}
		} else if (i + 1 < argc && strcmp(argv[i], "--server-addr") == 0) {
			++i;
			strcpy(server_addr, argv[i]);
		} else if (i + 1 < argc && strcmp(argv[i], "--local-addr") == 0) {
			++i;
			strcpy(local_addr, argv[i]);
		} else {//config-interface
			strcpy(config_interface_name, argv[i]);
		}
	}
	
	if (mode == IPv6) {
		if (strlen(server_addr) == 0) {
			fprintf(err, "server-addr MUST be configured in DHCPv4-over-IPv6 mode!\n");
			exit(0);
		}
		memset(&dest, 0, sizeof(dest));
		dest.sin6_family = AF_INET6;
		//dest.sin6_port = htons(IPv6_SERVER_PORT);
		if (inet_pton(AF_INET6, server_addr, &dest.sin6_addr) < 0) {
			fprintf(err, "Failed to resolve server_addr : %s\n", server_addr);
			exit(1);
		}
		printf("server-addr : %s\n", server_addr);
	}

    if (mode == DHCPv6) {
		memset(&dest, 0, sizeof(dest));
		dest.sin6_family = AF_INET6;
		if (strlen(server_addr) == 0) {
			strcpy(server_addr, "ff02::1:2");
		}
		if (inet_pton(AF_INET6, server_addr, &dest.sin6_addr) < 0) {
			fprintf(err, "Failed to resolve server_addr : %s\n", server_addr);
			exit(1);
		}
	}
	
	if ((mode == IPv6 || mode == DHCPv6) && strlen(local_addr) > 0) {
		memset(&src, 0, sizeof(src));
		src.sin6_family = AF_INET6;
		if (inet_pton(AF_INET6, local_addr, &src.sin6_addr) < 0) {
			fprintf(err, "Failed to resolve local_addr : %s\n", local_addr);
			exit(1);
		}
		printf("local-addr : %s\n", local_addr);
	}

	if (portset)
		printf("port set mode\n");
//	else
//		printf("No Port Set!\n");
	
	if (config_interface_name[0] == '\0') {
		usage();
		exit(0);
	}
	if (network_interface_name[0] == '\0')
		strcpy(network_interface_name, config_interface_name);
	
	init_interfaces();
	init_dhcp();
	if (daemon)
		init_daemon();
		
	while (1) {
		handle_dhcp();
	}
	return 0;
}