1 /* 2 * netcat.h -- main header project file 3 * Part of the GNU netcat project 4 * 5 * Author: Giovanni Giacobbi <giovanni@giacobbi.net> 6 * Copyright (C) 2002 - 2004 Giovanni Giacobbi 7 * 8 * $Id: netcat.h,v 1.35 2004/01/03 16:42:07 themnemonic Exp $ 9 */ 10 11 /*************************************************************************** 12 * * 13 * This program is free software; you can redistribute it and/or modify * 14 * it under the terms of the GNU General Public License as published by * 15 * the Free Software Foundation; either version 2 of the License, or * 16 * (at your option) any later version. * 17 * * 18 * This program is distributed in the hope that it will be useful, * 19 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 21 * GNU General Public License for more details. * 22 * * 23 ***************************************************************************/ 24 25 #ifndef NETCAT_H 26 #define NETCAT_H 27 28 #include <stdio.h> 29 #include <stdlib.h> 30 #include <stdarg.h> 31 #include <string.h> 32 #include <ctype.h> 33 #include <unistd.h> 34 #include <assert.h> 35 #include <errno.h> 36 #include <sys/types.h> /* basic types definition */ 37 #include <sys/time.h> /* timeval, time_t */ 38 #include <sys/socket.h> 39 #include <sys/uio.h> /* needed for reading/writing vectors */ 40 #include <sys/param.h> /* defines MAXHOSTNAMELEN and other stuff */ 41 #include <netinet/in.h> 42 #include <arpa/inet.h> /* inet_ntop(), inet_pton() */ 43 44 /* other misc unchecked includes */ 45 #if 0 46 #include <netinet/in_systm.h> /* misc crud that netinet/ip.h references */ 47 #include <netinet/ip.h> /* IPOPT_LSRR, header stuff */ 48 #endif 49 50 /* These are useful to keep the source readable */ 51 #ifndef STDIN_FILENO 52 # define STDIN_FILENO 0 53 #endif 54 #ifndef STDOUT_FILENO 55 # define STDOUT_FILENO 1 56 #endif 57 #ifndef STDERR_FILENO 58 # define STDERR_FILENO 2 59 #endif 60 #ifndef SHUT_RDWR 61 # define SHUT_RDWR 2 62 #endif 63 64 /* find a random routine */ 65 #if defined(HAVE_RANDOM) && defined(HAVE_SRANDOM) 66 # define USE_RANDOM /* try with most modern random routines */ 67 # define SRAND srandom 68 # define RAND random 69 #elif defined(HAVE_RAND) && defined(HAVE_SRAND) 70 # define USE_RANDOM /* otherwise fallback to the older rand() */ 71 # define SRAND srand 72 # define RAND rand 73 #endif /* if none of them are here, CHANGE OS! */ 74 75 /* This must be defined to the longest possible internet address length in 76 string notation. 77 Bugfix: Looks like Solaris 7 doesn't define this standard. It's ok to use 78 the following workaround since this is going to change to introduce IPv6 79 support. */ 80 #ifdef INET_ADDRSTRLEN 81 # define NETCAT_ADDRSTRLEN INET_ADDRSTRLEN 82 #else 83 # define NETCAT_ADDRSTRLEN 16 84 #endif 85 86 /* FIXME: I should search more about this portnames standards. At the moment 87 i'll fix my own size for this */ 88 #define NETCAT_MAXPORTNAMELEN 64 89 90 /* Find out whether we can use the RFC 2292 extensions on this machine 91 (I've found out only linux supporting this feature so far) */ 92 #ifdef HAVE_STRUCT_IN_PKTINFO 93 # if defined(SOL_IP) && defined(IP_PKTINFO) 94 # define USE_PKTINFO 95 # endif 96 #endif 97 98 /* MAXINETADDR defines the maximum number of host aliases that are saved after 99 a successfully hostname lookup. Please not that this value will also take 100 a significant role in the memory usage. Approximately one struct takes: 101 MAXINETADDRS * (NETCAT_ADDRSTRLEN + sizeof(struct in_addr)) */ 102 #define MAXINETADDRS 6 103 104 #ifndef INADDR_NONE 105 # define INADDR_NONE 0xffffffff 106 #endif 107 108 /* FIXME: shall we really change this define? probably not. */ 109 #ifdef MAXHOSTNAMELEN 110 # undef MAXHOSTNAMELEN /* might be too small on aix, so fix it */ 111 #endif 112 #define MAXHOSTNAMELEN 256 113 114 /* TRUE and FALSE values for logical type `bool' */ 115 #ifndef TRUE 116 # define TRUE 1 117 #endif 118 #ifndef FALSE 119 # define FALSE 0 120 #endif 121 122 /* this is just a logical type, but helps a lot */ 123 #ifndef __cplusplus 124 # ifndef bool 125 # define bool unsigned char 126 # endif 127 #endif 128 #define BOOL_TO_STR(__var__) (__var__ ? "TRUE" : "FALSE") 129 #define NULL_STR(__var__) (__var__ ? __var__ : "(null)") 130 131 /* there are some OS that still doesn't support POSIX standards */ 132 #ifndef HAVE_IN_PORT_T 133 typedef unsigned short in_port_t; 134 #endif 135 136 /* Netcat basic operating modes */ 137 138 typedef enum { 139 NETCAT_UNSPEC, 140 NETCAT_CONNECT, 141 NETCAT_LISTEN, 142 NETCAT_TUNNEL 143 } nc_mode_t; 144 145 /* Recognized protocols */ 146 147 typedef enum { 148 NETCAT_PROTO_UNSPEC, 149 NETCAT_PROTO_TCP, 150 NETCAT_PROTO_UDP 151 } nc_proto_t; 152 153 /* used for queues buffering and data tracking purposes. The `head' field is 154 a pointer to the begin of the buffer segment, while `pos' indicates the 155 actual position of the data stream. If `head' is NULL, it means that there 156 is no dynamically-allocated data in this buffer, *BUT* it MAY still contain 157 some local data segment (for example allocated inside the stack). 158 `len' indicates the length of the buffer starting from `pos'. */ 159 160 typedef struct { 161 unsigned char *head; 162 unsigned char *pos; 163 int len; 164 } nc_buffer_t; 165 166 /* this is the standard netcat hosts record. It contains an "authoritative" 167 `name' field, which may be empty, and a list of IP addresses in the network 168 notation and in the dotted string notation. */ 169 170 typedef struct { 171 char name[MAXHOSTNAMELEN]; /* dns name */ 172 char addrs[MAXINETADDRS][NETCAT_ADDRSTRLEN]; /* ascii-format IP addresses */ 173 struct in_addr iaddrs[MAXINETADDRS]; /* real addresses */ 174 } nc_host_t; 175 176 /* standard netcat port record. It contains the port `name', which may be 177 empty, and the port number both as number and as string. */ 178 179 typedef struct { 180 char name[NETCAT_MAXPORTNAMELEN]; /* canonical port name */ 181 char ascnum[8]; /* ascii port number */ 182 unsigned short num; /* port number */ 183 /* FIXME: this is just a test! */ 184 in_port_t netnum; /* port number in network byte order */ 185 } nc_port_t; 186 187 /* This is a more complex struct that holds socket records. [...] */ 188 189 typedef struct { 190 int fd, domain, timeout; 191 nc_proto_t proto; 192 nc_host_t local_host, host; 193 nc_port_t local_port, port; 194 nc_buffer_t sendq, recvq; 195 } nc_sock_t; 196 197 /* Netcat includes */ 198 199 #include "proto.h" 200 #include "intl.h" 201 #include "misc.h" 202 203 #endif /* !NETCAT_H */ 204