diff options
-rw-r--r-- | pcap-rpcap-int.h | 2 | ||||
-rw-r--r-- | pcap-rpcap.c | 88 | ||||
-rw-r--r-- | rpcap-protocol.c | 10 | ||||
-rw-r--r-- | rpcap-protocol.h | 137 | ||||
-rw-r--r-- | rpcapd/daemon.c | 106 |
5 files changed, 169 insertions, 174 deletions
diff --git a/pcap-rpcap-int.h b/pcap-rpcap-int.h index e707a85f..6b07d1fb 100644 --- a/pcap-rpcap-int.h +++ b/pcap-rpcap-int.h @@ -69,7 +69,7 @@ * Exported function prototypes * * * *********************************************************/ -void rpcap_createhdr(struct rpcap_header *header, uint8 type, uint16 value, uint32 length); +void rpcap_createhdr(struct rpcap_header *header, uint8_t type, uint16_t value, uint32_t length); int rpcap_senderror(SOCKET sock, char *error, unsigned short errcode, char *errbuf); #endif diff --git a/pcap-rpcap.c b/pcap-rpcap.c index 062f1107..6b1a1d1a 100644 --- a/pcap-rpcap.c +++ b/pcap-rpcap.c @@ -94,7 +94,7 @@ struct activehosts struct sockaddr_storage host; SOCKET sockctrl; SSL *ssl; - uint8 protocol_version; + uint8_t protocol_version; struct activehosts *next; }; @@ -128,8 +128,8 @@ struct pcap_rpcap { int rmt_capstarted; /* 'true' if the capture is already started (needed to knoe if we have to call the pcap_startcapture() */ char *currentfilter; /* Pointer to a buffer (allocated at run-time) that stores the current filter. Needed when flag PCAP_OPENFLAG_NOCAPTURE_RPCAP is turned on. */ - uint8 protocol_version; /* negotiated protocol version */ - uint8 uses_ssl; /* User asked for rpcaps scheme */ + uint8_t protocol_version; /* negotiated protocol version */ + uint8_t uses_ssl; /* User asked for rpcaps scheme */ unsigned int TotNetDrops; /* keeps the number of packets that have been dropped by the network */ @@ -170,12 +170,12 @@ static int pcap_setfilter_rpcap(pcap_t *fp, struct bpf_program *prog); static int pcap_setsampling_remote(pcap_t *fp); static int pcap_startcapture_remote(pcap_t *fp); static int rpcap_recv_msg_header(SOCKET sock, SSL *, struct rpcap_header *header, char *errbuf); -static int rpcap_check_msg_ver(SOCKET sock, SSL *, uint8 expected_ver, struct rpcap_header *header, char *errbuf); -static int rpcap_check_msg_type(SOCKET sock, SSL *, uint8 request_type, struct rpcap_header *header, uint16 *errcode, char *errbuf); -static int rpcap_process_msg_header(SOCKET sock, SSL *, uint8 ver, uint8 request_type, struct rpcap_header *header, char *errbuf); -static int rpcap_recv(SOCKET sock, SSL *, void *buffer, size_t toread, uint32 *plen, char *errbuf); -static void rpcap_msg_err(SOCKET sockctrl, SSL *, uint32 plen, char *remote_errbuf); -static int rpcap_discard(SOCKET sock, SSL *, uint32 len, char *errbuf); +static int rpcap_check_msg_ver(SOCKET sock, SSL *, uint8_t expected_ver, struct rpcap_header *header, char *errbuf); +static int rpcap_check_msg_type(SOCKET sock, SSL *, uint8_t request_type, struct rpcap_header *header, uint16_t *errcode, char *errbuf); +static int rpcap_process_msg_header(SOCKET sock, SSL *, uint8_t ver, uint8_t request_type, struct rpcap_header *header, char *errbuf); +static int rpcap_recv(SOCKET sock, SSL *, void *buffer, size_t toread, uint32_t *plen, char *errbuf); +static void rpcap_msg_err(SOCKET sockctrl, SSL *, uint32_t plen, char *remote_errbuf); +static int rpcap_discard(SOCKET sock, SSL *, uint32_t len, char *errbuf); static int rpcap_read_packet_msg(struct pcap_rpcap const *, pcap_t *p, size_t size); /**************************************************** @@ -388,7 +388,7 @@ static int pcap_read_nocb_remote(pcap_t *p, struct pcap_pkthdr *pkt_header, u_ch struct rpcap_header *header; /* general header according to the RPCAP format */ struct rpcap_pkthdr *net_pkt_header; /* header of the packet, from the message */ u_char *net_pkt_data; /* packet data from the message */ - uint32 plen; + uint32_t plen; int retval = 0; /* generic return value */ int msglen; @@ -903,7 +903,7 @@ static struct pcap_stat *rpcap_stats_rpcap(pcap_t *p, struct pcap_stat *ps, int struct pcap_rpcap *pr = p->priv; /* structure used when doing a remote live capture */ struct rpcap_header header; /* header of the RPCAP packet */ struct rpcap_stats netstats; /* statistics sent on the network */ - uint32 plen; /* data remaining in the message */ + uint32_t plen; /* data remaining in the message */ #ifdef _WIN32 if (mode != PCAP_STATS_STANDARD && mode != PCAP_STATS_EX) @@ -1076,8 +1076,8 @@ static int pcap_startcapture_remote(pcap_t *fp) struct pcap_rpcap *pr = fp->priv; /* structure used when doing a remote live capture */ char sendbuf[RPCAP_NETBUF_SIZE]; /* temporary buffer in which data to be sent is buffered */ int sendbufidx = 0; /* index which keeps the number of bytes currently buffered */ - uint16 portdata = 0; /* temp variable needed to keep the network port for the data connection */ - uint32 plen; + uint16_t portdata = 0; /* temp variable needed to keep the network port for the data connection */ + uint32_t plen; int active = 0; /* '1' if we're in active mode */ struct activehosts *temp; /* temp var needed to scan the host list chain, to detect if we're in active mode */ char host[INET6_ADDRSTRLEN + 1]; /* numeric name of the other host */ @@ -1101,7 +1101,7 @@ static int pcap_startcapture_remote(pcap_t *fp) int res; socklen_t itemp; int sockbufsize = 0; - uint32 server_sockbufsize; + uint32_t server_sockbufsize; // Take the opportunity to clear pr->data_ssl before any goto error, // as it seems p->priv is not zeroed after its malloced. @@ -1561,7 +1561,7 @@ static int pcap_pack_bpffilter(pcap_t *fp, char *sendbuf, int *sendbufidx, struc return -1; filter->filtertype = htons(RPCAP_UPDATEFILTER_BPF); - filter->nitems = htonl((int32)prog->bf_len); + filter->nitems = htonl((int32_t)prog->bf_len); if (sock_bufferize(NULL, prog->bf_len * sizeof(struct rpcap_filterbpf_insn), NULL, sendbufidx, RPCAP_NETBUF_SIZE, SOCKBUF_CHECKONLY, fp->errbuf, PCAP_ERRBUF_SIZE)) @@ -1884,8 +1884,8 @@ static int pcap_setsampling_remote(pcap_t *fp) memset(sampling_pars, 0, sizeof(struct rpcap_sampling)); - sampling_pars->method = (uint8)fp->rmt_samp.method; - sampling_pars->value = (uint16)htonl(fp->rmt_samp.value); + sampling_pars->method = (uint8_t)fp->rmt_samp.method; + sampling_pars->value = (uint16_t)htonl(fp->rmt_samp.value); if (sock_send(pr->rmt_sockctrl, pr->ctrl_ssl, sendbuf, sendbufidx, fp->errbuf, PCAP_ERRBUF_SIZE) < 0) @@ -1943,18 +1943,18 @@ static int pcap_setsampling_remote(pcap_t *fp) * \return '0' if everything is fine, '-1' for an error. For errors, * an error message string is returned in the 'errbuf' variable. */ -static int rpcap_doauth(SOCKET sockctrl, SSL *ssl, uint8 *ver, struct pcap_rmtauth *auth, char *errbuf) +static int rpcap_doauth(SOCKET sockctrl, SSL *ssl, uint8_t *ver, struct pcap_rmtauth *auth, char *errbuf) { char sendbuf[RPCAP_NETBUF_SIZE]; /* temporary buffer in which data that has to be sent is buffered */ int sendbufidx = 0; /* index which keeps the number of bytes currently buffered */ - uint16 length; /* length of the payload of this message */ + uint16_t length; /* length of the payload of this message */ struct rpcap_auth *rpauth; - uint16 auth_type; + uint16_t auth_type; struct rpcap_header header; size_t str_length; - uint32 plen; + uint32_t plen; struct rpcap_authreply authreply; /* authentication reply message */ - uint8 ourvers; + uint8_t ourvers; if (auth) { @@ -1974,7 +1974,7 @@ static int rpcap_doauth(SOCKET sockctrl, SSL *ssl, uint8 *ver, struct pcap_rmtau snprintf(errbuf, PCAP_ERRBUF_SIZE, "User name is too long (> 65535 bytes)"); return -1; } - length += (uint16)str_length; + length += (uint16_t)str_length; } if (auth->password) { @@ -1984,7 +1984,7 @@ static int rpcap_doauth(SOCKET sockctrl, SSL *ssl, uint8 *ver, struct pcap_rmtau snprintf(errbuf, PCAP_ERRBUF_SIZE, "Password is too long (> 65535 bytes)"); return -1; } - length += (uint16)str_length; + length += (uint16_t)str_length; } break; @@ -1993,7 +1993,7 @@ static int rpcap_doauth(SOCKET sockctrl, SSL *ssl, uint8 *ver, struct pcap_rmtau return -1; } - auth_type = (uint16)auth->type; + auth_type = (uint16_t)auth->type; } else { @@ -2021,7 +2021,7 @@ static int rpcap_doauth(SOCKET sockctrl, SSL *ssl, uint8 *ver, struct pcap_rmtau if (auth_type == RPCAP_RMTAUTH_PWD) { if (auth->username) - rpauth->slen1 = (uint16)strlen(auth->username); + rpauth->slen1 = (uint16_t)strlen(auth->username); else rpauth->slen1 = 0; @@ -2030,7 +2030,7 @@ static int rpcap_doauth(SOCKET sockctrl, SSL *ssl, uint8 *ver, struct pcap_rmtau return -1; if (auth->password) - rpauth->slen2 = (uint16)strlen(auth->password); + rpauth->slen2 = (uint16_t)strlen(auth->password); else rpauth->slen2 = 0; @@ -2150,7 +2150,7 @@ static const char userinfo_allowed_symbols[] = "-._~!&'()*+,;="; * struct created from a username and password parsed out of the userinfo * portion of a URI. */ -static int rpcap_doauth_userinfo(SOCKET sockctrl, SSL *ssl, uint8 *ver, const char *userinfo, char *errbuf) +static int rpcap_doauth_userinfo(SOCKET sockctrl, SSL *ssl, uint8_t *ver, const char *userinfo, char *errbuf) { struct pcap_rmtauth auth; const char *ptr; @@ -2234,8 +2234,8 @@ pcap_setnonblock_rpcap(pcap_t *p, int nonblock _U_) static int rpcap_setup_session(const char *source, struct pcap_rmtauth *auth, - int *activep, SOCKET *sockctrlp, uint8 *uses_sslp, SSL **sslp, - int rmt_flags, uint8 *protocol_versionp, char *host, char *port, + int *activep, SOCKET *sockctrlp, uint8_t *uses_sslp, SSL **sslp, + int rmt_flags, uint8_t *protocol_versionp, char *host, char *port, char *iface, char *errbuf) { int type; @@ -2431,9 +2431,9 @@ pcap_t *pcap_open_rpcap(const char *source, int snaplen, int flags, int read_tim char host[PCAP_BUF_SIZE], ctrlport[PCAP_BUF_SIZE], iface[PCAP_BUF_SIZE]; SOCKET sockctrl; SSL *ssl = NULL; - uint8 protocol_version; /* negotiated protocol version */ + uint8_t protocol_version; /* negotiated protocol version */ int active; - uint32 plen; + uint32_t plen; char sendbuf[RPCAP_NETBUF_SIZE]; /* temporary buffer in which data to be sent is buffered */ int sendbufidx = 0; /* index which keeps the number of bytes currently buffered */ @@ -2497,7 +2497,7 @@ pcap_t *pcap_open_rpcap(const char *source, int snaplen, int flags, int read_tim goto error_nodiscard; rpcap_createhdr((struct rpcap_header *) sendbuf, protocol_version, - RPCAP_MSG_OPEN_REQ, 0, (uint32) strlen(iface)); + RPCAP_MSG_OPEN_REQ, 0, (uint32_t) strlen(iface)); if (sock_bufferize(iface, (int) strlen(iface), sendbuf, &sendbufidx, RPCAP_NETBUF_SIZE, SOCKBUF_BUFFERIZE, errbuf, PCAP_ERRBUF_SIZE)) @@ -2597,15 +2597,15 @@ freeaddr(struct pcap_addr *addr) int pcap_findalldevs_ex_remote(const char *source, struct pcap_rmtauth *auth, pcap_if_t **alldevs, char *errbuf) { - uint8 protocol_version; /* protocol version */ + uint8_t protocol_version; /* protocol version */ SOCKET sockctrl; /* socket descriptor of the control connection */ SSL *ssl = NULL; /* optional SSL handler for sockctrl */ - uint32 plen; + uint32_t plen; struct rpcap_header header; /* structure that keeps the general header of the rpcap protocol */ int i, j; /* temp variables */ int nif; /* Number of interfaces listed */ int active; /* 'true' if we the other end-party is in active mode */ - uint8 uses_ssl; + uint8_t uses_ssl; char host[PCAP_BUF_SIZE], port[PCAP_BUF_SIZE]; char tmpstring[PCAP_BUF_SIZE + 1]; /* Needed to convert names and descriptions from 'old' syntax to the 'new' one */ pcap_if_t *lastdev; /* Last device in the pcap_if_t list */ @@ -2910,7 +2910,7 @@ SOCKET pcap_remoteact_accept_ex(const char *address, const char *port, const cha socklen_t fromlen; /* keeps the length of the sockaddr_storage variable */ SOCKET sockctrl; /* keeps the main socket identifier */ SSL *ssl = NULL; /* Optional SSL handler for sockctrl */ - uint8 protocol_version; /* negotiated protocol version */ + uint8_t protocol_version; /* negotiated protocol version */ struct activehosts *temp, *prev; /* temp var needed to scan he host list chain */ *connectinghost = 0; /* just in case */ @@ -3299,7 +3299,7 @@ static int rpcap_recv_msg_header(SOCKET sock, SSL *ssl, struct rpcap_header *hea * Make sure the protocol version of a received message is what we were * expecting. */ -static int rpcap_check_msg_ver(SOCKET sock, SSL *ssl, uint8 expected_ver, struct rpcap_header *header, char *errbuf) +static int rpcap_check_msg_ver(SOCKET sock, SSL *ssl, uint8_t expected_ver, struct rpcap_header *header, char *errbuf) { /* * Did the server specify the version we negotiated? @@ -3330,7 +3330,7 @@ static int rpcap_check_msg_ver(SOCKET sock, SSL *ssl, uint8 expected_ver, struct * Check the message type of a received message, which should either be * the expected message type or RPCAP_MSG_ERROR. */ -static int rpcap_check_msg_type(SOCKET sock, SSL *ssl, uint8 request_type, struct rpcap_header *header, uint16 *errcode, char *errbuf) +static int rpcap_check_msg_type(SOCKET sock, SSL *ssl, uint8_t request_type, struct rpcap_header *header, uint16_t *errcode, char *errbuf) { const char *request_type_string; const char *msg_type_string; @@ -3400,9 +3400,9 @@ static int rpcap_check_msg_type(SOCKET sock, SSL *ssl, uint8 request_type, struc /* * Receive and process the header of a message. */ -static int rpcap_process_msg_header(SOCKET sock, SSL *ssl, uint8 expected_ver, uint8 request_type, struct rpcap_header *header, char *errbuf) +static int rpcap_process_msg_header(SOCKET sock, SSL *ssl, uint8_t expected_ver, uint8_t request_type, struct rpcap_header *header, char *errbuf) { - uint16 errcode; + uint16_t errcode; if (rpcap_recv_msg_header(sock, ssl, header, errbuf) == -1) { @@ -3432,7 +3432,7 @@ static int rpcap_process_msg_header(SOCKET sock, SSL *ssl, uint8 expected_ver, u * Returns 0 on success, logs a message and returns -1 on a network * error. */ -static int rpcap_recv(SOCKET sock, SSL *ssl, void *buffer, size_t toread, uint32 *plen, char *errbuf) +static int rpcap_recv(SOCKET sock, SSL *ssl, void *buffer, size_t toread, uint32_t *plen, char *errbuf) { int nread; @@ -3455,7 +3455,7 @@ static int rpcap_recv(SOCKET sock, SSL *ssl, void *buffer, size_t toread, uint32 /* * This handles the RPCAP_MSG_ERROR message. */ -static void rpcap_msg_err(SOCKET sockctrl, SSL *ssl, uint32 plen, char *remote_errbuf) +static void rpcap_msg_err(SOCKET sockctrl, SSL *ssl, uint32_t plen, char *remote_errbuf) { char errbuf[PCAP_ERRBUF_SIZE]; @@ -3526,7 +3526,7 @@ static void rpcap_msg_err(SOCKET sockctrl, SSL *ssl, uint32 plen, char *remote_e * Returns 0 on success, logs a message and returns -1 on a network * error. */ -static int rpcap_discard(SOCKET sock, SSL *ssl, uint32 len, char *errbuf) +static int rpcap_discard(SOCKET sock, SSL *ssl, uint32_t len, char *errbuf) { if (len != 0) { diff --git a/rpcap-protocol.c b/rpcap-protocol.c index 0cdc0ba3..210038f3 100644 --- a/rpcap-protocol.c +++ b/rpcap-protocol.c @@ -80,13 +80,13 @@ * error message is returned in the 'errbuf' variable. */ int -rpcap_senderror(SOCKET sock, SSL *ssl, uint8 ver, unsigned short errcode, const char *error, char *errbuf) +rpcap_senderror(SOCKET sock, SSL *ssl, uint8_t ver, unsigned short errcode, const char *error, char *errbuf) { char sendbuf[RPCAP_NETBUF_SIZE]; /* temporary buffer in which data to be sent is buffered */ int sendbufidx = 0; /* index which keeps the number of bytes currently buffered */ - uint16 length; + uint16_t length; - length = (uint16)strlen(error); + length = (uint16_t)strlen(error); if (length > PCAP_ERRBUF_SIZE) length = PCAP_ERRBUF_SIZE; @@ -134,7 +134,7 @@ rpcap_senderror(SOCKET sock, SSL *ssl, uint8 ver, unsigned short errcode, const * variable. */ void -rpcap_createhdr(struct rpcap_header *header, uint8 ver, uint8 type, uint16 value, uint32 length) +rpcap_createhdr(struct rpcap_header *header, uint8_t ver, uint8_t type, uint16_t value, uint32_t length) { memset(header, 0, sizeof(struct rpcap_header)); @@ -182,7 +182,7 @@ static const char *replies[] = #define NUM_REPLY_TYPES (sizeof replies / sizeof replies[0]) const char * -rpcap_msg_type_string(uint8 type) +rpcap_msg_type_string(uint8_t type) { if (type & RPCAP_MSG_IS_REPLY) { type &= ~RPCAP_MSG_IS_REPLY; diff --git a/rpcap-protocol.h b/rpcap-protocol.h index 88d5133a..de8c757e 100644 --- a/rpcap-protocol.h +++ b/rpcap-protocol.h @@ -123,29 +123,24 @@ * of the structure should be provided for all the different versions or * version ranges (if more than one version of the protocol has the same * layout) that we support. - */ - -/* - * WARNING: These typedefs MUST be of a specific size. - * You might have to change them on your platform. * - * XXX - use the C99 types? Microsoft's newer versions of Visual Studio - * support them. + * We use the C99 intN_t and uintN_t types to indicat fields that are + * exactly N bits long on the network. Do not use types that might + * differ in their lengths. + * + * XXX - both libpcap and programs that use it will require significant + * work if you have machines where integral data types are not multiples + * of 8-bit bytes. If, for example, you're trying to get this to work + * on a PDP-10x, good luck. */ -#ifndef __HAIKU__ -typedef unsigned char uint8; /* 8-bit unsigned integer */ -typedef unsigned short uint16; /* 16-bit unsigned integer */ -typedef unsigned int uint32; /* 32-bit unsigned integer */ -typedef int int32; /* 32-bit signed integer */ -#endif /* Common header for all the RPCAP messages */ struct rpcap_header { - uint8 ver; /* RPCAP version number */ - uint8 type; /* RPCAP message type (error, findalldevs, ...) */ - uint16 value; /* Message-dependent value (not always used) */ - uint32 plen; /* Length of the payload of this RPCAP message */ + uint8_t ver; /* RPCAP version number */ + uint8_t type; /* RPCAP message type (error, findalldevs, ...) */ + uint16_t value; /* Message-dependent value (not always used) */ + uint32_t plen; /* Length of the payload of this RPCAP message */ }; /* @@ -157,18 +152,18 @@ struct rpcap_header */ struct rpcap_authreply { - uint8 minvers; /* Minimum version supported */ - uint8 maxvers; /* Maximum version supported */ + uint8_t minvers; /* Minimum version supported */ + uint8_t maxvers; /* Maximum version supported */ }; /* Format of the message for the interface description (findalldevs command) */ struct rpcap_findalldevs_if { - uint16 namelen; /* Length of the interface name */ - uint16 desclen; /* Length of the interface description */ - uint32 flags; /* Interface flags */ - uint16 naddr; /* Number of addresses */ - uint16 dummy; /* Must be zero */ + uint16_t namelen; /* Length of the interface name */ + uint16_t desclen; /* Length of the interface description */ + uint32_t flags; /* Interface flags */ + uint16_t naddr; /* Number of addresses */ + uint16_t dummy; /* Must be zero */ }; /* @@ -215,8 +210,8 @@ struct rpcap_findalldevs_if */ struct rpcap_sockaddr { - uint16 family; /* Address family */ - char data[128-2]; /* Data */ + uint16_t family; /* Address family */ + char data[128-2]; /* Data */ }; /* @@ -225,10 +220,10 @@ struct rpcap_sockaddr #define RPCAP_AF_INET 2 /* Value on all OSes */ struct rpcap_sockaddr_in { - uint16 family; /* Address family */ - uint16 port; /* Port number */ - uint32 addr; /* IPv4 address */ - uint8 zero[8]; /* Padding */ + uint16_t family; /* Address family */ + uint16_t port; /* Port number */ + uint32_t addr; /* IPv4 address */ + uint8_t zero[8]; /* Padding */ }; /* @@ -237,11 +232,11 @@ struct rpcap_sockaddr_in #define RPCAP_AF_INET6 23 /* Value on Windows */ struct rpcap_sockaddr_in6 { - uint16 family; /* Address family */ - uint16 port; /* Port number */ - uint32 flowinfo; /* IPv6 flow information */ - uint8 addr[16]; /* IPv6 address */ - uint32 scope_id; /* Scope zone index */ + uint16_t family; /* Address family */ + uint16_t port; /* Port number */ + uint32_t flowinfo; /* IPv6 flow information */ + uint8_t addr[16]; /* IPv6 address */ + uint32_t scope_id; /* Scope zone index */ }; /* Format of the message for the address listing (findalldevs command) */ @@ -260,25 +255,25 @@ struct rpcap_findalldevs_ifaddr */ struct rpcap_openreply { - int32 linktype; /* Link type */ - int32 tzoff; /* Timezone offset - not used by newer clients */ + int32_t linktype; /* Link type */ + int32_t tzoff; /* Timezone offset - not used by newer clients */ }; /* Format of the message that starts a remote capture (startcap command) */ struct rpcap_startcapreq { - uint32 snaplen; /* Length of the snapshot (number of bytes to capture for each packet) */ - uint32 read_timeout; /* Read timeout in milliseconds */ - uint16 flags; /* Flags (see RPCAP_STARTCAPREQ_FLAG_xxx) */ - uint16 portdata; /* Network port on which the client is waiting at (if 'serveropen') */ + uint32_t snaplen; /* Length of the snapshot (number of bytes to capture for each packet) */ + uint32_t read_timeout; /* Read timeout in milliseconds */ + uint16_t flags; /* Flags (see RPCAP_STARTCAPREQ_FLAG_xxx) */ + uint16_t portdata; /* Network port on which the client is waiting at (if 'serveropen') */ }; /* Format of the reply message that devoted to start a remote capture (startcap reply command) */ struct rpcap_startcapreply { - int32 bufsize; /* Size of the user buffer allocated by WinPcap; it can be different from the one we chose */ - uint16 portdata; /* Network port on which the server is waiting at (passive mode only) */ - uint16 dummy; /* Must be zero */ + int32_t bufsize; /* Size of the user buffer allocated by WinPcap; it can be different from the one we chose */ + uint16_t portdata; /* Network port on which the server is waiting at (passive mode only) */ + uint16_t dummy; /* Must be zero */ }; /* @@ -293,55 +288,55 @@ struct rpcap_pkthdr * This protocol needs to be updated with a new version before * 2038-01-19 03:14:07 UTC. */ - uint32 timestamp_sec; /* 'struct timeval' compatible, it represents the 'tv_sec' field */ - uint32 timestamp_usec; /* 'struct timeval' compatible, it represents the 'tv_usec' field */ - uint32 caplen; /* Length of portion present in the capture */ - uint32 len; /* Real length of this packet (off wire) */ - uint32 npkt; /* Ordinal number of the packet (i.e. the first one captured has '1', the second one '2', etc) */ + uint32_t timestamp_sec; /* 'struct timeval' compatible, it represents the 'tv_sec' field */ + uint32_t timestamp_usec; /* 'struct timeval' compatible, it represents the 'tv_usec' field */ + uint32_t caplen; /* Length of portion present in the capture */ + uint32_t len; /* Real length of this packet (off wire) */ + uint32_t npkt; /* Ordinal number of the packet (i.e. the first one captured has '1', the second one '2', etc) */ }; /* General header used for the pcap_setfilter() command; keeps just the number of BPF instructions */ struct rpcap_filter { - uint16 filtertype; /* type of the filter transferred (BPF instructions, ...) */ - uint16 dummy; /* Must be zero */ - uint32 nitems; /* Number of items contained into the filter (e.g. BPF instructions for BPF filters) */ + uint16_t filtertype; /* type of the filter transferred (BPF instructions, ...) */ + uint16_t dummy; /* Must be zero */ + uint32_t nitems; /* Number of items contained into the filter (e.g. BPF instructions for BPF filters) */ }; /* Structure that keeps a single BPF instruction; it is repeated 'ninsn' times according to the 'rpcap_filterbpf' header */ struct rpcap_filterbpf_insn { - uint16 code; /* opcode of the instruction */ - uint8 jt; /* relative offset to jump to in case of 'true' */ - uint8 jf; /* relative offset to jump to in case of 'false' */ - int32 k; /* instruction-dependent value */ + uint16_t code; /* opcode of the instruction */ + uint8_t jt; /* relative offset to jump to in case of 'true' */ + uint8_t jf; /* relative offset to jump to in case of 'false' */ + int32_t k; /* instruction-dependent value */ }; /* Structure that keeps the data required for the authentication on the remote host */ struct rpcap_auth { - uint16 type; /* Authentication type */ - uint16 dummy; /* Must be zero */ - uint16 slen1; /* Length of the first authentication item (e.g. username) */ - uint16 slen2; /* Length of the second authentication item (e.g. password) */ + uint16_t type; /* Authentication type */ + uint16_t dummy; /* Must be zero */ + uint16_t slen1; /* Length of the first authentication item (e.g. username) */ + uint16_t slen2; /* Length of the second authentication item (e.g. password) */ }; /* Structure that keeps the statistics about the number of packets captured, dropped, etc. */ struct rpcap_stats { - uint32 ifrecv; /* Packets received by the kernel filter (i.e. pcap_stats.ps_recv) */ - uint32 ifdrop; /* Packets dropped by the network interface (e.g. not enough buffers) (i.e. pcap_stats.ps_ifdrop) */ - uint32 krnldrop; /* Packets dropped by the kernel filter (i.e. pcap_stats.ps_drop) */ - uint32 svrcapt; /* Packets captured by the RPCAP daemon and sent on the network */ + uint32_t ifrecv; /* Packets received by the kernel filter (i.e. pcap_stats.ps_recv) */ + uint32_t ifdrop; /* Packets dropped by the network interface (e.g. not enough buffers) (i.e. pcap_stats.ps_ifdrop) */ + uint32_t krnldrop; /* Packets dropped by the kernel filter (i.e. pcap_stats.ps_drop) */ + uint32_t svrcapt; /* Packets captured by the RPCAP daemon and sent on the network */ }; /* Structure that is needed to set sampling parameters */ struct rpcap_sampling { - uint8 method; /* Sampling method */ - uint8 dummy1; /* Must be zero */ - uint16 dummy2; /* Must be zero */ - uint32 value; /* Parameter related to the sampling method */ + uint8_t method; /* Sampling method */ + uint8_t dummy1; /* Must be zero */ + uint16_t dummy2; /* Must be zero */ + uint32_t value; /* Parameter related to the sampling method */ }; /* @@ -423,8 +418,8 @@ struct rpcap_sampling #include "sockutils.h" #include "sslutils.h" -extern void rpcap_createhdr(struct rpcap_header *header, uint8 ver, uint8 type, uint16 value, uint32 length); -extern const char *rpcap_msg_type_string(uint8 type); -extern int rpcap_senderror(SOCKET sock, SSL *ssl, uint8 ver, uint16 errcode, const char *error, char *errbuf); +extern void rpcap_createhdr(struct rpcap_header *header, uint8_t ver, uint8_t type, uint16_t value, uint32_t length); +extern const char *rpcap_msg_type_string(uint8_t type); +extern int rpcap_senderror(SOCKET sock, SSL *ssl, uint8_t ver, uint16_t errcode, const char *error, char *errbuf); #endif diff --git a/rpcapd/daemon.c b/rpcapd/daemon.c index 362f4b9b..d835abab 100644 --- a/rpcapd/daemon.c +++ b/rpcapd/daemon.c @@ -113,7 +113,7 @@ struct session { SOCKET sockctrl; SOCKET sockdata; SSL *ctrl_ssl, *data_ssl; // optional SSL handlers for sockctrl and sockdata. - uint8 protocol_version; + uint8_t protocol_version; pcap_t *fp; unsigned int TotCapt; int have_thread; @@ -125,31 +125,31 @@ struct session { }; // Locally defined functions -static int daemon_msg_err(SOCKET sockctrl, SSL *, uint32 plen); -static int daemon_msg_auth_req(struct daemon_slpars *pars, uint32 plen); +static int daemon_msg_err(SOCKET sockctrl, SSL *, uint32_t plen); +static int daemon_msg_auth_req(struct daemon_slpars *pars, uint32_t plen); static int daemon_AuthUserPwd(char *username, char *password, char *errbuf); -static int daemon_msg_findallif_req(uint8 ver, struct daemon_slpars *pars, - uint32 plen); +static int daemon_msg_findallif_req(uint8_t ver, struct daemon_slpars *pars, + uint32_t plen); -static int daemon_msg_open_req(uint8 ver, struct daemon_slpars *pars, - uint32 plen, char *source, size_t sourcelen); -static int daemon_msg_startcap_req(uint8 ver, struct daemon_slpars *pars, - uint32 plen, char *source, struct session **sessionp, +static int daemon_msg_open_req(uint8_t ver, struct daemon_slpars *pars, + uint32_t plen, char *source, size_t sourcelen); +static int daemon_msg_startcap_req(uint8_t ver, struct daemon_slpars *pars, + uint32_t plen, char *source, struct session **sessionp, struct rpcap_sampling *samp_param, int uses_ssl); -static int daemon_msg_endcap_req(uint8 ver, struct daemon_slpars *pars, +static int daemon_msg_endcap_req(uint8_t ver, struct daemon_slpars *pars, struct session *session); -static int daemon_msg_updatefilter_req(uint8 ver, struct daemon_slpars *pars, - struct session *session, uint32 plen); -static int daemon_unpackapplyfilter(SOCKET sockctrl, SSL *, struct session *session, uint32 *plenp, char *errbuf); +static int daemon_msg_updatefilter_req(uint8_t ver, struct daemon_slpars *pars, + struct session *session, uint32_t plen); +static int daemon_unpackapplyfilter(SOCKET sockctrl, SSL *, struct session *session, uint32_t *plenp, char *errbuf); -static int daemon_msg_stats_req(uint8 ver, struct daemon_slpars *pars, - struct session *session, uint32 plen, struct pcap_stat *stats, +static int daemon_msg_stats_req(uint8_t ver, struct daemon_slpars *pars, + struct session *session, uint32_t plen, struct pcap_stat *stats, unsigned int svrcapt); -static int daemon_msg_setsampling_req(uint8 ver, struct daemon_slpars *pars, - uint32 plen, struct rpcap_sampling *samp_param); +static int daemon_msg_setsampling_req(uint8_t ver, struct daemon_slpars *pars, + uint32_t plen, struct rpcap_sampling *samp_param); static void daemon_seraddr(struct sockaddr_storage *sockaddrin, struct rpcap_sockaddr *sockaddrout); #ifdef _WIN32 @@ -160,8 +160,8 @@ static void noop_handler(int sign); #endif static int rpcapd_recv_msg_header(SOCKET sock, SSL *, struct rpcap_header *headerp); -static int rpcapd_recv(SOCKET sock, SSL *, char *buffer, size_t toread, uint32 *plen, char *errmsgbuf); -static int rpcapd_discard(SOCKET sock, SSL *, uint32 len); +static int rpcapd_recv(SOCKET sock, SSL *, char *buffer, size_t toread, uint32_t *plen, char *errmsgbuf); +static int rpcapd_discard(SOCKET sock, SSL *, uint32_t len); static void session_close(struct session *); // @@ -169,14 +169,14 @@ static void session_close(struct session *); // the client, in case we aren't doing TLS but they are. // struct tls_record_header { - uint8 type; // ContentType - will be 22, for Handshake - uint8 version_major; // TLS protocol major version - uint8 version_injor; // TLS protocol minor version + uint8_t type; // ContentType - will be 22, for Handshake + uint8_t version_major; // TLS protocol major version + uint8_t version_injor; // TLS protocol minor version // This is *not* aligned on a 2-byte boundary; we just // declare it as two bytes. Don't assume any particular // compiler's mechanism for saying "packed"! - uint8 length_hi; // Upper 8 bits of payload length - uint8 length_lo; // Low 8 bits of payload length + uint8_t length_hi; // Upper 8 bits of payload length + uint8_t length_lo; // Low 8 bits of payload length }; #define TLS_RECORD_HEADER_LEN 5 // Don't use sizeof in case it's padded @@ -188,8 +188,8 @@ struct tls_record_header { // TLS alert message. // struct tls_alert { - uint8 alert_level; - uint8 alert_description; + uint8_t alert_level; + uint8_t alert_description; }; #define TLS_ALERT_LEN 2 @@ -214,7 +214,7 @@ int daemon_serviceloop(SOCKET sockctrl, int isactive, char *passiveClients, int nullAuthAllowed, int uses_ssl) { - uint8 first_octet; + uint8_t first_octet; struct tls_record_header tls_header; struct tls_alert tls_alert; struct daemon_slpars pars; // service loop parameters @@ -224,7 +224,7 @@ daemon_serviceloop(SOCKET sockctrl, int isactive, char *passiveClients, SSL *ssl = NULL; int nrecv; struct rpcap_header header; // RPCAP message general header - uint32 plen; // payload length from header + uint32_t plen; // payload length from header int authenticated = 0; // 1 if the client has successfully authenticated char source[PCAP_BUF_SIZE+1]; // keeps the string that contains the interface to open int got_source = 0; // 1 if we've gotten the source from an open request @@ -1135,7 +1135,7 @@ end: * This handles the RPCAP_MSG_ERR message. */ static int -daemon_msg_err(SOCKET sockctrl, SSL *ssl, uint32 plen) +daemon_msg_err(SOCKET sockctrl, SSL *ssl, uint32_t plen) { char errbuf[PCAP_ERRBUF_SIZE]; char remote_errbuf[PCAP_ERRBUF_SIZE]; @@ -1214,7 +1214,7 @@ daemon_msg_err(SOCKET sockctrl, SSL *ssl, uint32 plen) * unrecoverable error or for the authentication failure. */ static int -daemon_msg_auth_req(struct daemon_slpars *pars, uint32 plen) +daemon_msg_auth_req(struct daemon_slpars *pars, uint32_t plen) { char errbuf[PCAP_ERRBUF_SIZE]; // buffer for network errors char errmsgbuf[PCAP_ERRBUF_SIZE]; // buffer for errors to send to the client @@ -1258,7 +1258,7 @@ daemon_msg_auth_req(struct daemon_slpars *pars, uint32 plen) case RPCAP_RMTAUTH_PWD: { char *username, *passwd; - uint32 usernamelen, passwdlen; + uint32_t usernamelen, passwdlen; usernamelen = ntohs(auth.slen1); username = (char *) malloc (usernamelen + 1); @@ -1590,10 +1590,10 @@ daemon_AuthUserPwd(char *username, char *password, char *errbuf) sizeof (errmsgbuf)); \ goto error; \ } \ - replylen += (uint32)(itemlen) + replylen += (uint32_t)(itemlen) static int -daemon_msg_findallif_req(uint8 ver, struct daemon_slpars *pars, uint32 plen) +daemon_msg_findallif_req(uint8_t ver, struct daemon_slpars *pars, uint32_t plen) { char errbuf[PCAP_ERRBUF_SIZE]; // buffer for network errors char errmsgbuf[PCAP_ERRBUF_SIZE]; // buffer for errors to send to the client @@ -1602,8 +1602,8 @@ daemon_msg_findallif_req(uint8 ver, struct daemon_slpars *pars, uint32 plen) pcap_if_t *alldevs = NULL; // pointer to the header of the interface chain pcap_if_t *d; // temp pointer needed to scan the interface chain struct pcap_addr *address; // pcap structure that keeps a network address of an interface - uint32 replylen; // length of reply payload - uint16 nif = 0; // counts the number of interface listed + uint32_t replylen; // length of reply payload + uint16_t nif = 0; // counts the number of interface listed // Discard the rest of the message; there shouldn't be any payload. if (rpcapd_discard(pars->sockctrl, pars->ssl, plen) == -1) @@ -1700,7 +1700,7 @@ daemon_msg_findallif_req(uint8 ver, struct daemon_slpars *pars, uint32 plen) // send the interface list for (d = alldevs; d != NULL; d = d->next) { - uint16 lname, ldescr; + uint16_t lname, ldescr; // Note: the findalldevs_if entries are *not* neatly // aligned on 4-byte boundaries, because they're @@ -1719,11 +1719,11 @@ daemon_msg_findallif_req(uint8 ver, struct daemon_slpars *pars, uint32 plen) * fit in 16 bits. */ if (d->description) - ldescr = (uint16) strlen(d->description); + ldescr = (uint16_t) strlen(d->description); else ldescr = 0; if (d->name) - lname = (uint16) strlen(d->name); + lname = (uint16_t) strlen(d->name); else lname = 0; @@ -1843,7 +1843,7 @@ error: to discard excess data in the message, if present) */ static int -daemon_msg_open_req(uint8 ver, struct daemon_slpars *pars, uint32 plen, +daemon_msg_open_req(uint8_t ver, struct daemon_slpars *pars, uint32_t plen, char *source, size_t sourcelen) { char errbuf[PCAP_ERRBUF_SIZE]; // buffer for network errors @@ -1945,7 +1945,7 @@ error: to discard excess data in the message, if present) */ static int -daemon_msg_startcap_req(uint8 ver, struct daemon_slpars *pars, uint32 plen, +daemon_msg_startcap_req(uint8_t ver, struct daemon_slpars *pars, uint32_t plen, char *source, struct session **sessionp, struct rpcap_sampling *samp_param _U_, int uses_ssl) { @@ -2278,7 +2278,7 @@ fatal_error: } static int -daemon_msg_endcap_req(uint8 ver, struct daemon_slpars *pars, +daemon_msg_endcap_req(uint8_t ver, struct daemon_slpars *pars, struct session *session) { char errbuf[PCAP_ERRBUF_SIZE]; // buffer for network errors @@ -2316,7 +2316,7 @@ daemon_msg_endcap_req(uint8 ver, struct daemon_slpars *pars, #define RPCAP_BPF_MAXINSNS 8192 static int -daemon_unpackapplyfilter(SOCKET sockctrl, SSL *ctrl_ssl, struct session *session, uint32 *plenp, char *errmsgbuf) +daemon_unpackapplyfilter(SOCKET sockctrl, SSL *ctrl_ssl, struct session *session, uint32_t *plenp, char *errmsgbuf) { int status; struct rpcap_filter filter; @@ -2401,8 +2401,8 @@ daemon_unpackapplyfilter(SOCKET sockctrl, SSL *ctrl_ssl, struct session *session } static int -daemon_msg_updatefilter_req(uint8 ver, struct daemon_slpars *pars, - struct session *session, uint32 plen) +daemon_msg_updatefilter_req(uint8_t ver, struct daemon_slpars *pars, + struct session *session, uint32_t plen) { char errbuf[PCAP_ERRBUF_SIZE]; char errmsgbuf[PCAP_ERRBUF_SIZE]; // buffer for errors to send to the client @@ -2455,7 +2455,7 @@ error: \brief Received the sampling parameters from remote host and it stores in the pcap_t structure. */ static int -daemon_msg_setsampling_req(uint8 ver, struct daemon_slpars *pars, uint32 plen, +daemon_msg_setsampling_req(uint8_t ver, struct daemon_slpars *pars, uint32_t plen, struct rpcap_sampling *samp_param) { char errbuf[PCAP_ERRBUF_SIZE]; // buffer for network errors @@ -2514,8 +2514,8 @@ error: } static int -daemon_msg_stats_req(uint8 ver, struct daemon_slpars *pars, - struct session *session, uint32 plen, struct pcap_stat *stats, +daemon_msg_stats_req(uint8_t ver, struct daemon_slpars *pars, + struct session *session, uint32_t plen, struct pcap_stat *stats, unsigned int svrcapt) { char errbuf[PCAP_ERRBUF_SIZE]; // buffer for network errors @@ -2536,7 +2536,7 @@ daemon_msg_stats_req(uint8 ver, struct daemon_slpars *pars, goto error; rpcap_createhdr((struct rpcap_header *) sendbuf, ver, - RPCAP_MSG_STATS_REPLY, 0, (uint16) sizeof(struct rpcap_stats)); + RPCAP_MSG_STATS_REPLY, 0, (uint16_t) sizeof(struct rpcap_stats)); netstats = (struct rpcap_stats *) &sendbuf[sendbufidx]; @@ -2709,7 +2709,7 @@ daemon_thrdatamain(void *ptr) rpcap_createhdr((struct rpcap_header *) sendbuf, session->protocol_version, RPCAP_MSG_PACKET, 0, - (uint16) (sizeof(struct rpcap_pkthdr) + pkt_header->caplen)); + (uint16_t) (sizeof(struct rpcap_pkthdr) + pkt_header->caplen)); net_pkt_header = (struct rpcap_pkthdr *) &sendbuf[sendbufidx]; @@ -2731,8 +2731,8 @@ daemon_thrdatamain(void *ptr) // This protocol needs to be updated with a new version // before 2038-01-19 03:14:07 UTC. // - net_pkt_header->timestamp_sec = htonl((uint32)pkt_header->ts.tv_sec); - net_pkt_header->timestamp_usec = htonl((uint32)pkt_header->ts.tv_usec); + net_pkt_header->timestamp_sec = htonl((uint32_t)pkt_header->ts.tv_sec); + net_pkt_header->timestamp_usec = htonl((uint32_t)pkt_header->ts.tv_usec); // Bufferize the pkt data if (sock_bufferize((char *) pkt_data, pkt_header->caplen, @@ -2927,7 +2927,7 @@ rpcapd_recv_msg_header(SOCKET sock, SSL *ssl, struct rpcap_header *headerp) * error. */ static int -rpcapd_recv(SOCKET sock, SSL *ssl, char *buffer, size_t toread, uint32 *plen, char *errmsgbuf) +rpcapd_recv(SOCKET sock, SSL *ssl, char *buffer, size_t toread, uint32_t *plen, char *errmsgbuf) { int nread; char errbuf[PCAP_ERRBUF_SIZE]; // buffer for network errors @@ -2956,7 +2956,7 @@ rpcapd_recv(SOCKET sock, SSL *ssl, char *buffer, size_t toread, uint32 *plen, ch * error. */ static int -rpcapd_discard(SOCKET sock, SSL *ssl, uint32 len) +rpcapd_discard(SOCKET sock, SSL *ssl, uint32_t len) { char errbuf[PCAP_ERRBUF_SIZE + 1]; // keeps the error string, prior to be printed |