Lines Matching defs:session

105 // Data for a session managed by a thread.
112 struct session {
138 uint32 plen, char *source, struct session **sessionp,
141 struct session *session);
144 struct session *session, uint32 plen);
145 static int daemon_unpackapplyfilter(SOCKET sockctrl, SSL *, struct session *session, uint32 *plenp, char *errbuf);
148 struct session *session, uint32 plen, struct pcap_stat *stats,
165 static void session_close(struct session *);
234 struct session *session = NULL; // struct session main variable
336 // Shut the session down.
747 // - if the device is open, I don't have to be in the middle of a capture (session->sockdata)
750 // Be carefully: the capture can have been started, but an error occurred (so session != NULL, but
752 if ((!pars.isactive) && (session == NULL || session->sockdata == 0))
904 plen, source, &session, &samp_param,
916 if (session)
919 &pars, session, plen) == -1)
942 case RPCAP_MSG_CLOSE: // The other endpoint close the pcap session
957 session, plen, &stats, svrcapt) == -1)
966 case RPCAP_MSG_ENDCAP_REQ: // The other endpoint close the current capture session
968 if (session)
971 if (pcap_stats(session->fp, &stats))
973 svrcapt = session->TotCapt;
984 &pars, session) == -1)
986 free(session);
987 session = NULL;
992 free(session);
993 session = NULL;
1106 // If we have a capture session running, close it.
1107 if (session)
1109 session_close(session);
1110 free(session);
1111 session = NULL;
1957 char *source, struct session **sessionp,
1964 struct session *session = NULL; // saves state of session
2005 // Create a session structure
2006 session = malloc(sizeof(struct session));
2007 if (session == NULL)
2009 snprintf(errmsgbuf, PCAP_ERRBUF_SIZE, "Can't allocate session structure");
2013 session->sockdata = INVALID_SOCKET;
2014 session->ctrl_ssl = session->data_ssl = NULL;
2016 session->have_thread = 0;
2027 session->thread = INVALID_HANDLE_VALUE;
2029 memset(&session->thread, 0, sizeof(session->thread));
2033 if ((session->fp = pcap_open_live(source,
2091 if ((session->sockdata = sock_open(peerhost, addrinfo, SOCKOPEN_CLIENT, 0, errmsgbuf, PCAP_ERRBUF_SIZE)) == INVALID_SOCKET)
2102 if ((session->sockdata = sock_open(NULL, addrinfo, SOCKOPEN_SERVER, 1 /* max 1 connection in queue */, errmsgbuf, PCAP_ERRBUF_SIZE)) == INVALID_SOCKET)
2107 if (getsockname(session->sockdata, (struct sockaddr *) &saddr, &saddrlen) == -1)
2129 session->sockctrl = pars->sockctrl;
2130 session->ctrl_ssl = pars->ssl;
2131 session->protocol_version = ver;
2134 ret = daemon_unpackapplyfilter(pars->sockctrl, pars->ssl, session, &plen, errmsgbuf);
2161 startcapreply->bufsize = htonl(pcap_bufsize(session->fp));
2183 socktemp = accept(session->sockdata, (struct sockaddr *) &saddr, &saddrlen);
2195 sock_close(session->sockdata, NULL, 0);
2196 session->sockdata = socktemp;
2206 ssl = ssl_promotion(1, session->sockdata, errbuf, PCAP_ERRBUF_SIZE);
2214 session->data_ssl = ssl;
2218 session->thread = (HANDLE)_beginthreadex(NULL, 0, daemon_thrdatamain,
2219 (void *) session, 0, NULL);
2220 if (session->thread == 0)
2226 ret = pthread_create(&session->thread, NULL, daemon_thrdatamain,
2227 (void *) session);
2235 session->have_thread = 1;
2241 *sessionp = session;
2254 if (session)
2256 session_close(session);
2257 free(session);
2284 if (session)
2286 session_close(session);
2287 free(session);
2295 struct session *session)
2300 session_close(session);
2332 daemon_unpackapplyfilter(SOCKET sockctrl, SSL *ctrl_ssl, struct session *session, uint32 *plenp, char *errmsgbuf)
2407 if (pcap_setfilter(session->fp, &bf_prog))
2409 snprintf(errmsgbuf, PCAP_ERRBUF_SIZE, "RPCAP error: %s", pcap_geterr(session->fp));
2418 struct session *session, uint32 plen)
2425 ret = daemon_unpackapplyfilter(pars->sockctrl, pars->ssl, session, &plen, errmsgbuf);
2531 struct session *session, uint32 plen, struct pcap_stat *stats,
2560 if (session && session->fp)
2562 if (pcap_stats(session->fp, stats) == -1)
2564 snprintf(errmsgbuf, PCAP_ERRBUF_SIZE, "%s", pcap_geterr(session->fp));
2571 netstats->svrcapt = htonl(session->TotCapt);
2607 struct session *session; // pointer to the struct session for this session
2620 session = (struct session *) ptr;
2622 session->TotCapt = 0; // counter which is incremented each time a packet is received
2631 if (pcap_snapshot(session->fp) < 0)
2639 pcap_snapshot(session->fp));
2659 sendbufsize = sizeof(struct rpcap_header) + sizeof(struct rpcap_pkthdr) + pcap_snapshot(session->fp);
2698 retval = pcap_next_ex(session->fp, &pkt_header, (const u_char **) &pkt_data); // cast to avoid a compiler warning
2724 session->protocol_version, RPCAP_MSG_PACKET, 0,
2742 net_pkt_header->npkt = htonl(++(session->TotCapt));
2764 status = sock_send(session->sockdata, session->data_ssl, sendbuf, sendbufidx, errbuf, PCAP_ERRBUF_SIZE);
2795 snprintf(errbuf, PCAP_ERRBUF_SIZE, "Error reading the packets: %s", pcap_geterr(session->fp));
2796 rpcap_senderror(session->sockctrl, session->ctrl_ssl, session->protocol_version,
2802 // The main thread will clean up the session structure.
2989 // Shut down any packet-capture thread associated with the session,
2995 // copied into the session, as the service loop might still use it.
2997 static void session_close(struct session *session)
2999 if (session->have_thread)
3008 pcap_breakloop(session->fp);
3022 SetEvent(pcap_getevent(session->fp));
3030 WaitForSingleObject(session->thread, INFINITE);
3036 CloseHandle(session->thread);
3037 session->have_thread = 0;
3038 session->thread = INVALID_HANDLE_VALUE;
3047 pthread_kill(session->thread, SIGUSR1);
3055 pthread_join(session->thread, NULL);
3056 session->have_thread = 0;
3057 memset(&session->thread, 0, sizeof(session->thread));
3062 if (session->data_ssl)
3066 ssl_finish(session->data_ssl);
3067 session->data_ssl = NULL;
3071 if (session->sockdata != INVALID_SOCKET)
3073 sock_close(session->sockdata, NULL, 0);
3074 session->sockdata = INVALID_SOCKET;
3077 if (session->fp)
3079 pcap_close(session->fp);
3080 session->fp = NULL;