Blame tests/test_pcap.c

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