| 1 | /* |
| 2 | * Copyright (C) 1999,2000,2001 Ross Combs ([email protected]) |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; either version 2 |
| 7 | * of the License, or (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 17 | */ |
| 18 | #ifndef INCLUDED_ADDR_TYPES |
| 19 | #define INCLUDED_ADDR_TYPES |
| 20 | |
| 21 | #ifdef JUST_NEED_TYPES |
| 22 | # include "common/list.h" |
| 23 | #else |
| 24 | # define JUST_NEED_TYPES |
| 25 | # include "common/list.h" |
| 26 | # undef JUST_NEED_TYPES |
| 27 | #endif |
| 28 | |
| 29 | namespace pvpgn |
| 30 | { |
| 31 | |
| 32 | typedef union |
| 33 | { |
| 34 | unsigned long n; |
| 35 | int i; |
| 36 | void * p; |
| 37 | } t_addr_data; |
| 38 | |
| 39 | typedef struct addr_struct |
| 40 | #ifdef ADDR_INTERNAL_ACCESS |
| 41 | { |
| 42 | char const * str; /* hostname or ip */ |
| 43 | unsigned int ip; |
| 44 | unsigned int port; |
| 45 | t_addr_data data; /* data argument */ |
| 46 | } |
| 47 | #endif |
| 48 | t_addr; |
| 49 | |
| 50 | typedef struct netaddr_struct |
| 51 | #ifdef ADDR_INTERNAL_ACCESS |
| 52 | { |
| 53 | unsigned int ip; |
| 54 | unsigned int mask; |
| 55 | } |
| 56 | #endif |
| 57 | t_netaddr; |
| 58 | |
| 59 | typedef t_list t_addrlist; |
| 60 | |
| 61 | } |
| 62 | |
| 63 | #endif |
| 64 | |
| 65 | |
| 66 | /*****/ |
| 67 | #ifndef JUST_NEED_TYPES |
| 68 | #ifndef INCLUDED_ADDR_PROTOS |
| 69 | #define INCLUDED_ADDR_PROTOS |
| 70 | |
| 71 | namespace pvpgn |
| 72 | { |
| 73 | |
| 74 | /* ipaddr and port are in host byte order */ |
| 75 | extern char const * addr_num_to_addr_str(unsigned int ipaddr, unsigned short port); |
| 76 | /* ipaddr is in host byte order */ |
| 77 | extern char const * addr_num_to_ip_str(unsigned int ipaddr); |
| 78 | |
| 79 | extern char const * host_lookup(char const * hoststr, unsigned int * ipaddr); |
| 80 | |
| 81 | /* ipaddr and port are in host byte order */ |
| 82 | extern t_addr * addr_create_num(unsigned int ipaddr, unsigned short port); |
| 83 | |
| 84 | /* defipaddr and defport are in host byte order */ |
| 85 | extern t_addr * addr_create_str(char const * str, unsigned int defipaddr, unsigned short defport); |
| 86 | |
| 87 | extern int addr_destroy(t_addr const * addr); |
| 88 | extern char * addr_get_host_str(t_addr const * addr, char * str, unsigned int len); |
| 89 | extern char * addr_get_addr_str(t_addr const * addr, char * str, unsigned int len); |
| 90 | /* returned in host byte order */ |
| 91 | extern unsigned int addr_get_ip(t_addr const * addr); |
| 92 | /* returned in host byte order */ |
| 93 | extern unsigned short addr_get_port(t_addr const * addr); |
| 94 | extern int addr_set_data(t_addr * addr, t_addr_data data); |
| 95 | extern t_addr_data addr_get_data(t_addr const * addr); |
| 96 | extern t_netaddr * netaddr_create_str(char const * str); |
| 97 | extern int netaddr_destroy(t_netaddr const * netaddr); |
| 98 | extern char * netaddr_get_addr_str(t_netaddr const * netaddr, char * str, unsigned int len); |
| 99 | extern int netaddr_contains_addr_num(t_netaddr const * netaddr, unsigned int ipaddr); |
| 100 | |
| 101 | /* defipaddr and defport are in host byte order */ |
| 102 | extern int addrlist_append(t_addrlist * addrlist, char const * str, unsigned int defipaddr, unsigned short defport); |
| 103 | extern t_addrlist * addrlist_create(char const * str, unsigned int defipaddr, unsigned short defport); |
| 104 | extern int addrlist_destroy(t_addrlist * addrlist); |
| 105 | extern int addrlist_get_length(t_addrlist const * addrlist); |
| 106 | } |
| 107 | |
| 108 | #endif |
| 109 | #endif |