1f7c5421560640d23fc10803b9d59a9ff1d83e467The Android Open Source Project/* 2f7c5421560640d23fc10803b9d59a9ff1d83e467The Android Open Source Project * dhcpcd - DHCP client daemon 3a3a2260384a906e1674c7498c2f479e9f37bc503Dmitry Shmidt * Copyright (c) 2006-2011 Roy Marples <roy@marples.name> 4f7c5421560640d23fc10803b9d59a9ff1d83e467The Android Open Source Project * All rights reserved 5f7c5421560640d23fc10803b9d59a9ff1d83e467The Android Open Source Project 6f7c5421560640d23fc10803b9d59a9ff1d83e467The Android Open Source Project * Redistribution and use in source and binary forms, with or without 7f7c5421560640d23fc10803b9d59a9ff1d83e467The Android Open Source Project * modification, are permitted provided that the following conditions 8f7c5421560640d23fc10803b9d59a9ff1d83e467The Android Open Source Project * are met: 9f7c5421560640d23fc10803b9d59a9ff1d83e467The Android Open Source Project * 1. Redistributions of source code must retain the above copyright 10f7c5421560640d23fc10803b9d59a9ff1d83e467The Android Open Source Project * notice, this list of conditions and the following disclaimer. 11f7c5421560640d23fc10803b9d59a9ff1d83e467The Android Open Source Project * 2. Redistributions in binary form must reproduce the above copyright 12f7c5421560640d23fc10803b9d59a9ff1d83e467The Android Open Source Project * notice, this list of conditions and the following disclaimer in the 13f7c5421560640d23fc10803b9d59a9ff1d83e467The Android Open Source Project * documentation and/or other materials provided with the distribution. 14f7c5421560640d23fc10803b9d59a9ff1d83e467The Android Open Source Project * 15f7c5421560640d23fc10803b9d59a9ff1d83e467The Android Open Source Project * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16f7c5421560640d23fc10803b9d59a9ff1d83e467The Android Open Source Project * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17f7c5421560640d23fc10803b9d59a9ff1d83e467The Android Open Source Project * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18f7c5421560640d23fc10803b9d59a9ff1d83e467The Android Open Source Project * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19f7c5421560640d23fc10803b9d59a9ff1d83e467The Android Open Source Project * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20f7c5421560640d23fc10803b9d59a9ff1d83e467The Android Open Source Project * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21f7c5421560640d23fc10803b9d59a9ff1d83e467The Android Open Source Project * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22f7c5421560640d23fc10803b9d59a9ff1d83e467The Android Open Source Project * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23f7c5421560640d23fc10803b9d59a9ff1d83e467The Android Open Source Project * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24f7c5421560640d23fc10803b9d59a9ff1d83e467The Android Open Source Project * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25f7c5421560640d23fc10803b9d59a9ff1d83e467The Android Open Source Project * SUCH DAMAGE. 26f7c5421560640d23fc10803b9d59a9ff1d83e467The Android Open Source Project */ 27f7c5421560640d23fc10803b9d59a9ff1d83e467The Android Open Source Project 28f7c5421560640d23fc10803b9d59a9ff1d83e467The Android Open Source Project#ifndef COMMON_H 29f7c5421560640d23fc10803b9d59a9ff1d83e467The Android Open Source Project#define COMMON_H 30f7c5421560640d23fc10803b9d59a9ff1d83e467The Android Open Source Project 31a3a2260384a906e1674c7498c2f479e9f37bc503Dmitry Shmidt#include <sys/time.h> 32f7c5421560640d23fc10803b9d59a9ff1d83e467The Android Open Source Project#include <stdio.h> 33e86eee143ed21592f88a46623a81f71002430459Dmitry Shmidt 34e86eee143ed21592f88a46623a81f71002430459Dmitry Shmidt#include "config.h" 35e86eee143ed21592f88a46623a81f71002430459Dmitry Shmidt#include "defs.h" 36f7c5421560640d23fc10803b9d59a9ff1d83e467The Android Open Source Project 37f7c5421560640d23fc10803b9d59a9ff1d83e467The Android Open Source Project#define UNCONST(a) ((void *)(unsigned long)(const void *)(a)) 38f7c5421560640d23fc10803b9d59a9ff1d83e467The Android Open Source Project 39e86eee143ed21592f88a46623a81f71002430459Dmitry Shmidt#define timeval_to_double(tv) ((tv)->tv_sec * 1.0 + (tv)->tv_usec * 1.0e-6) 40e86eee143ed21592f88a46623a81f71002430459Dmitry Shmidt#define timernorm(tvp) \ 41e86eee143ed21592f88a46623a81f71002430459Dmitry Shmidt do { \ 42e86eee143ed21592f88a46623a81f71002430459Dmitry Shmidt while ((tvp)->tv_usec >= 1000000) { \ 43e86eee143ed21592f88a46623a81f71002430459Dmitry Shmidt (tvp)->tv_sec++; \ 44e86eee143ed21592f88a46623a81f71002430459Dmitry Shmidt (tvp)->tv_usec -= 1000000; \ 45e86eee143ed21592f88a46623a81f71002430459Dmitry Shmidt } \ 46e86eee143ed21592f88a46623a81f71002430459Dmitry Shmidt } while (0 /* CONSTCOND */); 47e86eee143ed21592f88a46623a81f71002430459Dmitry Shmidt 48f7c5421560640d23fc10803b9d59a9ff1d83e467The Android Open Source Project#if __GNUC__ > 2 || defined(__INTEL_COMPILER) 49e86eee143ed21592f88a46623a81f71002430459Dmitry Shmidt# define _noreturn __attribute__((__noreturn__)) 50e86eee143ed21592f88a46623a81f71002430459Dmitry Shmidt# define _packed __attribute__((__packed__)) 51e86eee143ed21592f88a46623a81f71002430459Dmitry Shmidt# define _unused __attribute__((__unused__)) 52f7c5421560640d23fc10803b9d59a9ff1d83e467The Android Open Source Project#else 53e86eee143ed21592f88a46623a81f71002430459Dmitry Shmidt# define _noreturn 54e86eee143ed21592f88a46623a81f71002430459Dmitry Shmidt# define _packed 55f7c5421560640d23fc10803b9d59a9ff1d83e467The Android Open Source Project# define _unused 56f7c5421560640d23fc10803b9d59a9ff1d83e467The Android Open Source Project#endif 57f7c5421560640d23fc10803b9d59a9ff1d83e467The Android Open Source Project 58e86eee143ed21592f88a46623a81f71002430459Dmitry Shmidt/* We don't really need this as our supported systems define __restrict 59e86eee143ed21592f88a46623a81f71002430459Dmitry Shmidt * automatically for us, but it is here for completeness. */ 60e86eee143ed21592f88a46623a81f71002430459Dmitry Shmidt#ifndef __restrict 61e86eee143ed21592f88a46623a81f71002430459Dmitry Shmidt# if defined(__lint__) 62e86eee143ed21592f88a46623a81f71002430459Dmitry Shmidt# define __restrict 63e86eee143ed21592f88a46623a81f71002430459Dmitry Shmidt# elif __STDC_VERSION__ >= 199901L 64e86eee143ed21592f88a46623a81f71002430459Dmitry Shmidt# define __restrict restrict 65e86eee143ed21592f88a46623a81f71002430459Dmitry Shmidt# elif !(2 < __GNUC__ || (2 == __GNU_C && 95 <= __GNUC_VERSION__)) 66e86eee143ed21592f88a46623a81f71002430459Dmitry Shmidt# define __restrict 67f7c5421560640d23fc10803b9d59a9ff1d83e467The Android Open Source Project# endif 68f7c5421560640d23fc10803b9d59a9ff1d83e467The Android Open Source Project#endif 69f7c5421560640d23fc10803b9d59a9ff1d83e467The Android Open Source Project 70f7c5421560640d23fc10803b9d59a9ff1d83e467The Android Open Source Projectint set_cloexec(int); 71f7c5421560640d23fc10803b9d59a9ff1d83e467The Android Open Source Projectint set_nonblock(int); 72e86eee143ed21592f88a46623a81f71002430459Dmitry Shmidtchar *get_line(FILE * __restrict); 73f7c5421560640d23fc10803b9d59a9ff1d83e467The Android Open Source Projectextern int clock_monotonic; 74f7c5421560640d23fc10803b9d59a9ff1d83e467The Android Open Source Projectint get_monotonic(struct timeval *); 75a3a2260384a906e1674c7498c2f479e9f37bc503Dmitry Shmidtssize_t setvar(char ***, const char *, const char *, const char *); 76a3a2260384a906e1674c7498c2f479e9f37bc503Dmitry Shmidtssize_t setvard(char ***, const char *, const char *, int); 77f7c5421560640d23fc10803b9d59a9ff1d83e467The Android Open Source Projecttime_t uptime(void); 78f7c5421560640d23fc10803b9d59a9ff1d83e467The Android Open Source Projectint writepid(int, pid_t); 79f7c5421560640d23fc10803b9d59a9ff1d83e467The Android Open Source Projectvoid *xrealloc(void *, size_t); 80f7c5421560640d23fc10803b9d59a9ff1d83e467The Android Open Source Projectvoid *xmalloc(size_t); 81f7c5421560640d23fc10803b9d59a9ff1d83e467The Android Open Source Projectvoid *xzalloc(size_t); 82f7c5421560640d23fc10803b9d59a9ff1d83e467The Android Open Source Projectchar *xstrdup(const char *); 83f7c5421560640d23fc10803b9d59a9ff1d83e467The Android Open Source Project 846a7ffa31d45635b56558b9ba8bbd05fc002e1fa4John Grossman/* Uncomment the #def below to send DHCPCD syslog messages to Android's logcat 856a7ffa31d45635b56558b9ba8bbd05fc002e1fa4John Grossman * instead. */ 866a7ffa31d45635b56558b9ba8bbd05fc002e1fa4John Grossman/* #define REDIRECT_SYSLOG_TO_ANDROID_LOGCAT */ 876a7ffa31d45635b56558b9ba8bbd05fc002e1fa4John Grossman#ifdef REDIRECT_SYSLOG_TO_ANDROID_LOGCAT 886a7ffa31d45635b56558b9ba8bbd05fc002e1fa4John Grossman 896a7ffa31d45635b56558b9ba8bbd05fc002e1fa4John Grossman#define LOG_TAG "DHCPCD" 906a7ffa31d45635b56558b9ba8bbd05fc002e1fa4John Grossman#include <utils/Log.h> 916a7ffa31d45635b56558b9ba8bbd05fc002e1fa4John Grossman 926a7ffa31d45635b56558b9ba8bbd05fc002e1fa4John Grossman#undef LOG_EMERG 936a7ffa31d45635b56558b9ba8bbd05fc002e1fa4John Grossman#undef LOG_ALERT 946a7ffa31d45635b56558b9ba8bbd05fc002e1fa4John Grossman#undef LOG_CRIT 956a7ffa31d45635b56558b9ba8bbd05fc002e1fa4John Grossman#undef LOG_ERR 966a7ffa31d45635b56558b9ba8bbd05fc002e1fa4John Grossman#undef LOG_WARNING 976a7ffa31d45635b56558b9ba8bbd05fc002e1fa4John Grossman#undef LOG_NOTICE 986a7ffa31d45635b56558b9ba8bbd05fc002e1fa4John Grossman#undef LOG_INFO 996a7ffa31d45635b56558b9ba8bbd05fc002e1fa4John Grossman#undef LOG_DEBUG 1006a7ffa31d45635b56558b9ba8bbd05fc002e1fa4John Grossman 1016a7ffa31d45635b56558b9ba8bbd05fc002e1fa4John Grossman#define LOG_EMERG ANDROID_LOG_FATAL 1026a7ffa31d45635b56558b9ba8bbd05fc002e1fa4John Grossman#define LOG_ALERT ANDROID_LOG_FATAL 1036a7ffa31d45635b56558b9ba8bbd05fc002e1fa4John Grossman#define LOG_CRIT ANDROID_LOG_FATAL 1046a7ffa31d45635b56558b9ba8bbd05fc002e1fa4John Grossman#define LOG_ERR ANDROID_LOG_ERROR 1056a7ffa31d45635b56558b9ba8bbd05fc002e1fa4John Grossman#define LOG_WARNING ANDROID_LOG_WARN 1066a7ffa31d45635b56558b9ba8bbd05fc002e1fa4John Grossman#define LOG_NOTICE ANDROID_LOG_WARN 1076a7ffa31d45635b56558b9ba8bbd05fc002e1fa4John Grossman#define LOG_INFO ANDROID_LOG_INFO 1086a7ffa31d45635b56558b9ba8bbd05fc002e1fa4John Grossman#define LOG_DEBUG ANDROID_LOG_DEBUG 1096a7ffa31d45635b56558b9ba8bbd05fc002e1fa4John Grossman#define syslog(a, b...) android_printLog(a, LOG_TAG, b) 1106a7ffa31d45635b56558b9ba8bbd05fc002e1fa4John Grossman 1116a7ffa31d45635b56558b9ba8bbd05fc002e1fa4John Grossman#endif /* REDIRECT_SYSLOG_TO_ANDROID_LOGCAT */ 1126a7ffa31d45635b56558b9ba8bbd05fc002e1fa4John Grossman 113f7c5421560640d23fc10803b9d59a9ff1d83e467The Android Open Source Project#endif 114