1 /* 2 * FILE: sap.h 3 * AUTHOR: Ivan R. Judson <judson@mcs.anl.gov> 4 * 5 * $Revision: 1.1 $ 6 * $Date: 2003/05/28 11:03:36 $ 7 * 8 * Copyright (c) 2002 Argonne National Laboratory/University of Chicago 9 * All rights reserved. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, is permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 3. All advertising materials mentioning features or use of this software 20 * must display the following acknowledgement: 21 * This product includes software developed by the Mathematics and 22 * Computer Science Division of Argonne National Laboratory. 23 * 4. Neither the name of the University nor of the Department may be used 24 * to endorse or promote products derived from this software without 25 * specific prior written permission. 26 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND 27 * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE 30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 * SUCH DAMAGE. 37 */ 38 39 #ifndef _SAP_H 40 #define _SAP_H 41 42 struct sap; 43 44 #if defined(__cplusplus) 45 extern "C" { 46 #endif 47 48 #define SAP_MAX_PACKET_LEN 1024 49 50 typedef struct { 51 #ifdef WORDS_BIGENDIAN 52 unsigned short version:3; 53 unsigned short address_type:1; 54 unsigned short reserved:1; 55 unsigned short message_type:1; 56 unsigned short encrypted_payload:1; 57 unsigned short compressed_payload:1; 58 #else 59 unsigned short compressed_payload:1; 60 unsigned short encrypted_payload:1; 61 unsigned short message_type:1; 62 unsigned short reserved:1; 63 unsigned short address_type:1; 64 unsigned short version:3; 65 #endif 66 uint8_t authentication_length; 67 uint16_t message_identifier_hash; 68 } sap_header; 69 70 typedef struct { 71 sap_header *header; 72 unsigned char *originating_source; 73 unsigned char *authentication_data; 74 unsigned char *payload_type; 75 unsigned char *payload; 76 } sap_packet; 77 78 typedef void (*sap_callback)(sap_packet *packet); 79 80 struct sap *sap_init(const char *addr, uint16_t port, int ttl, 81 sap_callback callback); 82 83 int sap_recv(struct sap *s, struct timeval *timeout); 84 85 void sap_done(struct sap *s); 86 87 void print_sap_packet(sap_packet *p); 88 89 #if defined(__cplusplus) 90 } 91 #endif 92 93 #endif 94 95