1 /*- 2 * Copyright (c) 1998-2008 DHIS, Dynamic Host Information System 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * 26 */ 27 28 #define MAX_MSG 256 29 30 typedef struct { 31 int opcode; 32 int serial; 33 int version; 34 int rport; 35 } header4_t; 36 37 typedef struct { 38 int opcode; 39 int serial; 40 int version; 41 int rport; 42 int hostid; 43 } header_t; 44 45 typedef struct { header_t hdr; 46 unsigned char buff[MAX_MSG-sizeof(header_t)]; 47 } msg_t; 48 49 /* R3 messages */ 50 typedef struct { header4_t hdr; int id; int pass; } r3_online_req_t; 51 typedef struct { header4_t hdr; int id; int pass; } r3_offline_req_t; 52 53 /* R4 messages */ 54 typedef struct { header4_t hdr; } r4_echo_req_t; 55 typedef struct { header4_t hdr; int oserial; } r4_echo_ack_t; 56 typedef struct { header4_t hdr; int id; char pass[16]; } r4_auth_req_t; 57 typedef struct { header4_t hdr; } r4_auth_deny_t; 58 typedef struct { header4_t hdr; int sid; } r4_auth_ack_t; 59 typedef struct { header4_t hdr; int id; char x[200]; } r4_auth_sendx_t; 60 typedef struct { header4_t hdr; char y[200]; } r4_auth_sendy_t; 61 typedef struct { header4_t hdr; int next_check; } r4_check_req_t; 62 typedef struct { header4_t hdr; int sid; } r4_check_ack_t; 63 typedef struct { header4_t hdr; int sid; } r4_offline_req_t; 64 65 /* R5 messages */ 66 typedef struct { header_t hdr; } echo_req_t; 67 typedef struct { header_t hdr; int oserial; } echo_ack_t; 68 typedef struct { header_t hdr; char pass[16];int refresh; } auth_req_t; 69 typedef struct { header_t hdr; } auth_deny_t; 70 typedef struct { header_t hdr; int sid; } auth_ack_t; 71 typedef struct { header_t hdr; int sid; int raddr; } auth_ack_51_t; 72 typedef struct { header_t hdr; char x[200]; } auth_sendx_t; 73 typedef struct { header_t hdr; char y[200]; } auth_sendy_t; 74 typedef struct { header_t hdr; int next_check; } check_req_t; 75 typedef struct { header_t hdr; int sid; } check_ack_t; 76 typedef struct { header_t hdr; int sid; } offline_req_t; 77 78 int msg_size_by_opcode(int); 79 void swap_int(int *); 80 void swap_msg(int *,int); 81 int little_endian(void); 82 void convert_message(msg_t *,int); 83 int get_serial(void); 84 int net_init(void); 85 int net_close(void); 86 int net_check_message(void); 87 int net_read_message(msg_t *,int *); 88 int net_write_message(msg_t *,int,int); 89 int net_do_dgram(msg_t,int); 90 91