/* $Id$ * Include file for the packet assembly and disassembly layer * Copyright (C) 2004 Jan Kratochvil * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; exactly version 2 of June 1991 is required * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef _UDPGATE_PACKET_H #define _UDPGATE_PACKET_H 1 #include #include G_BEGIN_DECLS #define HOSTIP_GUINT32_TO_STRING(hostip_guint32) \ (udpgate_printf_alloca("%d.%d.%d.%d", \ ((hostip_guint32)>>24U)&0xFFU, \ ((hostip_guint32)>>16U)&0xFFU, \ ((hostip_guint32)>> 8U)&0xFFU, \ ((hostip_guint32)>> 0U)&0xFFU)) /* Do not use nested udpgate_printf_alloca() - macros cannot nest! */ #define SOCKADDR_IN_TO_STRING(sockaddr_in_pointer) ({ \ const gchar *_hostip_string=HOSTIP_GUINT32_TO_STRING(ntohl((sockaddr_in_pointer)->sin_addr.s_addr)); \ udpgate_printf_alloca("%s:%d",_hostip_string,ntohs((sockaddr_in_pointer)->sin_port)); \ }) #define PACKET_HEADER "UDPGate0" #define PACKET_ELEM_ATTR_MANDATORY (0x80000000) #define PACKET_ELEM_ATTR_OPTIONAL (0x00000000) enum packet_elem_type { PACKET_ELEM_TYPE_PROGRAM_VERSION=(0x01|PACKET_ELEM_ATTR_MANDATORY), /* 'VERSION' string */ PACKET_ELEM_TYPE_CLIENT_INADDR =(0x02|PACKET_ELEM_ATTR_MANDATORY), /* host order */ PACKET_ELEM_TYPE_CLIENT_PORT =(0x03|PACKET_ELEM_ATTR_MANDATORY), /* host order */ PACKET_ELEM_TYPE_DATA_GUINT32 =(0x04|PACKET_ELEM_ATTR_MANDATORY), /* user data (e.g. unique id) */ }; gpointer packet_assembly(size_t *packet_length_pointer,GHashTable *values); gboolean packet_recognized(gconstpointer packet,size_t packet_length); GHashTable *packet_disassembly(gconstpointer packet,size_t packet_length); void packet_disassembly_destroy(GHashTable *hash); G_END_DECLS #endif /* _UDPGATE_PACKET_H */