RCS file: /usr1/CVS/rtems/cpukit/libnetworking/nfs/bootp_subr.c,v
retrieving revision 1.25
diff -p -u -u -r1.25 bootp_subr.c
|
|
bootpc_call( |
456 | 456 | |
457 | 457 | } /* while secs */ |
458 | 458 | } /* forever send/receive */ |
459 | | |
460 | | printf("BOOTP timeout for server 0x%x\n", |
461 | | (int)ntohl(sin->sin_addr.s_addr)); |
462 | | |
| 459 | { |
| 460 | uint32_t addr = ntohl(sin->sin_addr.s_addr); |
| 461 | printf("BOOTP timeout for server %lu.%lu.%lu.%lu\n", |
| 462 | (addr >> 24) & 0xff, (addr >> 16) & 0xff, |
| 463 | (addr >> 8) & 0xff, addr & 0xff); |
| 464 | } |
463 | 465 | error = ETIMEDOUT; |
464 | 466 | goto out; |
465 | 467 | |
… |
… |
bootpc_fakeup_interface(struct ifreq *ir |
510 | 512 | sin->sin_family = AF_INET; |
511 | 513 | sin->sin_addr.s_addr = INADDR_ANY; |
512 | 514 | error = ifioctl(so, SIOCSIFADDR, (caddr_t)ireq, procp); |
513 | | if (error) { |
| 515 | /* |
| 516 | * Ignore a File already exists (EEXIST) error code. This means a |
| 517 | * route for the address is already present and is returned on |
| 518 | * a second pass to here. |
| 519 | */ |
| 520 | if (error && (error != EEXIST)) { |
514 | 521 | printf("bootpc_fakeup_interface: set if addr, error=%s\n", strerror(error)); |
515 | 522 | return error; |
516 | 523 | } |
… |
… |
bootpc_fakeup_interface(struct ifreq *ir |
541 | 548 | return error; |
542 | 549 | } |
543 | 550 | |
544 | | |
545 | 551 | /* Add default route to 0.0.0.0 so we can send data */ |
546 | 552 | |
547 | 553 | bzero((caddr_t) &dst, sizeof(dst)); |
… |
… |
bootpc_fakeup_interface(struct ifreq *ir |
565 | 571 | (struct sockaddr *) &mask, |
566 | 572 | RTF_UP | RTF_STATIC |
567 | 573 | , NULL); |
568 | | if (error) |
569 | | printf("bootpc_fakeup_interface: add default route, error=%d\n", error); |
| 574 | if (error && error != EEXIST) |
| 575 | printf("bootpc_fakeup_interface: add default route, error=%s\n", |
| 576 | strerror(error)); |
| 577 | |
570 | 578 | return error; |
571 | 579 | } |
572 | 580 | |
RCS file: /usr1/CVS/rtems/cpukit/libnetworking/rtems/rtems_dhcp.c,v
retrieving revision 1.2
diff -p -u -u -r1.2 rtems_dhcp.c
|
|
dhcp_task (rtems_task_argument _sdl) |
697 | 697 | int error; |
698 | 698 | struct proc *procp = NULL; |
699 | 699 | int disconnected; |
| 700 | rtems_status_code ev_st; |
700 | 701 | |
701 | 702 | sdl = (struct sockaddr_dl *) _sdl; |
702 | 703 | |
703 | 704 | count = dhcp_elapsed_time; |
704 | 705 | disconnected = 0; |
705 | 706 | |
706 | | |
707 | | while (TRUE) |
| 707 | while (true) |
708 | 708 | { |
709 | 709 | /* |
710 | 710 | * Sleep until the next poll |
711 | 711 | */ |
712 | 712 | timeout = TOD_MILLISECONDS_TO_TICKS (1000); |
713 | | rtems_event_receive (RTEMS_EVENT_0, |
714 | | RTEMS_WAIT | RTEMS_EVENT_ANY, |
715 | | timeout, &event_out); |
| 713 | ev_st = rtems_event_receive (RTEMS_EVENT_0, |
| 714 | RTEMS_WAIT | RTEMS_EVENT_ANY, |
| 715 | timeout, &event_out); |
716 | 716 | |
717 | | if(event_out & RTEMS_EVENT_0) break; |
| 717 | /* |
| 718 | * Check if not a poll timeout. So when ANY event received, exit task. |
| 719 | * Actually, only event RTEMS_EVENT_0 sent from rtem_dhcp_failsafe.c |
| 720 | * if "failsafe" dhcp enabled when interface down. Otherwise, no |
| 721 | * event should occur, just timeout. |
| 722 | */ |
| 723 | if(ev_st != RTEMS_TIMEOUT) |
| 724 | break; |
718 | 725 | |
719 | 726 | count++; |
720 | 727 | |
… |
… |
dhcp_task (rtems_task_argument _sdl) |
722 | 729 | { |
723 | 730 | rtems_bsdnet_semaphore_obtain (); |
724 | 731 | |
725 | | dhcp_request_req (&call, &dhcp_req, sdl, TRUE); |
| 732 | dhcp_request_req (&call, &dhcp_req, sdl, true); |
726 | 733 | |
727 | 734 | /* |
728 | 735 | * Send the Request. |
… |
… |
dhcp_init (int update_files) |
886 | 893 | sprintf (ireq.ifr_name, "%s%d", ifp->if_name, ifp->if_unit); |
887 | 894 | |
888 | 895 | if ((error = socreate (AF_INET, &so, SOCK_DGRAM, 0, procp)) != 0) { |
889 | | printf ("dhcpc_init: socreate, error=%d\n", error); |
| 896 | printf ("dhcpc_init: socreate, error: %s\n", strerror(error)); |
890 | 897 | return -1; |
891 | 898 | } |
892 | 899 | |
… |
… |
dhcp_init (int update_files) |
904 | 911 | |
905 | 912 | if (!sdl){ |
906 | 913 | printf ("dhcpc_init: Unable to find HW address\n"); |
| 914 | soclose (so); |
907 | 915 | return -1; |
908 | 916 | } |
909 | 917 | if (sdl->sdl_alen != EALEN) { |
910 | 918 | printf ("dhcpc_init: HW address len is %d, expected value is %d\n", |
911 | 919 | sdl->sdl_alen, EALEN); |
| 920 | soclose (so); |
912 | 921 | return -1; |
913 | 922 | } |
914 | 923 | |
… |
… |
dhcp_init (int update_files) |
922 | 931 | */ |
923 | 932 | error = bootpc_call (&call, &reply, procp); |
924 | 933 | if (error) { |
925 | | printf ("BOOTP call failed -- error %d\n", error); |
| 934 | printf ("BOOTP call failed -- %s\n", strerror(error)); |
| 935 | soclose (so); |
926 | 936 | return -1; |
927 | 937 | } |
928 | 938 | |
… |
… |
dhcp_init (int update_files) |
931 | 941 | */ |
932 | 942 | if (memcmp (&reply.vend[0], dhcp_magic_cookie, sizeof (dhcp_magic_cookie)) != 0) { |
933 | 943 | printf ("DHCP server did not send Magic Cookie.\n"); |
| 944 | soclose (so); |
934 | 945 | return -1; |
935 | 946 | } |
936 | 947 | |
… |
… |
dhcp_init (int update_files) |
938 | 949 | |
939 | 950 | if (dhcp_message_type != DHCP_OFFER) { |
940 | 951 | printf ("DHCP server did not send a DHCP Offer.\n"); |
| 952 | soclose (so); |
941 | 953 | return -1; |
942 | 954 | } |
943 | 955 | |
944 | 956 | /* |
945 | 957 | * Send a DHCP REQUEST |
946 | 958 | */ |
947 | | dhcp_request_req (&call, &reply, sdl, TRUE); |
| 959 | dhcp_request_req (&call, &reply, sdl, true); |
948 | 960 | |
949 | 961 | error = bootpc_call (&call, &reply, procp); |
950 | 962 | if (error) { |
951 | | printf ("BOOTP call failed -- error %d\n", error); |
| 963 | printf ("BOOTP call failed -- %s\n", strerror(error)); |
| 964 | soclose (so); |
952 | 965 | return -1; |
953 | 966 | } |
954 | 967 | |
… |
… |
dhcp_init (int update_files) |
957 | 970 | */ |
958 | 971 | if (memcmp (&reply.vend[0], dhcp_magic_cookie, sizeof (dhcp_magic_cookie)) != 0) { |
959 | 972 | printf ("DHCP server did not send Magic Cookie.\n"); |
| 973 | soclose (so); |
960 | 974 | return -1; |
961 | 975 | } |
962 | 976 | |
… |
… |
dhcp_init (int update_files) |
964 | 978 | |
965 | 979 | if (dhcp_message_type != DHCP_ACK) { |
966 | 980 | printf ("DHCP server did not accept the DHCP request\n"); |
| 981 | soclose (so); |
967 | 982 | return -1; |
968 | 983 | } |
969 | 984 | |
… |
… |
dhcp_init (int update_files) |
1114 | 1129 | */ |
1115 | 1130 | void rtems_bsdnet_do_dhcp (void) |
1116 | 1131 | { |
| 1132 | bool update = true; |
1117 | 1133 | rtems_bsdnet_semaphore_obtain (); |
1118 | | while( dhcp_init (TRUE) < 0 ) { |
| 1134 | while( dhcp_init (update) < 0 ) { |
| 1135 | update = false; |
1119 | 1136 | rtems_bsdnet_semaphore_release(); |
1120 | 1137 | rtems_task_wake_after(TOD_MILLISECONDS_TO_TICKS(1000)); |
1121 | 1138 | rtems_bsdnet_semaphore_obtain (); |
… |
… |
int rtems_bsdnet_do_dhcp_timeout( void ) |
1128 | 1145 | int return_value; |
1129 | 1146 | |
1130 | 1147 | rtems_bsdnet_semaphore_obtain (); |
1131 | | return_value = dhcp_init (FALSE); |
| 1148 | return_value = dhcp_init (false); |
1132 | 1149 | rtems_bsdnet_semaphore_release (); |
1133 | 1150 | |
1134 | 1151 | return return_value; |