Lines Matching +full:buffered +full:- +full:positive
2 * Copyright (c) 2002 - 2005 NetGroup, Politecnico di Torino (Italy)
3 * Copyright (c) 2005 - 2008 CACE Technologies, Davis (California)
37 #include "diag-control.h"
45 #include "pcap-int.h"
46 #include "pcap-util.h"
47 #include "rpcap-protocol.h"
48 #include "pcap-rpcap.h"
64 * However there is no guarantees that the string will be zero-terminated.
70 * XXX - actually, null-terminating the error string is part of the
72 * that doesn't guarantee null-termination, even at the expense of
129 …char *currentfilter; /* Pointer to a buffer (allocated at run-time) that stores the current filte…
142 * variable. It is always equal to (TotAccepted - TotDrops),
146 * In this case, (TotAccepted - TotDrops - TotNetDrops) gives a
189 * This function translates (i.e. de-serializes) a 'rpcap_sockaddr'
199 * byte-swapped, and to handle the fact that AF_INET6 has different
226 * structure format. For most OSes, this looks like the over-the-wire
228 * on the machine receiving the reply. For OSes with the newer BSD-style
229 * sockaddr structures, this has, instead of a 2-byte address family,
230 * a 1-byte structure length followed by a 1-byte address family. The
232 * sending it; that would set it to 0 on a little-endian machine, as
234 * with its lower 8 bits zero, so putting that back into a 1-byte field
237 * Therefore, for older RPCAPDs running on an OS with newer BSD-style
238 * sockaddr structures, the family field, if treated as a big-endian
239 * (network byte order) 16-bit field, would be:
241 * (length << 8) | family if sent by a big-endian machine
242 * (length << 8) if sent by a little-endian machine
245 * older BSD-style sockaddr structures, the family field, if treated
246 * as a big-endian 16-bit field, would just contain the family.
249 * to be de-serialized.
252 * the de-serialized data. The structure returned can be either a 'sockaddr_in' or 'sockaddr_in6'.
255 * \param errbuf: a pointer to a user-allocated buffer (of size PCAP_ERRBUF_SIZE)
258 * \return '0' if everything is fine, '-1' if some errors occurred. Basically, the error
269 * Possible IPv4 family values other than the designated over-the-wire value,
281 * Possible IPv6 family values other than the designated over-the-wire value,
286 * The new BSD sockaddr structure format was in place before 4.4-Lite, so
287 * all the free-software BSDs use it.
291 …_BSD_AF_INET6_DARWIN_BE ((SOCKADDR_IN6_LEN << 8) | 30) /* macOS, iOS, anything else Darwin-based */
302 switch (ntohs(sockaddrin->family)) in rpcap_deseraddr()
316 return -1; in rpcap_deseraddr()
320 sockaddrout_ipv4->sin_family = AF_INET; in rpcap_deseraddr()
321 sockaddrout_ipv4->sin_port = ntohs(sockaddrin_ipv4->port); in rpcap_deseraddr()
322 memcpy(&sockaddrout_ipv4->sin_addr, &sockaddrin_ipv4->addr, sizeof(sockaddrout_ipv4->sin_addr)); in rpcap_deseraddr()
323 memset(sockaddrout_ipv4->sin_zero, 0, sizeof(sockaddrout_ipv4->sin_zero)); in rpcap_deseraddr()
346 return -1; in rpcap_deseraddr()
350 sockaddrout_ipv6->sin6_family = AF_INET6; in rpcap_deseraddr()
351 sockaddrout_ipv6->sin6_port = ntohs(sockaddrin_ipv6->port); in rpcap_deseraddr()
352 sockaddrout_ipv6->sin6_flowinfo = ntohl(sockaddrin_ipv6->flowinfo); in rpcap_deseraddr()
353 memcpy(&sockaddrout_ipv6->sin6_addr, &sockaddrin_ipv6->addr, sizeof(sockaddrout_ipv6->sin6_addr)); in rpcap_deseraddr()
354 sockaddrout_ipv6->sin6_scope_id = ntohl(sockaddrin_ipv6->scope_id); in rpcap_deseraddr()
383 * - the 'timeout' chosen by the user is split in two (half on the server side,
385 * - this function checks for packets; if there are no packets, it waits for
391 struct pcap_rpcap *pr = p->priv; /* structure used when doing a remote live capture */ in pcap_read_nocb_remote()
407 tv.tv_sec = p->opt.timeout / 1000; in pcap_read_nocb_remote()
408 tv.tv_usec = (suseconds_t)((p->opt.timeout - tv.tv_sec * 1000) * 1000); in pcap_read_nocb_remote()
413 retval = pr->data_ssl && SSL_pending(pr->data_ssl) > 0; in pcap_read_nocb_remote()
421 * 'fp->rmt_sockdata' has always to be set before calling the select(), in pcap_read_nocb_remote()
424 FD_SET(pr->rmt_sockdata, &rfds); in pcap_read_nocb_remote()
429 retval = select((int) pr->rmt_sockdata + 1, &rfds, NULL, NULL, &tv); in pcap_read_nocb_remote()
432 if (retval == -1) in pcap_read_nocb_remote()
441 sock_geterrmsg(p->errbuf, PCAP_ERRBUF_SIZE, in pcap_read_nocb_remote()
443 return -1; in pcap_read_nocb_remote()
455 header = (struct rpcap_header *) p->buffer; in pcap_read_nocb_remote()
456 net_pkt_header = (struct rpcap_pkthdr *) ((char *)p->buffer + sizeof(struct rpcap_header)); in pcap_read_nocb_remote()
457 net_pkt_data = (u_char *)p->buffer + sizeof(struct rpcap_header) + sizeof(struct rpcap_pkthdr); in pcap_read_nocb_remote()
459 if (pr->rmt_flags & PCAP_OPENFLAG_DATATX_UDP) in pcap_read_nocb_remote()
462 msglen = sock_recv_dgram(pr->rmt_sockdata, pr->data_ssl, p->buffer, in pcap_read_nocb_remote()
463 p->bufsize, p->errbuf, PCAP_ERRBUF_SIZE); in pcap_read_nocb_remote()
464 if (msglen == -1) in pcap_read_nocb_remote()
467 return -1; in pcap_read_nocb_remote()
469 if (msglen == -3) in pcap_read_nocb_remote()
479 snprintf(p->errbuf, PCAP_ERRBUF_SIZE, in pcap_read_nocb_remote()
481 return -1; in pcap_read_nocb_remote()
483 plen = ntohl(header->plen); in pcap_read_nocb_remote()
490 snprintf(p->errbuf, PCAP_ERRBUF_SIZE, in pcap_read_nocb_remote()
492 return -1; in pcap_read_nocb_remote()
499 if ((size_t)p->cc < sizeof(struct rpcap_header)) in pcap_read_nocb_remote()
507 if (status == -1) in pcap_read_nocb_remote()
510 return -1; in pcap_read_nocb_remote()
512 if (status == -3) in pcap_read_nocb_remote()
525 plen = ntohl(header->plen); in pcap_read_nocb_remote()
526 if (plen > p->bufsize - sizeof(struct rpcap_header)) in pcap_read_nocb_remote()
534 snprintf(p->errbuf, PCAP_ERRBUF_SIZE, in pcap_read_nocb_remote()
536 return -1; in pcap_read_nocb_remote()
539 if (status == -1) in pcap_read_nocb_remote()
542 return -1; in pcap_read_nocb_remote()
544 if (status == -3) in pcap_read_nocb_remote()
555 p->bp = p->buffer; in pcap_read_nocb_remote()
556 p->cc = 0; in pcap_read_nocb_remote()
562 header->plen = plen; in pcap_read_nocb_remote()
567 if (rpcap_check_msg_ver(pr->rmt_sockdata, pr->data_ssl, pr->protocol_version, in pcap_read_nocb_remote()
568 header, p->errbuf) == -1) in pcap_read_nocb_remote()
576 if (header->type != RPCAP_MSG_PACKET) in pcap_read_nocb_remote()
581 if (ntohl(net_pkt_header->caplen) > plen) in pcap_read_nocb_remote()
583 snprintf(p->errbuf, PCAP_ERRBUF_SIZE, in pcap_read_nocb_remote()
585 return -1; in pcap_read_nocb_remote()
589 pkt_header->caplen = ntohl(net_pkt_header->caplen); in pcap_read_nocb_remote()
590 pkt_header->len = ntohl(net_pkt_header->len); in pcap_read_nocb_remote()
591 pkt_header->ts.tv_sec = ntohl(net_pkt_header->timestamp_sec); in pcap_read_nocb_remote()
592 pkt_header->ts.tv_usec = ntohl(net_pkt_header->timestamp_usec); in pcap_read_nocb_remote()
601 pr->TotCapt++; in pcap_read_nocb_remote()
603 if (pr->rmt_flags & PCAP_OPENFLAG_DATATX_UDP) in pcap_read_nocb_remote()
608 npkt = ntohl(net_pkt_header->npkt); in pcap_read_nocb_remote()
610 if (pr->TotCapt != npkt) in pcap_read_nocb_remote()
612 pr->TotNetDrops += (npkt - pr->TotCapt); in pcap_read_nocb_remote()
613 pr->TotCapt = npkt; in pcap_read_nocb_remote()
630 struct pcap_rpcap *pr = p->priv; /* structure used when doing a remote live capture */ in pcap_read_rpcap()
637 * If this is client-side, and we haven't already started in pcap_read_rpcap()
640 if (pr->rmt_clientside) in pcap_read_rpcap()
643 if (!pr->rmt_capstarted) in pcap_read_rpcap()
650 return -1; in pcap_read_rpcap()
659 * back into positive territory, and thus cause us to in pcap_read_rpcap()
660 * return a too-low count. in pcap_read_rpcap()
674 if (p->break_loop) { in pcap_read_rpcap()
676 * Yes - clear the flag that indicates that it in pcap_read_rpcap()
680 p->break_loop = 0; in pcap_read_rpcap()
693 * Do whatever post-processing is necessary, hand in pcap_read_rpcap()
697 pcapint_post_process(p->linktype, pr->byte_swapped, in pcap_read_rpcap()
702 else if (ret == -1) in pcap_read_rpcap()
716 if (p->break_loop) { in pcap_read_rpcap()
720 p->break_loop = 0; in pcap_read_rpcap()
723 /* No - return the number of packets we've processed. */ in pcap_read_rpcap()
742 struct pcap_rpcap *pr = fp->priv; /* structure used when doing a remote live capture */ in pcap_cleanup_rpcap()
751 if (temp->sockctrl == pr->rmt_sockctrl) in pcap_cleanup_rpcap()
756 temp = temp->next; in pcap_cleanup_rpcap()
761 rpcap_createhdr(&header, pr->protocol_version, in pcap_cleanup_rpcap()
769 (void)sock_send(pr->rmt_sockctrl, pr->ctrl_ssl, (char *)&header, in pcap_cleanup_rpcap()
774 rpcap_createhdr(&header, pr->protocol_version, in pcap_cleanup_rpcap()
782 if (sock_send(pr->rmt_sockctrl, pr->ctrl_ssl, (char *)&header, in pcap_cleanup_rpcap()
790 if (rpcap_process_msg_header(pr->rmt_sockctrl, pr->ctrl_ssl, in pcap_cleanup_rpcap()
791 pr->protocol_version, RPCAP_MSG_ENDCAP_REQ, in pcap_cleanup_rpcap()
794 (void)rpcap_discard(pr->rmt_sockctrl, pr->ctrl_ssl, in pcap_cleanup_rpcap()
800 if (pr->rmt_sockdata) in pcap_cleanup_rpcap()
803 if (pr->data_ssl) in pcap_cleanup_rpcap()
807 ssl_finish(pr->data_ssl); in pcap_cleanup_rpcap()
808 pr->data_ssl = NULL; in pcap_cleanup_rpcap()
811 sock_close(pr->rmt_sockdata, NULL, 0); in pcap_cleanup_rpcap()
812 pr->rmt_sockdata = 0; in pcap_cleanup_rpcap()
815 if ((!active) && (pr->rmt_sockctrl)) in pcap_cleanup_rpcap()
818 if (pr->ctrl_ssl) in pcap_cleanup_rpcap()
822 ssl_finish(pr->ctrl_ssl); in pcap_cleanup_rpcap()
823 pr->ctrl_ssl = NULL; in pcap_cleanup_rpcap()
826 sock_close(pr->rmt_sockctrl, NULL, 0); in pcap_cleanup_rpcap()
829 pr->rmt_sockctrl = 0; in pcap_cleanup_rpcap()
830 pr->ctrl_ssl = NULL; in pcap_cleanup_rpcap()
832 if (pr->currentfilter) in pcap_cleanup_rpcap()
834 free(pr->currentfilter); in pcap_cleanup_rpcap()
835 pr->currentfilter = NULL; in pcap_cleanup_rpcap()
857 return -1; in pcap_stats_rpcap()
867 *pcap_stat_size = sizeof (p->stat); in pcap_stats_ex_rpcap()
870 return (rpcap_stats_rpcap(p, &(p->stat), PCAP_STATS_EX)); in pcap_stats_ex_rpcap()
879 * - PCAP_STATS_STANDARD: if we want just standard statistics (i.e.,
881 * - PCAP_STATS_EX: if we want extended statistics (i.e., for
913 struct pcap_rpcap *pr = p->priv; /* structure used when doing a remote live capture */ in rpcap_stats_rpcap()
924 snprintf(p->errbuf, PCAP_ERRBUF_SIZE, in rpcap_stats_rpcap()
934 if (!pr->rmt_capstarted) in rpcap_stats_rpcap()
936 ps->ps_drop = 0; in rpcap_stats_rpcap()
937 ps->ps_ifdrop = 0; in rpcap_stats_rpcap()
938 ps->ps_recv = 0; in rpcap_stats_rpcap()
942 ps->ps_capt = 0; in rpcap_stats_rpcap()
943 ps->ps_sent = 0; in rpcap_stats_rpcap()
944 ps->ps_netdrop = 0; in rpcap_stats_rpcap()
951 rpcap_createhdr(&header, pr->protocol_version, in rpcap_stats_rpcap()
955 if (sock_send(pr->rmt_sockctrl, pr->ctrl_ssl, (char *)&header, in rpcap_stats_rpcap()
956 sizeof(struct rpcap_header), p->errbuf, PCAP_ERRBUF_SIZE) < 0) in rpcap_stats_rpcap()
960 if (rpcap_process_msg_header(pr->rmt_sockctrl, pr->ctrl_ssl, pr->protocol_version, in rpcap_stats_rpcap()
961 RPCAP_MSG_STATS_REQ, &header, p->errbuf) == -1) in rpcap_stats_rpcap()
967 if (rpcap_recv(pr->rmt_sockctrl, pr->ctrl_ssl, (char *)&netstats, in rpcap_stats_rpcap()
968 sizeof(struct rpcap_stats), &plen, p->errbuf) == -1) in rpcap_stats_rpcap()
971 ps->ps_drop = ntohl(netstats.krnldrop); in rpcap_stats_rpcap()
972 ps->ps_ifdrop = ntohl(netstats.ifdrop); in rpcap_stats_rpcap()
973 ps->ps_recv = ntohl(netstats.ifrecv); in rpcap_stats_rpcap()
977 ps->ps_capt = pr->TotCapt; in rpcap_stats_rpcap()
978 ps->ps_netdrop = pr->TotNetDrops; in rpcap_stats_rpcap()
979 ps->ps_sent = ntohl(netstats.svrcapt); in rpcap_stats_rpcap()
984 if (rpcap_discard(pr->rmt_sockctrl, pr->ctrl_ssl, plen, p->errbuf) == -1) in rpcap_stats_rpcap()
995 (void)rpcap_discard(pr->rmt_sockctrl, pr->ctrl_ssl, plen, NULL); in rpcap_stats_rpcap()
1013 * \param errbuf: a pointer to a user-allocated buffer (of size
1047 if (sock_cmpaddr(&temp->host, (struct sockaddr_storage *) ai_next->ai_addr) == 0) in rpcap_remoteact_getsock()
1054 ai_next = ai_next->ai_next; in rpcap_remoteact_getsock()
1056 temp = temp->next; in rpcap_remoteact_getsock()
1080 * \return '0' if everything is fine, '-1' otherwise. The error message
1085 struct pcap_rpcap *pr = fp->priv; /* structure used when doing a remote live capture */ in pcap_startcapture_remote()
1086 char sendbuf[RPCAP_NETBUF_SIZE]; /* temporary buffer in which data to be sent is buffered */ in pcap_startcapture_remote()
1087 int sendbufidx = 0; /* index which keeps the number of bytes currently buffered */ in pcap_startcapture_remote()
1094 /* socket-related variables*/ in pcap_startcapture_remote()
1104 /* RPCAP-related variables*/ in pcap_startcapture_remote()
1115 // Take the opportunity to clear pr->data_ssl before any goto error, in pcap_startcapture_remote()
1116 // as it seems p->priv is not zeroed after its malloced. in pcap_startcapture_remote()
1117 // XXX - it now should be, as it's allocated by pcap_alloc_pcap_t(), in pcap_startcapture_remote()
1119 pr->data_ssl = NULL; in pcap_startcapture_remote()
1126 return -1; in pcap_startcapture_remote()
1132 if (temp->sockctrl == pr->rmt_sockctrl) in pcap_startcapture_remote()
1137 temp = temp->next; in pcap_startcapture_remote()
1150 if (getpeername(pr->rmt_sockctrl, (struct sockaddr *) &saddr, &saddrlen) == -1) in pcap_startcapture_remote()
1152 sock_geterrmsg(fp->errbuf, PCAP_ERRBUF_SIZE, in pcap_startcapture_remote()
1156 ai_family = ((struct sockaddr_storage *) &saddr)->ss_family; in pcap_startcapture_remote()
1162 sock_geterrmsg(fp->errbuf, PCAP_ERRBUF_SIZE, in pcap_startcapture_remote()
1169 * - we're using TCP, and the user wants us to be in active mode in pcap_startcapture_remote()
1170 * - we're using UDP in pcap_startcapture_remote()
1172 if ((active) || (pr->rmt_flags & PCAP_OPENFLAG_DATATX_UDP)) in pcap_startcapture_remote()
1182 hints.ai_socktype = (pr->rmt_flags & PCAP_OPENFLAG_DATATX_UDP) ? SOCK_DGRAM : SOCK_STREAM; in pcap_startcapture_remote()
1186 addrinfo = sock_initaddress(NULL, NULL, &hints, fp->errbuf, in pcap_startcapture_remote()
1192 1 /* max 1 connection in queue */, fp->errbuf, PCAP_ERRBUF_SIZE)) == INVALID_SOCKET) in pcap_startcapture_remote()
1201 if (getsockname(sockdata, (struct sockaddr *) &saddr, &saddrlen) == -1) in pcap_startcapture_remote()
1203 sock_geterrmsg(fp->errbuf, PCAP_ERRBUF_SIZE, in pcap_startcapture_remote()
1212 portdata = sin4->sin_port; in pcap_startcapture_remote()
1217 portdata = sin6->sin6_port; in pcap_startcapture_remote()
1221 snprintf(fp->errbuf, PCAP_ERRBUF_SIZE, in pcap_startcapture_remote()
1233 &sendbufidx, RPCAP_NETBUF_SIZE, SOCKBUF_CHECKONLY, fp->errbuf, PCAP_ERRBUF_SIZE)) in pcap_startcapture_remote()
1237 pr->protocol_version, RPCAP_MSG_STARTCAP_REQ, 0, in pcap_startcapture_remote()
1238 …sizeof(struct rpcap_startcapreq) + sizeof(struct rpcap_filter) + fp->fcode.bf_len * sizeof(struct … in pcap_startcapture_remote()
1244 &sendbufidx, RPCAP_NETBUF_SIZE, SOCKBUF_CHECKONLY, fp->errbuf, PCAP_ERRBUF_SIZE)) in pcap_startcapture_remote()
1250 fp->opt.timeout = fp->opt.timeout / 2; in pcap_startcapture_remote()
1251 startcapreq->read_timeout = htonl(fp->opt.timeout); in pcap_startcapture_remote()
1254 if ((active) || (pr->rmt_flags & PCAP_OPENFLAG_DATATX_UDP)) in pcap_startcapture_remote()
1256 startcapreq->portdata = portdata; in pcap_startcapture_remote()
1259 startcapreq->snaplen = htonl(fp->snapshot); in pcap_startcapture_remote()
1260 startcapreq->flags = 0; in pcap_startcapture_remote()
1262 if (pr->rmt_flags & PCAP_OPENFLAG_PROMISCUOUS) in pcap_startcapture_remote()
1263 startcapreq->flags |= RPCAP_STARTCAPREQ_FLAG_PROMISC; in pcap_startcapture_remote()
1264 if (pr->rmt_flags & PCAP_OPENFLAG_DATATX_UDP) in pcap_startcapture_remote()
1265 startcapreq->flags |= RPCAP_STARTCAPREQ_FLAG_DGRAM; in pcap_startcapture_remote()
1267 startcapreq->flags |= RPCAP_STARTCAPREQ_FLAG_SERVEROPEN; in pcap_startcapture_remote()
1269 startcapreq->flags = htons(startcapreq->flags); in pcap_startcapture_remote()
1272 if (pcap_pack_bpffilter(fp, &sendbuf[sendbufidx], &sendbufidx, &fp->fcode)) in pcap_startcapture_remote()
1275 if (sock_send(pr->rmt_sockctrl, pr->ctrl_ssl, sendbuf, sendbufidx, fp->errbuf, in pcap_startcapture_remote()
1280 if (rpcap_process_msg_header(pr->rmt_sockctrl, pr->ctrl_ssl, pr->protocol_version, in pcap_startcapture_remote()
1281 RPCAP_MSG_STARTCAP_REQ, &header, fp->errbuf) == -1) in pcap_startcapture_remote()
1286 if (rpcap_recv(pr->rmt_sockctrl, pr->ctrl_ssl, (char *)&startcapreply, in pcap_startcapture_remote()
1287 sizeof(struct rpcap_startcapreply), &plen, fp->errbuf) == -1) in pcap_startcapture_remote()
1294 * - if we're in active mode, we have to wait for a remote connection in pcap_startcapture_remote()
1295 * - if we're in passive more, we have to start a connection in pcap_startcapture_remote()
1301 if (!(pr->rmt_flags & PCAP_OPENFLAG_DATATX_UDP)) in pcap_startcapture_remote()
1309 hints.ai_socktype = (pr->rmt_flags & PCAP_OPENFLAG_DATATX_UDP) ? SOCK_DGRAM : SOCK_STREAM; in pcap_startcapture_remote()
1314 fp->errbuf, PCAP_ERRBUF_SIZE); in pcap_startcapture_remote()
1318 …if ((sockdata = sock_open(host, addrinfo, SOCKOPEN_CLIENT, 0, fp->errbuf, PCAP_ERRBUF_SIZE)) == IN… in pcap_startcapture_remote()
1336 sock_geterrmsg(fp->errbuf, PCAP_ERRBUF_SIZE, in pcap_startcapture_remote()
1342 sock_close(sockdata, fp->errbuf, PCAP_ERRBUF_SIZE); in pcap_startcapture_remote()
1348 pr->rmt_sockdata = sockdata; in pcap_startcapture_remote()
1351 if (pr->uses_ssl) in pcap_startcapture_remote()
1353 pr->data_ssl = ssl_promotion(0, sockdata, fp->errbuf, PCAP_ERRBUF_SIZE); in pcap_startcapture_remote()
1354 if (! pr->data_ssl) goto error; in pcap_startcapture_remote()
1369 if (res == -1) in pcap_startcapture_remote()
1371 sock_geterrmsg(fp->errbuf, PCAP_ERRBUF_SIZE, in pcap_startcapture_remote()
1386 if (server_sockbufsize <= (u_int) fp->snapshot) in pcap_startcapture_remote()
1429 fp->bufsize = sizeof(struct rpcap_header) + sizeof(struct rpcap_pkthdr) + fp->snapshot; in pcap_startcapture_remote()
1431 fp->buffer = (u_char *)malloc(fp->bufsize); in pcap_startcapture_remote()
1432 if (fp->buffer == NULL) in pcap_startcapture_remote()
1434 pcapint_fmt_errmsg_for_errno(fp->errbuf, PCAP_ERRBUF_SIZE, in pcap_startcapture_remote()
1442 fp->bp = fp->buffer; in pcap_startcapture_remote()
1443 fp->cc = 0; in pcap_startcapture_remote()
1446 if (rpcap_discard(pr->rmt_sockctrl, pr->ctrl_ssl, plen, fp->errbuf) == -1) in pcap_startcapture_remote()
1455 if (pr->rmt_flags & PCAP_OPENFLAG_NOCAPTURE_RPCAP) in pcap_startcapture_remote()
1459 if (pcap_createfilter_norpcappkt(fp, &fcode) == -1) in pcap_startcapture_remote()
1463 /* (the 'pr->rmt_capstarted' variable will be updated some lines below) */ in pcap_startcapture_remote()
1464 if (pcap_updatefilter_remote(fp, &fcode) == -1) in pcap_startcapture_remote()
1470 pr->rmt_capstarted = 1; in pcap_startcapture_remote()
1486 (void)rpcap_discard(pr->rmt_sockctrl, pr->ctrl_ssl, plen, NULL); in pcap_startcapture_remote()
1490 if (pr->data_ssl) in pcap_startcapture_remote()
1494 ssl_finish(pr->data_ssl); in pcap_startcapture_remote()
1495 pr->data_ssl = NULL; in pcap_startcapture_remote()
1506 if (pr->ctrl_ssl) in pcap_startcapture_remote()
1510 ssl_finish(pr->ctrl_ssl); in pcap_startcapture_remote()
1511 pr->ctrl_ssl = NULL; in pcap_startcapture_remote()
1514 sock_close(pr->rmt_sockctrl, NULL, 0); in pcap_startcapture_remote()
1532 return -1; in pcap_startcapture_remote()
1539 * - pcap_startcapture_remote() is called (we have to send the filter
1541 * - we want to update the filter during a capture (i.e. pcap_setfilter()
1556 * \return '0' if everything is fine, '-1' otherwise. The error message (if one)
1567 if (prog->bf_len == 0) /* No filters have been specified; so, let's apply a "fake" filter */ in pcap_pack_bpffilter()
1569 if (pcap_compile(fp, &fake_prog, NULL /* buffer */, 1, 0) == -1) in pcap_pack_bpffilter()
1570 return -1; in pcap_pack_bpffilter()
1578 RPCAP_NETBUF_SIZE, SOCKBUF_CHECKONLY, fp->errbuf, PCAP_ERRBUF_SIZE)) in pcap_pack_bpffilter()
1579 return -1; in pcap_pack_bpffilter()
1581 filter->filtertype = htons(RPCAP_UPDATEFILTER_BPF); in pcap_pack_bpffilter()
1582 filter->nitems = htonl((int32)prog->bf_len); in pcap_pack_bpffilter()
1584 if (sock_bufferize(NULL, prog->bf_len * sizeof(struct rpcap_filterbpf_insn), in pcap_pack_bpffilter()
1585 NULL, sendbufidx, RPCAP_NETBUF_SIZE, SOCKBUF_CHECKONLY, fp->errbuf, PCAP_ERRBUF_SIZE)) in pcap_pack_bpffilter()
1586 return -1; in pcap_pack_bpffilter()
1589 bf_insn = prog->bf_insns; in pcap_pack_bpffilter()
1591 for (i = 0; i < prog->bf_len; i++) in pcap_pack_bpffilter()
1593 insn->code = htons(bf_insn->code); in pcap_pack_bpffilter()
1594 insn->jf = bf_insn->jf; in pcap_pack_bpffilter()
1595 insn->jt = bf_insn->jt; in pcap_pack_bpffilter()
1596 insn->k = htonl(bf_insn->k); in pcap_pack_bpffilter()
1614 * - the capture has been started: in this case, pcap_setfilter_rpcap()
1616 * - the capture has not started yet: in this case, pcap_setfilter_rpcap()
1626 * XXX - we really should have pcap_setfilter() always discard packets
1632 struct pcap_rpcap *pr = fp->priv; /* structure used when doing a remote live capture */ in pcap_updatefilter_remote()
1633 char sendbuf[RPCAP_NETBUF_SIZE]; /* temporary buffer in which data to be sent is buffered */ in pcap_updatefilter_remote()
1634 int sendbufidx = 0; /* index which keeps the number of bytes currently buffered */ in pcap_updatefilter_remote()
1638 RPCAP_NETBUF_SIZE, SOCKBUF_CHECKONLY, fp->errbuf, PCAP_ERRBUF_SIZE)) in pcap_updatefilter_remote()
1639 return -1; in pcap_updatefilter_remote()
1642 pr->protocol_version, RPCAP_MSG_UPDATEFILTER_REQ, 0, in pcap_updatefilter_remote()
1643 sizeof(struct rpcap_filter) + prog->bf_len * sizeof(struct rpcap_filterbpf_insn)); in pcap_updatefilter_remote()
1646 return -1; in pcap_updatefilter_remote()
1648 if (sock_send(pr->rmt_sockctrl, pr->ctrl_ssl, sendbuf, sendbufidx, fp->errbuf, in pcap_updatefilter_remote()
1650 return -1; in pcap_updatefilter_remote()
1653 if (rpcap_process_msg_header(pr->rmt_sockctrl, pr->ctrl_ssl, pr->protocol_version, in pcap_updatefilter_remote()
1654 RPCAP_MSG_UPDATEFILTER_REQ, &header, fp->errbuf) == -1) in pcap_updatefilter_remote()
1655 return -1; in pcap_updatefilter_remote()
1660 if (rpcap_discard(pr->rmt_sockctrl, pr->ctrl_ssl, header.plen, fp->errbuf) == -1) in pcap_updatefilter_remote()
1661 return -1; in pcap_updatefilter_remote()
1669 struct pcap_rpcap *pr = fp->priv; /* structure used when doing a remote live capture */ in pcap_save_current_filter_rpcap()
1673 * - We are on an remote capture in pcap_save_current_filter_rpcap()
1674 * - we do not want to capture RPCAP traffic in pcap_save_current_filter_rpcap()
1679 if (pr->rmt_clientside && in pcap_save_current_filter_rpcap()
1680 (pr->rmt_flags & PCAP_OPENFLAG_NOCAPTURE_RPCAP)) in pcap_save_current_filter_rpcap()
1682 if (pr->currentfilter) in pcap_save_current_filter_rpcap()
1683 free(pr->currentfilter); in pcap_save_current_filter_rpcap()
1688 pr->currentfilter = strdup(filter); in pcap_save_current_filter_rpcap()
1703 struct pcap_rpcap *pr = fp->priv; /* structure used when doing a remote live capture */ in pcap_setfilter_rpcap()
1705 if (!pr->rmt_capstarted) in pcap_setfilter_rpcap()
1708 if (pcapint_install_bpf_program(fp, prog) == -1) in pcap_setfilter_rpcap()
1709 return -1; in pcap_setfilter_rpcap()
1713 /* we have to update a filter during run-time */ in pcap_setfilter_rpcap()
1715 return -1; in pcap_setfilter_rpcap()
1727 * \return '0' if everything is fine, '-1' otherwise. The error message (if one)
1732 struct pcap_rpcap *pr = fp->priv; /* structure used when doing a remote live capture */ in pcap_createfilter_norpcappkt()
1736 if (pr->rmt_flags & PCAP_OPENFLAG_NOCAPTURE_RPCAP) in pcap_createfilter_norpcappkt()
1749 if (getpeername(pr->rmt_sockctrl, (struct sockaddr *) &saddr, &saddrlen) == -1) in pcap_createfilter_norpcappkt()
1751 sock_geterrmsg(fp->errbuf, PCAP_ERRBUF_SIZE, in pcap_createfilter_norpcappkt()
1753 return -1; in pcap_createfilter_norpcappkt()
1759 sock_geterrmsg(fp->errbuf, PCAP_ERRBUF_SIZE, in pcap_createfilter_norpcappkt()
1761 return -1; in pcap_createfilter_norpcappkt()
1766 if (getsockname(pr->rmt_sockctrl, (struct sockaddr *) &saddr, &saddrlen) == -1) in pcap_createfilter_norpcappkt()
1768 sock_geterrmsg(fp->errbuf, PCAP_ERRBUF_SIZE, in pcap_createfilter_norpcappkt()
1770 return -1; in pcap_createfilter_norpcappkt()
1777 sock_geterrmsg(fp->errbuf, PCAP_ERRBUF_SIZE, in pcap_createfilter_norpcappkt()
1779 return -1; in pcap_createfilter_norpcappkt()
1783 if (getsockname(pr->rmt_sockdata, (struct sockaddr *) &saddr, &saddrlen) == -1) in pcap_createfilter_norpcappkt()
1785 sock_geterrmsg(fp->errbuf, PCAP_ERRBUF_SIZE, in pcap_createfilter_norpcappkt()
1787 return -1; in pcap_createfilter_norpcappkt()
1793 sock_geterrmsg(fp->errbuf, PCAP_ERRBUF_SIZE, in pcap_createfilter_norpcappkt()
1795 return -1; in pcap_createfilter_norpcappkt()
1798 if (pr->currentfilter && pr->currentfilter[0] != '\0') in pcap_createfilter_norpcappkt()
1806 pr->currentfilter, myaddress, peeraddress, in pcap_createfilter_norpcappkt()
1808 mydataport) == -1) in pcap_createfilter_norpcappkt()
1811 snprintf(fp->errbuf, PCAP_ERRBUF_SIZE, in pcap_createfilter_norpcappkt()
1813 return -1; in pcap_createfilter_norpcappkt()
1825 myaddress, peeraddress, mydataport) == -1) in pcap_createfilter_norpcappkt()
1828 snprintf(fp->errbuf, PCAP_ERRBUF_SIZE, in pcap_createfilter_norpcappkt()
1830 return -1; in pcap_createfilter_norpcappkt()
1839 pr->rmt_clientside = 0; in pcap_createfilter_norpcappkt()
1841 if (pcap_compile(fp, prog, newfilter, 1, 0) == -1) in pcap_createfilter_norpcappkt()
1842 RetVal = -1; in pcap_createfilter_norpcappkt()
1845 pr->rmt_clientside = 1; in pcap_createfilter_norpcappkt()
1863 * \return '0' if everything is OK, '-1' is something goes wrong. The
1868 struct pcap_rpcap *pr = fp->priv; /* structure used when doing a remote live capture */ in pcap_setsampling_remote()
1869 char sendbuf[RPCAP_NETBUF_SIZE];/* temporary buffer in which data to be sent is buffered */ in pcap_setsampling_remote()
1870 int sendbufidx = 0; /* index which keeps the number of bytes currently buffered */ in pcap_setsampling_remote()
1875 if (fp->rmt_samp.method == PCAP_SAMP_NOSAMP) in pcap_setsampling_remote()
1883 if (fp->rmt_samp.method < 0 || fp->rmt_samp.method > 255) { in pcap_setsampling_remote()
1884 snprintf(fp->errbuf, PCAP_ERRBUF_SIZE, in pcap_setsampling_remote()
1885 "Invalid sampling method %d", fp->rmt_samp.method); in pcap_setsampling_remote()
1886 return -1; in pcap_setsampling_remote()
1888 if (fp->rmt_samp.value < 0 || fp->rmt_samp.value > 65535) { in pcap_setsampling_remote()
1889 snprintf(fp->errbuf, PCAP_ERRBUF_SIZE, in pcap_setsampling_remote()
1890 "Invalid sampling value %d", fp->rmt_samp.value); in pcap_setsampling_remote()
1891 return -1; in pcap_setsampling_remote()
1895 &sendbufidx, RPCAP_NETBUF_SIZE, SOCKBUF_CHECKONLY, fp->errbuf, PCAP_ERRBUF_SIZE)) in pcap_setsampling_remote()
1896 return -1; in pcap_setsampling_remote()
1899 pr->protocol_version, RPCAP_MSG_SETSAMPLING_REQ, 0, in pcap_setsampling_remote()
1906 &sendbufidx, RPCAP_NETBUF_SIZE, SOCKBUF_CHECKONLY, fp->errbuf, PCAP_ERRBUF_SIZE)) in pcap_setsampling_remote()
1907 return -1; in pcap_setsampling_remote()
1911 sampling_pars->method = (uint8)fp->rmt_samp.method; in pcap_setsampling_remote()
1912 sampling_pars->value = (uint16)htonl(fp->rmt_samp.value); in pcap_setsampling_remote()
1914 if (sock_send(pr->rmt_sockctrl, pr->ctrl_ssl, sendbuf, sendbufidx, fp->errbuf, in pcap_setsampling_remote()
1916 return -1; in pcap_setsampling_remote()
1919 if (rpcap_process_msg_header(pr->rmt_sockctrl, pr->ctrl_ssl, pr->protocol_version, in pcap_setsampling_remote()
1920 RPCAP_MSG_SETSAMPLING_REQ, &header, fp->errbuf) == -1) in pcap_setsampling_remote()
1921 return -1; in pcap_setsampling_remote()
1926 if (rpcap_discard(pr->rmt_sockctrl, pr->ctrl_ssl, header.plen, fp->errbuf) == -1) in pcap_setsampling_remote()
1927 return -1; in pcap_setsampling_remote()
1961 * byte order the server says it has is byte-swapped from ours, 0
1966 * \param errbuf: a pointer to a user-allocated buffer (of size
1971 * \return '0' if everything is fine, '-1' for an error. For errors,
1977 …char sendbuf[RPCAP_NETBUF_SIZE]; /* temporary buffer in which data that has to be sent is buffered… in rpcap_doauth()
1978 int sendbufidx = 0; /* index which keeps the number of bytes currently buffered */ in rpcap_doauth()
1987 int has_byte_order; /* The server sent its version of the byte-order magic number */ in rpcap_doauth()
1992 switch (auth->type) in rpcap_doauth()
2000 if (auth->username) in rpcap_doauth()
2002 str_length = strlen(auth->username); in rpcap_doauth()
2006 return -1; in rpcap_doauth()
2010 if (auth->password) in rpcap_doauth()
2012 str_length = strlen(auth->password); in rpcap_doauth()
2016 return -1; in rpcap_doauth()
2024 return -1; in rpcap_doauth()
2027 auth_type = (uint16)auth->type; in rpcap_doauth()
2037 return -1; in rpcap_doauth()
2046 return -1; in rpcap_doauth()
2050 rpauth->type = htons(auth_type); in rpcap_doauth()
2054 if (auth->username) in rpcap_doauth()
2055 rpauth->slen1 = (uint16)strlen(auth->username); in rpcap_doauth()
2057 rpauth->slen1 = 0; in rpcap_doauth()
2059 if (sock_bufferize(auth->username, rpauth->slen1, sendbuf, in rpcap_doauth()
2061 return -1; in rpcap_doauth()
2063 if (auth->password) in rpcap_doauth()
2064 rpauth->slen2 = (uint16)strlen(auth->password); in rpcap_doauth()
2066 rpauth->slen2 = 0; in rpcap_doauth()
2068 if (sock_bufferize(auth->password, rpauth->slen2, sendbuf, in rpcap_doauth()
2070 return -1; in rpcap_doauth()
2072 rpauth->slen1 = htons(rpauth->slen1); in rpcap_doauth()
2073 rpauth->slen2 = htons(rpauth->slen2); in rpcap_doauth()
2078 return -1; in rpcap_doauth()
2082 &header, errbuf) == -1) in rpcap_doauth()
2083 return -1; in rpcap_doauth()
2095 /* Yes - is it big enough to include version information? */ in rpcap_doauth()
2098 /* No - discard it and fail. */ in rpcap_doauth()
2102 return -1; in rpcap_doauth()
2105 /* Yes - does it include server byte order information? */ in rpcap_doauth()
2108 /* No - just read the version information */ in rpcap_doauth()
2114 /* Yes - read it all. */ in rpcap_doauth()
2127 return -1; in rpcap_doauth()
2132 reply_len, &plen, errbuf) == -1) in rpcap_doauth()
2135 return -1; in rpcap_doauth()
2139 if (rpcap_discard(sockctrl, ssl, plen, errbuf) == -1) in rpcap_doauth()
2140 return -1; in rpcap_doauth()
2149 * Bogus - give up on this server. in rpcap_doauth()
2153 return -1; in rpcap_doauth()
2171 /* No - it supports only version 0. */ in rpcap_doauth()
2231 return -1; in rpcap_doauth()
2243 return -1; in rpcap_doauth()
2246 /* We don't currently support non-blocking mode. */
2250 snprintf(p->errbuf, PCAP_ERRBUF_SIZE, in pcap_getnonblock_rpcap()
2251 "Non-blocking mode isn't supported for capturing remotely with rpcap"); in pcap_getnonblock_rpcap()
2252 return (-1); in pcap_getnonblock_rpcap()
2258 snprintf(p->errbuf, PCAP_ERRBUF_SIZE, in pcap_setnonblock_rpcap()
2259 "Non-blocking mode isn't supported for capturing remotely with rpcap"); in pcap_setnonblock_rpcap()
2260 return (-1); in pcap_setnonblock_rpcap()
2279 errbuf) == -1) in rpcap_setup_session()
2280 return -1; in rpcap_setup_session()
2288 "Non-remote interface passed to remote capture routine"); in rpcap_setup_session()
2289 return -1; in rpcap_setup_session()
2301 return -1; in rpcap_setup_session()
2306 if (sock_init(errbuf, PCAP_ERRBUF_SIZE) == -1) in rpcap_setup_session()
2307 return -1; in rpcap_setup_session()
2314 *sockctrlp = activeconn->sockctrl; in rpcap_setup_session()
2315 *sslp = activeconn->ssl; in rpcap_setup_session()
2316 *protocol_versionp = activeconn->protocol_version; in rpcap_setup_session()
2317 *byte_swappedp = activeconn->byte_swapped; in rpcap_setup_session()
2330 return -1; in rpcap_setup_session()
2353 return -1; in rpcap_setup_session()
2359 return -1; in rpcap_setup_session()
2374 return -1; in rpcap_setup_session()
2380 return -1; in rpcap_setup_session()
2385 byte_swappedp, auth, errbuf) == -1) in rpcap_setup_session()
2397 return -1; in rpcap_setup_session()
2451 int byte_swapped; /* server is known to be byte-swapped */ in pcap_open_rpcap()
2454 char sendbuf[RPCAP_NETBUF_SIZE]; /* temporary buffer in which data to be sent is buffered */ in pcap_open_rpcap()
2455 int sendbufidx = 0; /* index which keeps the number of bytes currently buffered */ in pcap_open_rpcap()
2457 /* RPCAP-related variables */ in pcap_open_rpcap()
2481 * XXX - should we leave this up to the remote server to in pcap_open_rpcap()
2487 fp->opt.device = source_str; in pcap_open_rpcap()
2488 fp->snapshot = snaplen; in pcap_open_rpcap()
2489 fp->opt.timeout = read_timeout; in pcap_open_rpcap()
2490 pr = fp->priv; in pcap_open_rpcap()
2491 pr->rmt_flags = flags; in pcap_open_rpcap()
2496 if (rpcap_setup_session(fp->opt.device, auth, &active, &sockctrl, in pcap_open_rpcap()
2497 &pr->uses_ssl, &ssl, flags, &protocol_version, &byte_swapped, in pcap_open_rpcap()
2498 host, ctrlport, iface, errbuf) == -1) in pcap_open_rpcap()
2529 RPCAP_MSG_OPEN_REQ, &header, errbuf) == -1) in pcap_open_rpcap()
2535 sizeof(struct rpcap_openreply), &plen, errbuf) == -1) in pcap_open_rpcap()
2539 if (rpcap_discard(sockctrl, ssl, plen, errbuf) == -1) in pcap_open_rpcap()
2543 fp->linktype = ntohl(openreply.linktype); in pcap_open_rpcap()
2544 pr->rmt_sockctrl = sockctrl; in pcap_open_rpcap()
2545 pr->ctrl_ssl = ssl; in pcap_open_rpcap()
2546 pr->protocol_version = protocol_version; in pcap_open_rpcap()
2547 pr->byte_swapped = byte_swapped; in pcap_open_rpcap()
2548 pr->rmt_clientside = 1; in pcap_open_rpcap()
2551 fp->read_op = pcap_read_rpcap; in pcap_open_rpcap()
2552 fp->save_current_filter_op = pcap_save_current_filter_rpcap; in pcap_open_rpcap()
2553 fp->setfilter_op = pcap_setfilter_rpcap; in pcap_open_rpcap()
2554 fp->getnonblock_op = pcap_getnonblock_rpcap; in pcap_open_rpcap()
2555 fp->setnonblock_op = pcap_setnonblock_rpcap; in pcap_open_rpcap()
2556 fp->stats_op = pcap_stats_rpcap; in pcap_open_rpcap()
2558 fp->stats_ex_op = pcap_stats_ex_rpcap; in pcap_open_rpcap()
2560 fp->cleanup_op = pcap_cleanup_rpcap; in pcap_open_rpcap()
2562 fp->activated = 1; in pcap_open_rpcap()
2578 (void)rpcap_discard(sockctrl, pr->ctrl_ssl, plen, NULL); in pcap_open_rpcap()
2600 #define PCAP_TEXT_SOURCE_ADAPTER_LEN (sizeof PCAP_TEXT_SOURCE_ADAPTER - 1)
2603 #define PCAP_TEXT_SOURCE_ON_REMOTE_HOST_LEN (sizeof PCAP_TEXT_SOURCE_ON_REMOTE_HOST - 1)
2608 free(addr->addr); in freeaddr()
2609 free(addr->netmask); in freeaddr()
2610 free(addr->broadaddr); in freeaddr()
2611 free(addr->dstaddr); in freeaddr()
2626 int active; /* 'true' if we the other end-party is in active mode */ in pcap_findalldevs_ex_remote()
2642 errbuf) == -1) in pcap_findalldevs_ex_remote()
2645 return -1; in pcap_findalldevs_ex_remote()
2658 RPCAP_MSG_FINDALLIF_REQ, &header, errbuf) == -1) in pcap_findalldevs_ex_remote()
2677 sizeof(struct rpcap_findalldevs_if), &plen, errbuf) == -1) in pcap_findalldevs_ex_remote()
2709 lastdev->next = dev; in pcap_findalldevs_ex_remote()
2726 findalldevs_if.namelen, &plen, errbuf) == -1) in pcap_findalldevs_ex_remote()
2733 host, port, tmpstring, uses_ssl, errbuf) == -1) in pcap_findalldevs_ex_remote()
2736 dev->name = strdup(tmpstring2); in pcap_findalldevs_ex_remote()
2737 if (dev->name == NULL) in pcap_findalldevs_ex_remote()
2755 findalldevs_if.desclen, &plen, errbuf) == -1) in pcap_findalldevs_ex_remote()
2760 if (pcapint_asprintf(&dev->description, in pcap_findalldevs_ex_remote()
2762 tmpstring, PCAP_TEXT_SOURCE_ON_REMOTE_HOST, host) == -1) in pcap_findalldevs_ex_remote()
2770 dev->flags = ntohl(findalldevs_if.flags); in pcap_findalldevs_ex_remote()
2781 &plen, errbuf) == -1) in pcap_findalldevs_ex_remote()
2794 addr->next = NULL; in pcap_findalldevs_ex_remote()
2795 addr->addr = NULL; in pcap_findalldevs_ex_remote()
2796 addr->netmask = NULL; in pcap_findalldevs_ex_remote()
2797 addr->broadaddr = NULL; in pcap_findalldevs_ex_remote()
2798 addr->dstaddr = NULL; in pcap_findalldevs_ex_remote()
2800 if (rpcap_deseraddr(&ifaddr.addr, &addr->addr, in pcap_findalldevs_ex_remote()
2801 errbuf) == -1) in pcap_findalldevs_ex_remote()
2806 if (rpcap_deseraddr(&ifaddr.netmask, &addr->netmask, in pcap_findalldevs_ex_remote()
2807 errbuf) == -1) in pcap_findalldevs_ex_remote()
2812 if (rpcap_deseraddr(&ifaddr.broadaddr, &addr->broadaddr, in pcap_findalldevs_ex_remote()
2813 errbuf) == -1) in pcap_findalldevs_ex_remote()
2818 if (rpcap_deseraddr(&ifaddr.dstaddr, &addr->dstaddr, in pcap_findalldevs_ex_remote()
2819 errbuf) == -1) in pcap_findalldevs_ex_remote()
2825 if ((addr->addr == NULL) && (addr->netmask == NULL) && in pcap_findalldevs_ex_remote()
2826 (addr->broadaddr == NULL) && (addr->dstaddr == NULL)) in pcap_findalldevs_ex_remote()
2841 dev->addresses = addr; in pcap_findalldevs_ex_remote()
2845 prevaddr->next = addr; in pcap_findalldevs_ex_remote()
2869 return -1; in pcap_findalldevs_ex_remote()
2914 return -1; in pcap_findalldevs_ex_remote()
2926 /* socket-related variables */ in pcap_remoteact_accept_ex()
2948 if (sock_init(errbuf, PCAP_ERRBUF_SIZE) == -1) in pcap_remoteact_accept_ex()
2949 return (PCAP_SOCKET)-1; in pcap_remoteact_accept_ex()
2965 return (PCAP_SOCKET)-2; in pcap_remoteact_accept_ex()
2971 return (PCAP_SOCKET)-2; in pcap_remoteact_accept_ex()
2981 /* (which is not allowed on a non-connected socket) */ in pcap_remoteact_accept_ex()
2988 return (PCAP_SOCKET)-2; in pcap_remoteact_accept_ex()
2999 return (PCAP_SOCKET)-1; in pcap_remoteact_accept_ex()
3004 return (PCAP_SOCKET)-1; in pcap_remoteact_accept_ex()
3023 return (PCAP_SOCKET)-1; in pcap_remoteact_accept_ex()
3039 return (PCAP_SOCKET)-1; in pcap_remoteact_accept_ex()
3046 auth, errbuf) == -1) in pcap_remoteact_accept_ex()
3059 return (PCAP_SOCKET)-3; in pcap_remoteact_accept_ex()
3071 if (sock_cmpaddr(&temp->host, &from) == 0) in pcap_remoteact_accept_ex()
3075 temp = temp->next; in pcap_remoteact_accept_ex()
3081 prev->next = (struct activehosts *) malloc(sizeof(struct activehosts)); in pcap_remoteact_accept_ex()
3082 temp = prev->next; in pcap_remoteact_accept_ex()
3104 return (PCAP_SOCKET)-1; in pcap_remoteact_accept_ex()
3107 memcpy(&temp->host, &from, fromlen); in pcap_remoteact_accept_ex()
3108 temp->sockctrl = sockctrl; in pcap_remoteact_accept_ex()
3109 temp->ssl = ssl; in pcap_remoteact_accept_ex()
3110 temp->protocol_version = protocol_version; in pcap_remoteact_accept_ex()
3111 temp->byte_swapped = byte_swapped; in pcap_remoteact_accept_ex()
3112 temp->next = NULL; in pcap_remoteact_accept_ex()
3140 return -1; in pcap_remoteact_close()
3148 if (sock_cmpaddr(&temp->host, (struct sockaddr_storage *) ai_next->ai_addr) == 0) in pcap_remoteact_close()
3154 rpcap_createhdr(&header, temp->protocol_version, in pcap_remoteact_close()
3161 if (sock_send(temp->sockctrl, temp->ssl, in pcap_remoteact_close()
3171 if (temp->ssl) in pcap_remoteact_close()
3177 ssl_finish(temp->ssl); in pcap_remoteact_close()
3180 (void)sock_close(temp->sockctrl, NULL, in pcap_remoteact_close()
3182 status = -1; in pcap_remoteact_close()
3187 if (temp->ssl) in pcap_remoteact_close()
3193 ssl_finish(temp->ssl); in pcap_remoteact_close()
3196 if (sock_close(temp->sockctrl, errbuf, in pcap_remoteact_close()
3197 PCAP_ERRBUF_SIZE) == -1) in pcap_remoteact_close()
3198 status = -1; in pcap_remoteact_close()
3206 prev->next = temp->next; in pcap_remoteact_close()
3208 activeHosts = temp->next; in pcap_remoteact_close()
3220 ai_next = ai_next->ai_next; in pcap_remoteact_close()
3223 temp = temp->next; in pcap_remoteact_close()
3233 return -1; in pcap_remoteact_close()
3274 if (sock_getascii_addrport((struct sockaddr_storage *) &temp->host, hoststr, in pcap_remoteact_list()
3275 RPCAP_HOSTLIST_SIZE, NULL, 0, NI_NUMERICHOST, errbuf, PCAP_ERRBUF_SIZE) != -1) in pcap_remoteact_list()
3276 … /* if (getnameinfo( (struct sockaddr *) &temp->host, sizeof (struct sockaddr_storage), hoststr, */ in pcap_remoteact_list()
3281 return -1; in pcap_remoteact_list()
3290 return -1; in pcap_remoteact_list()
3294 hostlist[len - 1] = sep; in pcap_remoteact_list()
3297 temp = temp->next; in pcap_remoteact_list()
3313 if (nrecv == -1) in rpcap_recv_msg_header()
3316 return -1; in rpcap_recv_msg_header()
3318 header->plen = ntohl(header->plen); in rpcap_recv_msg_header()
3331 if (header->ver != expected_ver) in rpcap_check_msg_ver()
3336 if (rpcap_discard(sock, ssl, header->plen, errbuf) == -1) in rpcap_check_msg_ver()
3337 return -1; in rpcap_check_msg_ver()
3346 header->ver, expected_ver); in rpcap_check_msg_ver()
3348 return -1; in rpcap_check_msg_ver()
3365 if (header->type == RPCAP_MSG_ERROR) in rpcap_check_msg_type()
3371 *errcode = ntohs(header->value); in rpcap_check_msg_type()
3372 rpcap_msg_err(sock, ssl, header->plen, errbuf); in rpcap_check_msg_type()
3373 return -1; in rpcap_check_msg_type()
3382 if (header->type != (request_type | RPCAP_MSG_IS_REPLY)) in rpcap_check_msg_type()
3391 if (rpcap_discard(sock, ssl, header->plen, errbuf) == -1) in rpcap_check_msg_type()
3392 return -1; in rpcap_check_msg_type()
3398 msg_type_string = rpcap_msg_type_string(header->type); in rpcap_check_msg_type()
3407 return -1; in rpcap_check_msg_type()
3416 header->type, request_type_string); in rpcap_check_msg_type()
3418 return -1; in rpcap_check_msg_type()
3431 if (rpcap_recv_msg_header(sock, ssl, header, errbuf) == -1) in rpcap_process_msg_header()
3434 return -1; in rpcap_process_msg_header()
3440 if (rpcap_check_msg_ver(sock, ssl, expected_ver, header, errbuf) == -1) in rpcap_process_msg_header()
3441 return -1; in rpcap_process_msg_header()
3453 * message into errmsgbuf and returns -2. Otherwise, tries to read
3456 * Returns 0 on success, logs a message and returns -1 on a network
3467 return -1; in rpcap_recv()
3471 if (nread == -1) in rpcap_recv()
3473 return -1; in rpcap_recv()
3475 *plen -= nread; in rpcap_recv()
3492 if (sock_recv(sockctrl, ssl, remote_errbuf, PCAP_ERRBUF_SIZE - 1, in rpcap_msg_err()
3494 PCAP_ERRBUF_SIZE) == -1) in rpcap_msg_err()
3504 * Null-terminate it. in rpcap_msg_err()
3506 remote_errbuf[PCAP_ERRBUF_SIZE - 1] = '\0'; in rpcap_msg_err()
3510 * If we're not in UTF-8 mode, convert it to the local in rpcap_msg_err()
3520 (void)rpcap_discard(sockctrl, ssl, plen - (PCAP_ERRBUF_SIZE - 1), remote_errbuf); in rpcap_msg_err()
3531 PCAP_ERRBUF_SIZE) == -1) in rpcap_msg_err()
3541 * Null-terminate it. in rpcap_msg_err()
3549 * Mostly used to discard wrong-sized messages.
3550 * Returns 0 on success, logs a message and returns -1 on a network
3557 if (sock_discard(sock, ssl, len, errbuf, PCAP_ERRBUF_SIZE) == -1) in rpcap_discard()
3560 return -1; in rpcap_discard()
3576 bp = p->bp; in rpcap_read_packet_msg()
3577 cc = p->cc; in rpcap_read_packet_msg()
3589 bytes_read = sock_recv(rp->rmt_sockdata, rp->data_ssl, bp, size - cc, in rpcap_read_packet_msg()
3590 SOCK_RECEIVEALL_NO|SOCK_EOF_IS_ERROR, p->errbuf, in rpcap_read_packet_msg()
3593 if (bytes_read == -1) in rpcap_read_packet_msg()
3599 p->bp = bp; in rpcap_read_packet_msg()
3600 p->cc = cc; in rpcap_read_packet_msg()
3601 return -1; in rpcap_read_packet_msg()
3603 if (bytes_read == -3) in rpcap_read_packet_msg()
3610 p->bp = bp; in rpcap_read_packet_msg()
3611 p->cc = cc; in rpcap_read_packet_msg()
3612 return -3; in rpcap_read_packet_msg()
3617 * EOF - server terminated the connection. in rpcap_read_packet_msg()
3621 snprintf(p->errbuf, PCAP_ERRBUF_SIZE, in rpcap_read_packet_msg()
3623 return -1; in rpcap_read_packet_msg()
3628 p->bp = bp; in rpcap_read_packet_msg()
3629 p->cc = cc; in rpcap_read_packet_msg()