Blame tests/test_pcap.c

Packit Service 31306d
/*
Packit Service 31306d
 * This file is part of the SSH Library
Packit Service 31306d
 *
Packit Service 31306d
 * Copyright (c) 2009 by Aris Adamantiadis
Packit Service 31306d
 *
Packit Service 31306d
 * The SSH Library is free software; you can redistribute it and/or modify
Packit Service 31306d
 * it under the terms of the GNU Lesser General Public License as published by
Packit Service 31306d
 * the Free Software Foundation; either version 2.1 of the License, or (at your
Packit Service 31306d
 * option) any later version.
Packit Service 31306d
 *
Packit Service 31306d
 * The SSH Library is distributed in the hope that it will be useful, but
Packit Service 31306d
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
Packit Service 31306d
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
Packit Service 31306d
 * License for more details.
Packit Service 31306d
 *
Packit Service 31306d
 * You should have received a copy of the GNU Lesser General Public License
Packit Service 31306d
 * along with the SSH Library; see the file COPYING.  If not, write to
Packit Service 31306d
 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
Packit Service 31306d
 * MA 02111-1307, USA.
Packit Service 31306d
 */
Packit Service 31306d
Packit Service 31306d
/* Simple test for the pcap functions */
Packit Service 31306d
Packit Service 31306d
#include <libssh/libssh.h>
Packit Service 31306d
#include <libssh/pcap.h>
Packit Service 31306d
#include <libssh/buffer.h>
Packit Service 31306d
Packit Service 31306d
#include <stdio.h>
Packit Service 31306d
#include <stdlib.h>
Packit Service 31306d
#include <string.h>
Packit Service 31306d
Packit Service 31306d
int main(int argc, char **argv){
Packit Service 31306d
	ssh_pcap_file pcap;
Packit Service 31306d
	ssh_pcap_context ctx;
Packit Service 31306d
	ssh_buffer buffer=ssh_buffer_new();
Packit Service 31306d
	char *str="Hello, this is a test string to test the capabilities of the"
Packit Service 31306d
			"pcap file writer.";
Packit Service 31306d
	printf("Simple pcap tester\n");
Packit Service 31306d
	pcap=ssh_pcap_file_new();
Packit Service 31306d
	if(ssh_pcap_file_open(pcap,"test.cap") != SSH_OK){
Packit Service 31306d
		printf("error happened\n");
Packit Service 31306d
		return EXIT_FAILURE;
Packit Service 31306d
	}
Packit Service 31306d
	buffer_add_data(buffer,str,strlen(str));
Packit Service 31306d
	ctx=ssh_pcap_context_new(NULL);
Packit Service 31306d
	ssh_pcap_context_set_file(ctx,pcap);
Packit Service 31306d
	ssh_pcap_context_write(ctx,SSH_PCAP_DIR_OUT,str,strlen(str),strlen(str));
Packit Service 31306d
Packit Service 31306d
	return EXIT_SUCCESS;
Packit Service 31306d
}