1 #ifndef FR_PACKET_H 2 #define FR_PACKET_H 3 4 /* 5 * packet.h Structures and prototypes 6 * for packet manipulation 7 * 8 * Version: $Id: 7e41a8dec6630a42738f38cf4f940eb8014d75d2 $ 9 * 10 * This program is free software; you can redistribute it and/or modify 11 * it under the terms of the GNU General Public License as published by 12 * the Free Software Foundation; either version 2 of the License, or 13 * (at your option) any later version. 14 * 15 * This program is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU General Public License for more details. 19 * 20 * You should have received a copy of the GNU General Public License 21 * along with this program; if not, write to the Free Software 22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 23 * 24 * Copyright 2001,2002,2003,2004,2005,2006 The FreeRADIUS server project 25 */ 26 27 RCSIDH(packet_h, "$Id: 7e41a8dec6630a42738f38cf4f940eb8014d75d2 $") 28 29 #ifdef __cplusplus 30 extern "C" { 31 #endif 32 33 int fr_packet_cmp(RADIUS_PACKET const *a, RADIUS_PACKET const *b); 34 int fr_inaddr_any(fr_ipaddr_t *ipaddr); 35 void fr_request_from_reply(RADIUS_PACKET *request, 36 RADIUS_PACKET const *reply); 37 int fr_socket(fr_ipaddr_t *ipaddr, uint16_t port); 38 39 typedef struct fr_packet_list_t fr_packet_list_t; 40 41 fr_packet_list_t *fr_packet_list_create(int alloc_id); 42 void fr_packet_list_free(fr_packet_list_t *pl); 43 bool fr_packet_list_insert(fr_packet_list_t *pl, 44 RADIUS_PACKET **request_p); 45 46 RADIUS_PACKET **fr_packet_list_find(fr_packet_list_t *pl, 47 RADIUS_PACKET *request); 48 RADIUS_PACKET **fr_packet_list_find_byreply(fr_packet_list_t *pl, 49 RADIUS_PACKET *reply); 50 bool fr_packet_list_yank(fr_packet_list_t *pl, 51 RADIUS_PACKET *request); 52 uint32_t fr_packet_list_num_elements(fr_packet_list_t *pl); 53 bool fr_packet_list_id_alloc(fr_packet_list_t *pl, int proto, 54 RADIUS_PACKET **request_p, void **pctx); 55 bool fr_packet_list_id_free(fr_packet_list_t *pl, 56 RADIUS_PACKET *request, bool yank); 57 bool fr_packet_list_socket_add(fr_packet_list_t *pl, int sockfd, int proto, 58 fr_ipaddr_t *dst_ipaddr, uint16_t dst_port, 59 void *ctx); 60 bool fr_packet_list_socket_del(fr_packet_list_t *pl, int sockfd); 61 bool fr_packet_list_socket_freeze(fr_packet_list_t *pl, int sockfd); 62 bool fr_packet_list_socket_thaw(fr_packet_list_t *pl, int sockfd); 63 int fr_packet_list_walk(fr_packet_list_t *pl, void *ctx, rb_walker_t callback); 64 int fr_packet_list_fd_set(fr_packet_list_t *pl, fd_set *set); 65 RADIUS_PACKET *fr_packet_list_recv(fr_packet_list_t *pl, fd_set *set); 66 67 uint32_t fr_packet_list_num_incoming(fr_packet_list_t *pl); 68 uint32_t fr_packet_list_num_outgoing(fr_packet_list_t *pl); 69 void fr_packet_header_print(FILE *fp, RADIUS_PACKET *packet, bool received); 70 71 /* 72 * "find" returns a pointer to the RADIUS_PACKET* member in the 73 * caller's structure. In order to get the pointer to the *top* 74 * of the caller's structure, you have to subtract the offset to 75 * the member from the returned pointer, and cast it to the 76 * required type. 77 */ 78 # define fr_packet2myptr(TYPE, MEMBER, PTR) (TYPE *) (((char *)PTR) - offsetof(TYPE, MEMBER)) 79 80 #ifdef __cplusplus 81 } 82 #endif 83 84 #endif /* FR_PACKET_H */ 85