00001 /* 00002 * Copyright (c) 2005, 2006 by KoanLogic s.r.l. <http://www.koanlogic.com> 00003 * All rights reserved. 00004 * 00005 * This file is part of KLone, and as such it is subject to the license stated 00006 * in the LICENSE file which you have received as part of this distribution. 00007 * 00008 * $Id: addr.h,v 1.15 2008/06/04 17:48:01 tat Exp $ 00009 */ 00010 00011 #ifndef _KLONE_ADDR_H_ 00012 #define _KLONE_ADDR_H_ 00013 00014 #include <sys/types.h> 00015 00016 #include <u/libu.h> 00017 00018 #ifdef __cplusplus 00019 extern "C" { 00020 #endif 00021 00022 typedef struct kaddr_s 00023 { 00024 enum type_e { ADDR_IPV4, ADDR_IPV6, ADDR_UNIX } type; 00025 union 00026 { 00027 struct sockaddr_in sin; 00028 #ifndef NO_IPV6 00029 struct sockaddr_in6 sin6; 00030 #endif 00031 #ifndef NO_UNIXSOCK 00032 struct sockaddr_un sun; 00033 #endif 00034 } sa; 00035 } kaddr_t; 00036 00037 int addr_create(kaddr_t **pa); 00038 int addr_set_from_config(kaddr_t *a, u_config_t *c); 00039 int addr_set_from_sa(kaddr_t *a, struct sockaddr *sa, size_t sz); 00040 int addr_set(kaddr_t *a, const char *ip, int port); 00041 int addr_set_ipv4_ip(kaddr_t *a, const char *ip); 00042 int addr_set_ipv4_port(kaddr_t *a, int port); 00043 int addr_free(kaddr_t *a); 00044 00045 #ifdef __cplusplus 00046 } 00047 #endif 00048 00049 #endif