San Mehat | c4a895b | 2009-06-23 21:10:57 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include <stdio.h> |
| 18 | |
| 19 | #define LOG_TAG "DhcpState" |
| 20 | #include <cutils/log.h> |
| 21 | |
| 22 | #include "DhcpState.h" |
| 23 | |
| 24 | char *DhcpState::toString(int val, char *buffer, int max) { |
| 25 | if (val == DhcpState::INIT) |
| 26 | strncpy(buffer, "INIT", max); |
| 27 | else if (val == DhcpState::DISCOVERING) |
| 28 | strncpy(buffer, "DISCOVERING", max); |
| 29 | else if (val == DhcpState::REQUESTING) |
| 30 | strncpy(buffer, "REQUESTING", max); |
| 31 | else if (val == DhcpState::BOUND) |
| 32 | strncpy(buffer, "BOUND", max); |
| 33 | else if (val == DhcpState::RENEWING) |
| 34 | strncpy(buffer, "RENEWING", max); |
| 35 | else if (val == DhcpState::REBINDING) |
| 36 | strncpy(buffer, "REBINDING", max); |
| 37 | else if (val == DhcpState::REBOOT) |
| 38 | strncpy(buffer, "REBOOT", max); |
| 39 | else if (val == DhcpState::RENEW_REQUESTED) |
| 40 | strncpy(buffer, "RENEW_REQUESTED", max); |
| 41 | else if (val == DhcpState::INIT_IPV4LL) |
| 42 | strncpy(buffer, "INIT_IPV4LL", max); |
| 43 | else if (val == DhcpState::PROBING) |
| 44 | strncpy(buffer, "PROBING", max); |
| 45 | else if (val == DhcpState::ANNOUNCING) |
| 46 | strncpy(buffer, "ANNOUNCING", max); |
| 47 | else |
| 48 | strncpy(buffer, "(internal error)", max); |
| 49 | |
| 50 | return buffer; |
| 51 | } |
| 52 | |
| 53 | int DhcpState::parseString(const char *buffer) { |
| 54 | if (!strcasecmp(buffer, "INIT")) |
| 55 | return DhcpState::INIT; |
| 56 | else if (!strcasecmp(buffer, "DISCOVERING")) |
| 57 | return DhcpState::DISCOVERING; |
| 58 | else if (!strcasecmp(buffer, "REQUESTING")) |
| 59 | return DhcpState::REQUESTING; |
| 60 | else if (!strcasecmp(buffer, "BOUND")) |
| 61 | return DhcpState::BOUND; |
| 62 | else if (!strcasecmp(buffer, "RENEWING")) |
| 63 | return DhcpState::RENEWING; |
| 64 | else if (!strcasecmp(buffer, "REBINDING")) |
| 65 | return DhcpState::REBINDING; |
| 66 | else if (!strcasecmp(buffer, "REBOOT")) |
| 67 | return DhcpState::REBOOT; |
| 68 | else if (!strcasecmp(buffer, "RENEW_REQUESTED")) |
| 69 | return DhcpState::INIT_IPV4LL; |
| 70 | else if (!strcasecmp(buffer, "INIT_IPV4LL")) |
| 71 | return DhcpState::INIT_IPV4LL; |
| 72 | else if (!strcasecmp(buffer, "PROBING")) |
| 73 | return DhcpState::PROBING; |
| 74 | else if (!strcasecmp(buffer, "ANNOUNCING")) |
| 75 | return DhcpState::ANNOUNCING; |
| 76 | else { |
| 77 | LOGW("Bad state '%s'", buffer); |
| 78 | return -1; |
| 79 | } |
| 80 | } |